self.grates = []
self.tileset = None
self.start_pos = (0, 0)
+ self.exit = None
self.enemies = []
self.friends = []
self.friends.remove(friend)
return friend
return None
+
+ def is_exit(self, x, y):
+ return self.exit and (x, y) == tuple(self.exit["pos"])
+
+ def get_exit_level(self):
+ return self.exit["next level"]
IMG = os.path.join('grate', 'grate')
TILESET = 'bunker'
+
+class Exit(Tile):
+ IMG = os.path.join('exit', 'exit')
+ TILESET = 'bunker'
+
+
class Tunnel(OrientatedTile):
@classmethod
"starting pos": [
5,
6
- ],
+ ],
+ "exit": {
+ "pos": [20, 3],
+ "next level": "level2"
+ },
"friendly roaches": [
[
2,
"starting pos": [
1,
1
- ],
+ ],
+ "exit": {
+ "pos": [20, 3],
+ "next level": "level1"
+ },
"friendly roaches": []
-}
\ No newline at end of file
+}
from pgzero.loaders import ResourceLoader
-from ..gamelib.tiles import Wall, Floor, Tunnel, Underground, Grate
+from ..gamelib.tiles import Wall, Floor, Tunnel, Underground, Grate, Exit
from ..gamelib.level import Level
from ..gamelib.door import Door
from ..gamelib.keypad import Keypad
self._level.tiles = level_data['tiles']
self._level.tileset = level_data['tileset']
self._level.start_pos = level_data["starting pos"]
+ self._level.exit = level_data["exit"]
self._level.enemies = []
self._level.friends = []
# Consistency check, so we can assume things are correct
tile['%s image' % layer] = \
TILES[tile[layer]['base']].image(neighbors)
# Hack this for now
- if layer == 'floor' and 'crawl' in tile[layer]['behaviour']:
+ if self._level.is_exit(x, y):
+ tile['floor image'] = Exit.image(neighbors)
+ elif layer == 'floor' and 'crawl' in tile[layer]['behaviour']:
tile['floor image'] = Grate.image(neighbors)
self._level.grates.append((x, y))
ev.apply(self)
def change_scene(self, scene):
+ print('here', self._scene)
self._apply_events(self._scene.exit(self._world.proxy()))
self._scene = scene
+ print('there', self._scene)
self._apply_events(self._scene.enter(self._world.proxy()))
def change_world(self, *args, **kw):
from pygame import Surface
import pygame.locals as pgl
from ..loaders.levelloader import levels
-from .base import Scene, ChangeSceneEvent, MoveViewportEvent, defer_to_update
+from .base import Scene, ChangeSceneEvent, MoveViewportEvent, WorldEvent, defer_to_update
from ..constants import TILE_SIZE, WIDTH, HEIGHT
from ..roaches import build_roach
from ..vehicles.base import Vehicle
class GameLevelScene(BaseLevelScene):
def enter(self, world):
+ print('enter', world['level']['name'], self._level)
if self._level is not None:
return
super().enter(world)
friend = self._level.remove_friend(x, y)
self._friends.remove(friend)
self._add_roach()
+ elif self._level.is_exit(x, y):
+ next_level = self._level.get_exit_level()
+ return [WorldEvent('set', {'level.name': next_level}), ChangeSceneEvent(GameLevelScene())]
def _fire_key(self):
print('Boom')