Refactor and sprites #7
@ -1,20 +1,24 @@
|
||||
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 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():
|
||||
@ -56,9 +60,9 @@ class GridDraw():
|
||||
pygame.time.delay(delay)
|
||||
|
||||
@default_color
|
||||
def line(self, x_1, y_1, x_2, y_2, color = None):
|
||||
def line(self, x_1, y_1, x_2, y_2, color=None):
|
||||
pygame.draw.line(self.screen, color, (x_1, y_1), (x_2, y_2))
|
||||
|
||||
|
||||
@default_color
|
||||
def board(self, tiles_x = None, tiles_y = None, color = None):
|
||||
tiles_x = tiles_x if tiles_x != None else self.tiles_x
|
||||
|
25
Interface/movement.py
Normal file
25
Interface/movement.py
Normal file
@ -0,0 +1,25 @@
|
||||
import pygame
|
||||
import sys
|
||||
|
||||
|
||||
def robot_movement(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)
|
@ -8,6 +8,9 @@ GRID_SIZE_Y = 10
|
||||
|
||||
# dummy function
|
||||
def initial_draw():
|
||||
# window name
|
||||
pygame.display.set_caption("AI Vacuum Cleaner")
|
||||
|
||||
grid = GridDraw(800, 800, GRID_SIZE_X, GRID_SIZE_Y)
|
||||
|
||||
x = 2
|
||||
@ -22,7 +25,6 @@ def initial_draw():
|
||||
|
||||
while True:
|
||||
grid.start_draw()
|
||||
# grid.draw_vacuum(x, y)
|
||||
grid.fill_grid_with_sprite('TILE')
|
||||
grid.board()
|
||||
|
||||
@ -46,5 +48,3 @@ def initial_draw():
|
||||
y = (y + 1 + GRID_SIZE_Y) % GRID_SIZE_Y
|
||||
|
||||
grid.end_draw(delay=10)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user