6 from pgzero.constants import keys
7 from pgzero.loaders import images
8 from .base import Scene, ChangeSceneEvent
9 from .constants import TILE_SIZE, LEVEL_PATH
12 class LevelScene(Scene):
15 def __init__(self, level_name):
16 self._level_name = level_name
17 f = open(os.path.join(LEVEL_PATH, level_name + '.json'))
18 level_data = json.load(f)
20 self._tiles = level_data['tiles']
21 self._load_tile_images()
23 def draw(self, screen):
25 #screen.draw.text("This is level {}".format(self._level_name), (200, 100))
26 for tile in self._tiles:
28 pos = [pos[0] * TILE_SIZE, pos[1] * TILE_SIZE]
29 if not 'image' in tile:
30 # Skip broken tiles for now
32 screen.blit(tile['image'], pos)
34 def _load_tile_images(self):
35 """Load all the tile images"""
36 for tile in self._tiles:
37 tile['image'] = getattr(images, tile['base'])
39 def on_key_down(self, key, mod, unicode):
40 if key == keys.ESCAPE:
41 from .menu import MenuScene
42 return [ChangeSceneEvent(MenuScene())]