1 """Render a level and allow moving the scene"""
3 from pygame.constants import BLEND_RGBA_MULT
4 from pgzero.constants import keys
5 from pgzero.loaders import images
6 from .level import BaseLevelScene
7 from .base import MoveViewportEvent
8 from ..constants import TILE_SIZE
9 from ..util import safepath
12 class ViewLevelScene(BaseLevelScene):
15 def enter(self, world):
17 # Mark starting position
18 self._roach = images.load(safepath("roach/roach_1")).copy()
19 self._roach.fill((255, 0, 0, 255), None, BLEND_RGBA_MULT)
20 x = self._level.start_pos[0] * TILE_SIZE
21 y = self._level.start_pos[1] * TILE_SIZE
22 for layer in ['floor', 'tunnels']:
23 self._surfaces[layer].blit(self._roach, (x, y))
25 def on_key_down(self, key, mod, unicode):
28 offset = (0, TILE_SIZE)
30 offset = (0, -TILE_SIZE)
31 elif key == keys.LEFT:
32 offset = (-TILE_SIZE, 0)
33 elif key == keys.RIGHT:
34 offset = (TILE_SIZE, 0)
36 if self._level_layer == 'floor':
37 self._level_layer = 'tunnels'
39 self._level_layer = 'floor'
42 return [MoveViewportEvent(offset)]
43 return super(ViewLevelScene, self).on_key_down(key, mod, unicode)