Skip to content

Commit

Permalink
refactor draw blocks +1
Browse files Browse the repository at this point in the history
  • Loading branch information
dgomes committed Nov 10, 2021
1 parent 0251aac commit 636e4ae
Showing 1 changed file with 15 additions and 26 deletions.
41 changes: 15 additions & 26 deletions viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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"])
Expand Down

0 comments on commit 636e4ae

Please sign in to comment.