1 """Render a level and allow moving the scene"""
5 from pygame.constants import BLEND_RGBA_MULT
6 from pgzero.constants import keys
7 from pgzero.loaders import images
8 from .level import BaseLevelScene
9 from .base import MoveViewportEvent
10 from ..constants import TILE_SIZE
13 class ViewLevelScene(BaseLevelScene):
16 def enter(self, world):
18 # Mark starting position
19 self._roach = images.load(os.path.join("roach/roach_1")).copy()
20 self._roach.fill((255, 0, 0, 255), None, BLEND_RGBA_MULT)
21 x = self._level.start_pos[0] * TILE_SIZE
22 y = self._level.start_pos[1] * TILE_SIZE
23 for layer in ['floor', 'tunnels']:
24 self._surfaces[layer].blit(self._roach, (x, y))
26 def on_key_down(self, key, mod, unicode):
29 offset = (0, TILE_SIZE)
31 offset = (0, -TILE_SIZE)
32 elif key == keys.LEFT:
33 offset = (-TILE_SIZE, 0)
34 elif key == keys.RIGHT:
35 offset = (TILE_SIZE, 0)
37 if self._level_layer == 'floor':
38 self._level_layer = 'tunnels'
40 self._level_layer = 'floor'
43 return [MoveViewportEvent(offset)]
44 return super(ViewLevelScene, self).on_key_down(key, mod, unicode)