Compare commits
7 Commits
9ac833550c
...
ef2e1a1fb7
Author | SHA1 | Date | |
---|---|---|---|
ef2e1a1fb7 | |||
|
2200cf15d7 | ||
|
9b7bb1a62c | ||
|
a5e38a707b | ||
|
257f0f7d1d | ||
|
3696636245 | ||
|
d080b04763 |
@ -1,29 +1,29 @@
|
|||||||
import sys
|
import sys
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
class Colors():
|
|
||||||
|
class Colors:
|
||||||
BLACK = 0, 0, 0
|
BLACK = 0, 0, 0
|
||||||
WHITE = 255, 255, 255
|
WHITE = 255, 255, 255
|
||||||
RED = 255, 0, 0
|
RED = 255, 0, 0
|
||||||
GREEN = 0, 255, 0
|
GREEN = 0, 255, 0
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_COLOR = Colors.WHITE
|
DEFAULT_COLOR = Colors.WHITE
|
||||||
|
|
||||||
|
|
||||||
def default_color(func):
|
def default_color(func):
|
||||||
def wrap(*args, **kwargs):
|
def wrap(*args, **kwargs):
|
||||||
if 'color' not in kwargs:
|
if "color" not in kwargs:
|
||||||
kwargs['color'] = DEFAULT_COLOR
|
kwargs["color"] = DEFAULT_COLOR
|
||||||
result = func(*args, **kwargs)
|
result = func(*args, **kwargs)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
return wrap
|
return wrap
|
||||||
|
|
||||||
class GridDraw():
|
|
||||||
def __init__(
|
class GridDraw:
|
||||||
self,
|
def __init__(self, width=None, height=None, background=None):
|
||||||
width = None,
|
|
||||||
height = None,
|
|
||||||
background = None
|
|
||||||
):
|
|
||||||
self.width = width if width != None else 100
|
self.width = width if width != None else 100
|
||||||
self.height = height if height != None else 100
|
self.height = height if height != None else 100
|
||||||
self.background = background if background != None else Colors.BLACK
|
self.background = background if background != None else Colors.BLACK
|
||||||
@ -53,5 +53,7 @@ class GridDraw():
|
|||||||
self.line(0, tiles_height * i, self.width, tiles_height * i, color=color)
|
self.line(0, tiles_height * i, self.width, tiles_height * i, color=color)
|
||||||
|
|
||||||
@default_color
|
@default_color
|
||||||
def circle(self, x, y, radius, color = None):
|
def circle(self, x, y, color=None):
|
||||||
pygame.draw.circle(self.screen, color, (x, y), radius)
|
pygame.draw.circle(
|
||||||
|
self.screen, color, (x, y), 20
|
||||||
|
) # TODO calculate radius (now 20) in terms of window size.
|
||||||
|
@ -1,17 +1,25 @@
|
|||||||
import pygame
|
import pygame
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def moving_cleaner(grid_width, grid_height,tile_width,tile_height, x, y):
|
|
||||||
|
def robot_movement(grid_width, grid_height, tile_width, tile_height, x, y):
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
|
# go left
|
||||||
if event.key == pygame.K_LEFT and x > (tile_width / 2):
|
if event.key == pygame.K_LEFT and x > (tile_width / 2):
|
||||||
x -= tile_width
|
x -= tile_width
|
||||||
|
|
||||||
|
# go right
|
||||||
if event.key == pygame.K_RIGHT and x < (grid_width - (tile_width / 2)):
|
if event.key == pygame.K_RIGHT and x < (grid_width - (tile_width / 2)):
|
||||||
x += tile_width
|
x += tile_width
|
||||||
|
|
||||||
|
# go up
|
||||||
if event.key == pygame.K_UP and y > (tile_height / 2):
|
if event.key == pygame.K_UP and y > (tile_height / 2):
|
||||||
y -= tile_height
|
y -= tile_height
|
||||||
|
|
||||||
|
# go down
|
||||||
if event.key == pygame.K_DOWN and y < (grid_height - (tile_height / 2)):
|
if event.key == pygame.K_DOWN and y < (grid_height - (tile_height / 2)):
|
||||||
y += tile_height
|
y += tile_height
|
||||||
return (x, y)
|
return (x, y)
|
||||||
|
@ -1,21 +1,33 @@
|
|||||||
from Interface.grid_draw import GridDraw, Colors
|
from Interface.grid_draw import GridDraw, Colors
|
||||||
import sys
|
import sys
|
||||||
import pygame
|
import pygame
|
||||||
from Interface.movement import moving_cleaner
|
from Interface.movement import robot_movement
|
||||||
|
|
||||||
# dummy function
|
|
||||||
def initial_draw(grid_width, grid_height):
|
def initial_draw(grid_dimensions, board_size):
|
||||||
|
# window name
|
||||||
|
pygame.display.set_caption("AI Vacuum Cleaner")
|
||||||
|
|
||||||
|
# define array for grid
|
||||||
|
border_array = [["" for j in range(board_size)] for i in range(board_size)]
|
||||||
|
|
||||||
|
# set window dimension
|
||||||
|
grid_width = grid_dimensions
|
||||||
|
grid_height = grid_dimensions
|
||||||
|
|
||||||
|
# FIXME @countingthedots: please tell me what is going on there and why???
|
||||||
grid = GridDraw(grid_width, grid_height)
|
grid = GridDraw(grid_width, grid_height)
|
||||||
tile_width = grid_width / 10
|
tile_width = grid_width / board_size
|
||||||
tile_height = grid_height / 10
|
tile_height = grid_height / board_size
|
||||||
x = tile_width / 2
|
x = tile_width / 2
|
||||||
y = tile_height / 2
|
y = tile_height / 2
|
||||||
radius = 15
|
radius = 20
|
||||||
|
|
||||||
|
# rendering loop
|
||||||
while True:
|
while True:
|
||||||
grid.start_draw()
|
grid.start_draw()
|
||||||
grid.board(10, 10)
|
grid.board(board_size, board_size)
|
||||||
(x,y) = moving_cleaner(grid_width,grid_height,tile_width,tile_height, x, y)
|
(x, y) = robot_movement(grid_width, grid_height, tile_width, tile_height, x, y)
|
||||||
grid.circle(x, y, 20, color=Colors.RED)
|
grid.circle(x, y, color=Colors.RED)
|
||||||
grid.end_draw()
|
grid.end_draw()
|
||||||
pygame.time.delay(10)
|
pygame.time.delay(10)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user