bugFixes
This commit is contained in:
parent
4933c04bd8
commit
be307ebab5
@ -13,10 +13,11 @@ def initial_draw(window_dimensions, board_size):
|
||||
pygame.display.set_caption("AI Vacuum Cleaner")
|
||||
|
||||
# define additional variables
|
||||
tile_size = window_width / board_size
|
||||
tile_size = window_dimensions / board_size
|
||||
|
||||
# initialize board array
|
||||
newGrid = Grid(board_size, tile_size)
|
||||
newGrid = Grid(board_size)
|
||||
newGrid.add(objectOnTile(1, 1, acceptedType.PLAYER))
|
||||
|
||||
# set window dimension
|
||||
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???
|
||||
#
|
||||
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
|
||||
while True:
|
||||
renderer.start_draw()
|
||||
renderer.board(board_size, board_size)
|
||||
(x, y) = robot_movement(
|
||||
window_width, window_height, tile_width, tile_height, x, y
|
||||
)
|
||||
renderer.circle(x, y, radius, color=Colors.RED)
|
||||
|
||||
newGrid.render(renderer, window_dimensions, board_size)
|
||||
|
||||
renderer.end_draw()
|
||||
pygame.time.delay(10)
|
||||
pygame.time.delay(30)
|
||||
|
||||
|
||||
# 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)
|
||||
def _translate_array_to_window_position(
|
||||
array_position, window_dimensions, board_size
|
||||
) -> int:
|
||||
tile_size_window = window_dimensions / board_size
|
||||
def _translate_array_to_window_position(array_position, tile_size_window) -> int:
|
||||
return array_position * tile_size_window + tile_size_window / 2
|
||||
|
||||
|
||||
class Grid:
|
||||
def __init__(self, size_array, tile_size):
|
||||
def __init__(self, size_array):
|
||||
self.array = [
|
||||
[objectOnTile(i, j) for j in range(size_array)] for i in range(size_array)
|
||||
]
|
||||
self.list: List[objectOnTile] = []
|
||||
|
||||
# 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
|
||||
for item in self.list:
|
||||
if item.type == acceptedType.PLAYER:
|
||||
@ -86,17 +80,17 @@ class Grid:
|
||||
|
||||
# position on screen
|
||||
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(
|
||||
item.position_y, window_dimensions, board_size
|
||||
item.position_y, tile_size
|
||||
)
|
||||
|
||||
# image rendering function
|
||||
renderer.circle(
|
||||
render_x,
|
||||
render_y,
|
||||
tile_width / PLAYER_RADIUS_RATIO,
|
||||
tile_size / PLAYER_RADIUS_RATIO,
|
||||
color=PLAYER_COLOR,
|
||||
)
|
||||
# TODO act accordingly to other options
|
||||
|
Loading…
Reference in New Issue
Block a user