Able to consume items.
authorSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 19:05:14 +0000 (21:05 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 19:05:14 +0000 (21:05 +0200)
koperkapel/gamelib/level.py
koperkapel/scenes/level.py

index 8b275b1911f2c1f9d0ab012d355c1ecae4824d56..bcc319a2886d2f5e530d30ff70be6f7f50478a09 100644 (file)
@@ -1,8 +1,5 @@
 """ Class holding the level info """
 
-from .keypad import Keypad
-from .door import Door
-
 
 class Level(object):
 
@@ -24,8 +21,7 @@ class Level(object):
         return [self.tiles[y][x-1] if x > 0 else None,
                 self.tiles[y][x+1] if x < self.width - 1 else None,
                 self.tiles[y-1][x] if y > 0 else None,
-                self.tiles[y+1][x] if y < self.height- 1 else None,
-               ]
+                self.tiles[y+1][x] if y < self.height - 1 else None]
 
     def can_walk(self, x, y, layer):
         if 'walk' in self.tiles[y][x][layer]['behaviour']:
@@ -67,15 +63,21 @@ class Level(object):
     def get_friends(self):
         return self._friends[:]
 
-    def is_on_friend(self, x, y):
-        return (x, y) in [x.game_pos for x in self.friends]
+    def friend_at(self, x, y):
+        for f in self.friends:
+            if f.game_pos == (x, y):
+                return f
+
+    def remove_friend(self, friend):
+        self.friends.remove(friend)
+
+    def item_at(self, x, y):
+        for i in self.items:
+            if i.game_pos == (x, y):
+                return i
 
-    def remove_friend(self, x, y):
-        for friend in self.friends[:]:
-            if friend.game_pos == (x, y):
-                self.friends.remove(friend)
-                return friend
-        return None
+    def remove_item(self, item):
+        self.items.remove(item)
 
     def is_exit(self, x, y):
         return self.exit and (x, y) == tuple(self.exit["pos"])
index a1515997dc48d470044925e0193495cc904d4add..735ed28dadde623962fe417b45920b3b9aeba8d4 100644 (file)
@@ -211,13 +211,20 @@ class GameLevelScene(BaseLevelScene):
                 self._mode = 'walk'
         elif self._level.is_keypad(x, y):
             self._level.press_keypad(x, y, self._roaches)
-        elif self._level.is_on_friend(x, y):
-            friend = self._level.remove_friend(x, y)
+        elif self._level.friend_at(x, y):
+            friend = self._level.friend_at(x, y)
+            self._level.remove_friend(friend)
             self._friends.remove(friend)
             self._add_roach()
+        elif self._level.item_at(x, y):
+            item = self._level.item_at(x, y)
+            self._level.remove_item(item)
+            self._items.remove(item)
         elif self._level.is_exit(x, y):
             next_level = self._level.get_exit_level()
-            return [WorldEvent('set', {'level.name': next_level}), ChangeSceneEvent(GameLevelScene())]
+            return [
+                WorldEvent('set', {'level.name': next_level}),
+                ChangeSceneEvent(GameLevelScene())]
 
     def _fire_key(self):
         print('Boom')