-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel_creator.py
More file actions
37 lines (28 loc) · 1.23 KB
/
level_creator.py
File metadata and controls
37 lines (28 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""Draws the levels"""
from __future__ import absolute_import
import pygame
from constants import Levels, Sprites
class LevelCreator:
"""Draws the current level"""
def __init__(self) -> None:
self.level_dimensions = Levels.LEVEL_DIMENSIONS
self.brick = Sprites.BRICK
self.coin = Sprites.COIN
self.brick_rects = []
self.coin_rect = []
def draw_level(self, background: pygame.Surface, level_layout: str) -> pygame.Surface:
"""Draws the specified level"""
for i in range(self.level_dimensions[1]):
for j in range(self.level_dimensions[0]):
character = level_layout[i*self.level_dimensions[0] + j]
if character == '#':
self.brick_rects.append(pygame.Rect((j*20, i*20), Sprites.BRICK_SIZE))
background.blit(self.brick, (j*20, i*20))
elif character == 'O':
self.brick_rects.append(pygame.Rect((j*20, i*20), Sprites.COIN_SIZE))
background.blit(self.coin, (j*20, i*20))
return background
def get_bricks(self) -> list[pygame.Rect]:
"""Returns the array of brick Rects"""
return self.brick_rects
level_creator = LevelCreator()