This commit is contained in:
Mateusz Dokowicz 2023-03-22 23:11:13 +01:00
parent 4933c04bd8
commit be307ebab5

View File

@ -13,10 +13,11 @@ def initial_draw(window_dimensions, board_size):
pygame.display.set_caption("AI Vacuum Cleaner") pygame.display.set_caption("AI Vacuum Cleaner")
# define additional variables # define additional variables
tile_size = window_width / board_size tile_size = window_dimensions / board_size
# initialize board array # initialize board array
newGrid = Grid(board_size, tile_size) newGrid = Grid(board_size)
newGrid.add(objectOnTile(1, 1, acceptedType.PLAYER))
# set window dimension # set window dimension
window_width = window_dimensions window_width = window_dimensions
@ -25,22 +26,16 @@ def initial_draw(window_dimensions, board_size):
# FIXME @countingthedots: please tell me what is going on there and why??? # FIXME @countingthedots: please tell me what is going on there and why???
# #
renderer = GridDraw(window_width, window_height) renderer = GridDraw(window_width, window_height)
tile_width = window_width / board_size
tile_height = window_height / board_size
radius = tile_width / 3
x = tile_width / 2
y = tile_height / 2
# rendering loop # rendering loop
while True: while True:
renderer.start_draw() renderer.start_draw()
renderer.board(board_size, board_size) renderer.board(board_size, board_size)
(x, y) = robot_movement(
window_width, window_height, tile_width, tile_height, x, y newGrid.render(renderer, window_dimensions, board_size)
)
renderer.circle(x, y, radius, color=Colors.RED)
renderer.end_draw() renderer.end_draw()
pygame.time.delay(10) pygame.time.delay(30)
# TODO wrap it all to another file that handles array rendering # TODO wrap it all to another file that handles array rendering
@ -61,22 +56,21 @@ class objectOnTile:
# calculate position from array position to window position eg.: array_position = 0 => window_position = 50 (px) # calculate position from array position to window position eg.: array_position = 0 => window_position = 50 (px)
def _translate_array_to_window_position( def _translate_array_to_window_position(array_position, tile_size_window) -> int:
array_position, window_dimensions, board_size
) -> int:
tile_size_window = window_dimensions / board_size
return array_position * tile_size_window + tile_size_window / 2 return array_position * tile_size_window + tile_size_window / 2
class Grid: class Grid:
def __init__(self, size_array, tile_size): def __init__(self, size_array):
self.array = [ self.array = [
[objectOnTile(i, j) for j in range(size_array)] for i in range(size_array) [objectOnTile(i, j) for j in range(size_array)] for i in range(size_array)
] ]
self.list: List[objectOnTile] = [] self.list: List[objectOnTile] = []
# render the array # render the array
def render(self, renderer: GridDraw, window_dimensions, board_size, tile_width): def render(self, renderer: GridDraw, window_dimensions, board_size):
tile_size = window_dimensions / board_size
# render object with respect to type # render object with respect to type
for item in self.list: for item in self.list:
if item.type == acceptedType.PLAYER: if item.type == acceptedType.PLAYER:
@ -86,17 +80,17 @@ class Grid:
# position on screen # position on screen
render_x = _translate_array_to_window_position( render_x = _translate_array_to_window_position(
item.position_x, window_dimensions, board_size item.position_x, tile_size
) )
render_y = _translate_array_to_window_position( render_y = _translate_array_to_window_position(
item.position_y, window_dimensions, board_size item.position_y, tile_size
) )
# image rendering function # image rendering function
renderer.circle( renderer.circle(
render_x, render_x,
render_y, render_y,
tile_width / PLAYER_RADIUS_RATIO, tile_size / PLAYER_RADIUS_RATIO,
color=PLAYER_COLOR, color=PLAYER_COLOR,
) )
# TODO act accordingly to other options # TODO act accordingly to other options