Hook up crawl behaviour. Make tunnel entrance even harder to find as a result
authorNeil <neil@dip.sun.ac.za>
Sat, 5 Mar 2016 09:59:49 +0000 (11:59 +0200)
committerNeil <neil@dip.sun.ac.za>
Sat, 5 Mar 2016 10:00:02 +0000 (12:00 +0200)
koperkapel/gamelib/level.py
koperkapel/gamelib/tiles.py
koperkapel/scenes/level.py

index 8c93baabb6533feb99f1f7ed50cbc547a28724d7..01c260e7d5859cd836cbc52a336116f8fe7398c6 100644 (file)
@@ -22,3 +22,6 @@ class Level(object):
 
     def can_fly(self, x, y, layer):
         return 'fly' in self.tiles[y][x][layer]['behaviour']
+
+    def can_crawl(self, x, y, layer):
+        return 'crawl' in self.tiles[y][x][layer]['behaviour']
index 382a2eab8bf72fa11cccf9ea0b25d21366e8761a..66a74ff05eee0cf6c6aee259f041762e7d31b94a 100644 (file)
@@ -64,7 +64,7 @@ class Tunnel(OrientatedTile):
 
     @classmethod
     def image(cls, neighbors):
-        connections = [True if 'walk' in x['behaviour'] else False for x in neighbors]
+        connections = [True if 'crawl' in x['behaviour'] else False for x in neighbors]
         conn_count = connections.count(True)
         # simple cases
         cls.ANGLE = 0
index 9dd8b61e3d7958ab67f7f25ae62b9467de770c7a..867eaacebea738a350fc27c73cdc94d870525c60 100644 (file)
@@ -62,6 +62,7 @@ class GameLevelScene(BaseLevelScene):
     def enter(self, world):
         super().enter(world)
         self._roaches = self.actors.add_layer("roaches", level=10)
+        self._mode = 'walk'
         return self._init_roaches(world.roaches)
 
     def _init_roaches(self, roaches):
@@ -78,32 +79,43 @@ class GameLevelScene(BaseLevelScene):
     def _set_pos(self, x, y):
         self._player_pos = (x, y)
 
+    def _can_move(self, x, y):
+        if self._mode == 'walk':
+            return self._level.can_walk(x, y, self._level_layer)
+        elif self._mode == 'fly':
+            return self._level.can_fly(x, y, self._level_layer)
+        elif self._mode == 'crawl':
+            return self._level.can_crawl(x, y, self._level_layer)
+
     def on_key_down(self, key, mod, unicode):
         offset = None
         x, y = self._player_pos
         if key == keys.DOWN:
-            if self._level.can_walk(x, y + 1, self._level_layer):
+            if self._can_move(x, y + 1):
                 self._set_pos(x, y + 1)
                 offset = (0, TILE_SIZE)
         elif key == keys.UP:
-            if self._level.can_walk(x, y - 1, self._level_layer):
+            if self._can_move(x, y - 1):
                 self._set_pos(x, y - 1)
                 offset = (0, -TILE_SIZE)
         elif key == keys.LEFT:
-            if self._level.can_walk(x - 1, y, self._level_layer):
+            if self._can_move(x - 1, y):
                 self._set_pos(x - 1, y)
                 offset = (-TILE_SIZE, 0)
         elif key == keys.RIGHT:
-            if self._level.can_walk(x + 1, y, self._level_layer):
+            if self._can_move(x + 1, y):
                 self._set_pos(x + 1, y)
                 offset = (TILE_SIZE, 0)
         elif key == keys.S:
-            if self._level_layer == 'floor':
-                if self._level.can_walk(x, y, 'tunnels'):
+            if self._level_layer == 'floor' and self._level.can_crawl(x, y, 'floor'):
+                # We're probably on a grate
+                if self._level.can_crawl(x, y, 'tunnels'):
                     self._level_layer = 'tunnels'
-            elif self._level.can_walk(x, y, 'floor'):
+                    self._mode = 'crawl'
+            elif self._level.can_crawl(x, y, 'floor'):
                 # Must be in the tunnels already
                 self._level_layer = 'floor'
+                self._mode = 'walk'
             return
         if offset:
             return [MoveViewportEvent(offset)]