formatting and comments

This commit is contained in:
Mateusz Dokowicz 2023-03-16 20:33:22 +01:00
parent 9ac833550c
commit d080b04763
3 changed files with 37 additions and 28 deletions

View File

@ -1,29 +1,29 @@
import sys
import pygame
class Colors():
class Colors:
BLACK = 0, 0, 0
WHITE = 255, 255, 255
RED = 255, 0, 0
GREEN = 0, 255, 0
DEFAULT_COLOR = Colors.WHITE
def default_color(func):
def wrap(*args, **kwargs):
if 'color' not in kwargs:
kwargs['color'] = DEFAULT_COLOR
if "color" not in kwargs:
kwargs["color"] = DEFAULT_COLOR
result = func(*args, **kwargs)
return result
return wrap
class GridDraw():
def __init__(
self,
width = None,
height = None,
background = None
):
class GridDraw:
def __init__(self, width=None, height=None, background=None):
self.width = width if width != None else 100
self.height = height if height != None else 100
self.background = background if background != None else Colors.BLACK

View File

@ -1,17 +1,25 @@
import pygame
import sys
def moving_cleaner(grid_width, grid_height, tile_width, tile_height, x, y):
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.KEYDOWN:
# go left
if event.key == pygame.K_LEFT and x > (tile_width / 2):
x -= tile_width
# go right
if event.key == pygame.K_RIGHT and x < (grid_width - (tile_width / 2)):
x += tile_width
# go up
if event.key == pygame.K_UP and y > (tile_height / 2):
y -= tile_height
# go down
if event.key == pygame.K_DOWN and y < (grid_height - (tile_height / 2)):
y += tile_height
return (x, y)

View File

@ -3,7 +3,7 @@ import sys
import pygame
from Interface.movement import moving_cleaner
# dummy function
def initial_draw(grid_width, grid_height):
grid = GridDraw(grid_width, grid_height)
tile_width = grid_width / 10
@ -11,6 +11,8 @@ def initial_draw(grid_width, grid_height):
x = tile_width / 2
y = tile_height / 2
radius = 15
# rendering loop
while True:
grid.start_draw()
grid.board(10, 10)
@ -18,4 +20,3 @@ def initial_draw(grid_width, grid_height):
grid.circle(x, y, 20, color=Colors.RED)
grid.end_draw()
pygame.time.delay(10)