Doors can open (and also close)
authorNeil <neil@dip.sun.ac.za>
Sat, 5 Mar 2016 12:17:46 +0000 (14:17 +0200)
committerNeil <neil@dip.sun.ac.za>
Sat, 5 Mar 2016 12:17:57 +0000 (14:17 +0200)
koperkapel/gamelib/door.py
koperkapel/gamelib/keypad.py
koperkapel/gamelib/level.py
koperkapel/loaders/levelloader.py
koperkapel/scenes/level.py

index 9b6e56326b74359837b3357e8aa7f42a500bf021..3134e1ce8f9716d6fc9590a17c9a9b09859984e9 100644 (file)
@@ -19,5 +19,9 @@ class Door(OrientatedSurfActor):
         self._closed = False
         self.surf = self._open_surf
 
+    def close(self):
+        self._closed = True
+        self.surf = self._closed_surf
+
     def is_closed(self):
         return self._closed
index 4667fcde95924490158653a8cc3355a61e19a6c7..b328f3965e54b3af1ed0b4997ae5bd739c246f3a 100644 (file)
@@ -14,7 +14,10 @@ class Keypad(SurfActor):
         surf = images.load(os.path.join('fixtures', 'keypad'))
         super().__init__(surf, anchor=(0, 0))
 
-    def activate(self):
+    def activate(self, roaches):
         # FIXME: Check stats
         for door in self._doors:
-            door.open()
+            if door.is_closed():
+                door.open()
+            else:
+                door.close()
index 39e456588e2a2a9a2186a8475f226af3b9f14573..a8fe447494f64a6c7e3e5b04f046696f3cb90036 100644 (file)
@@ -11,6 +11,7 @@ class Level(object):
         self.tiles = []
         self.keypads = []
         self.doors = []
+        self.grates = []
         self.tileset = None
         self.start_pos = (0, 0)
 
@@ -43,8 +44,18 @@ class Level(object):
     def can_crawl(self, x, y, layer):
         return 'crawl' in self.tiles[y][x][layer]['behaviour']
 
-    def keypad_at(self, x, y):
+    def is_keypad(self, x, y):
         for keypad in self.keypads:
             if (x, y) == keypad.game_pos:
-                return keypad
-        return None
+                return True
+        return False
+
+    def is_grate(self, x, y):
+        if (x, y) in self.grates:
+            return True
+        return False
+
+    def press_keypad(self, x, y, roaches):
+        for keypad in self.keypads:
+            if (x, y) == keypad.game_pos:
+                keypad.activate(roaches)
index 9bb85e41ebf89fd57084d00cdd7f01522e318d23..524769535fccd97b87396f056146ac364a352f26 100644 (file)
@@ -55,6 +55,7 @@ class LevelLoader(ResourceLoader):
                     angle = 0
                 new_door = Door(x, y, angle)
                 self._level.doors.append(new_door)
+                doors.append(new_door)
             # Add the keypads
             for keypad in door_info['keypads']:
                 new_keypad = Keypad(keypad[0], keypad[1], doors)
@@ -72,8 +73,8 @@ class LevelLoader(ResourceLoader):
                             TILES[tile[layer]['base']].image(neighbors)
                     # Hack this for now
                     if layer == 'floor' and 'crawl' in tile[layer]['behaviour']:
-                        print('Here')
                         tile['floor image'] = Grate.image(neighbors)
+                        self._level.grates.append((x, y))
 
 
 levels = LevelLoader('levels')
index 70dd7be23931d70ff129952598c525c7c1bf65fd..ea37e154ed643a39f166a1fcd8ada72553fd8af3 100644 (file)
@@ -129,17 +129,27 @@ class GameLevelScene(BaseLevelScene):
                 self._set_pos(x + 1, y)
                 offset = (TILE_SIZE, 0)
                 self._set_angle(270)
-        elif key == keys.S:
-            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'
-                    self._mode = 'crawl'
-            elif self._level.can_crawl(x, y, 'floor'):
-                # Must be in the tunnels already
-                self._level_layer = 'floor'
-                self._mode = 'walk'
+        elif key == keys.C:
+            # Activate
+            if self._level.is_grate(x, y):
+                if self._level_layer == 'floor' and self._level.can_crawl(x, y, 'floor'):
+                    if self._level.can_crawl(x, y, 'tunnels'):
+                        self._level_layer = 'tunnels'
+                        self._mode = 'crawl'
+                elif self._level.can_crawl(x, y, 'floor'):
+                    # Must be in the tunnels already
+                    self._level_layer = 'floor'
+                    self._mode = 'walk'
+            elif self._level.is_keypad(x, y):
+                self._level.press_keypad(x, y, self._roaches)
             return
+        elif key == keys.X:
+            # Fire
+            print('Boom')
+        elif key == keys.V:
+            # Leave vehicle
+            print('Vehicle key pressed')
+            
         if offset:
             return [MoveViewportEvent(offset)]
         return super(GameLevelScene, self).on_key_down(key, mod, unicode)