Don't do unneeded work after the level's done
authorNeil <neil@dip.sun.ac.za>
Sat, 20 Apr 2013 10:20:40 +0000 (12:20 +0200)
committerNeil <neil@dip.sun.ac.za>
Sat, 20 Apr 2013 10:20:40 +0000 (12:20 +0200)
erdslangetjie/__main__.py

index bc64f000d61c3b3177d48feaf389ccc16b19b3c3..8071d303de802105fa12e429579315a02ff163bc 100644 (file)
@@ -186,17 +186,20 @@ class GameWindow(RelativeLayout):
         # Do nothing on null moves
         if not self.player.move(direction, self.level_obj):
             return
-        self.check_state()
+        if self.check_state():
+            return
         self.do_nemesis_move()
 
     def do_nemesis_move(self):
         self.nemesis.move(self.level_obj, self.player.pos)
-        self.check_state()
+        if self.check_state():
+            return
         if self.move_counter > 4:
             self.move_counter = 0
             self.draw_nemesis()
             self.nemesis.move(self.level_obj, self.player.pos)
-            self.check_state()
+            if self.check_state():
+                return
         else:
             self.move_counter += 1
         self.draw_nemesis()
@@ -249,7 +252,7 @@ class GameWindow(RelativeLayout):
 
     def check_state(self):
         if not self.level_obj:
-            return
+            return True
         if self.level_obj.at_exit(self.player.pos):
             self.reset_level()
             # Jump to next level
@@ -257,7 +260,7 @@ class GameWindow(RelativeLayout):
             if not self.load_level():
                 self._closed()
                 self.app.game_over(True)
-            return
+            return True
         elif self.check_caught():
             # Caught
             if self.app.config.getdefault('bane', 'sound', '0') != '0':
@@ -265,7 +268,7 @@ class GameWindow(RelativeLayout):
             self.reset_level()
             self._closed()
             self.app.game_over(False)
-            return
+            return True
         elif self.level_obj.is_button(self.player.pos):
             self.level_obj.trigger_button(self.player.pos)
         elif self.level_obj.is_button(self.nemesis.pos):
@@ -273,6 +276,7 @@ class GameWindow(RelativeLayout):
         for map_pos, new_tile in self.level_obj.get_changed_tiles():
             pos = (map_pos[0] * TILE_SIZE, map_pos[1] * TILE_SIZE)
             self.draw_tile(pos, new_tile)
+        return False
 
     def _calc_mouse_pos(self, pos):
         pos = self.to_local(*pos)