From 636e4ae59d15c431495325857853d8ecf80c9e52 Mon Sep 17 00:00:00 2001 From: Diogo Gomes Date: Wed, 10 Nov 2021 10:23:58 +0000 Subject: [PATCH] refactor draw blocks +1 --- viewer.py | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/viewer.py b/viewer.py index 3a337f0..341bc36 100644 --- a/viewer.py +++ b/viewer.py @@ -79,18 +79,21 @@ async def main_loop(queue): win.fill((0, 0, 0)) - for x, y in newgame_json["grid"]: - pygame.draw.rect( - win, - COLORS["blue"], - ( - x * BLOCK_SIDE / SCALE, - y * BLOCK_SIDE / SCALE, - BLOCK_SIDE / SCALE, - BLOCK_SIDE / SCALE, - ), - 0, - ) + def draw_blocks(coordinates, color, x_offset=0, y_offset=0): + for x, y in coordinates: + pygame.draw.rect( + win, + color, + ( + (x + x_offset) * BLOCK_SIDE / SCALE, + (y + y_offset) * BLOCK_SIDE / SCALE, + BLOCK_SIDE / SCALE, + BLOCK_SIDE / SCALE, + ), + 0, + ) + + draw_blocks(newgame_json["grid"], COLORS["blue"]) game_speed = newgame_json["game_speed"] @@ -121,20 +124,6 @@ async def main_loop(queue): ) continue - def draw_blocks(coordinates, color, x_offset=0, y_offset=0): - for x, y in coordinates: - pygame.draw.rect( - win, - color, - ( - (x + x_offset) * BLOCK_SIDE / SCALE, - (y + y_offset) * BLOCK_SIDE / SCALE, - BLOCK_SIDE / SCALE, - BLOCK_SIDE / SCALE, - ), - 0, - ) - draw_blocks(newgame_json["grid"], COLORS["blue"]) draw_blocks(state["game"], COLORS["red"])