From: Neil Date: Sat, 20 Apr 2013 10:20:40 +0000 (+0200) Subject: Don't do unneeded work after the level's done X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=f9257acfddf031c4137eae93dfddaa31e0b6029c;p=erdslangetjie.git Don't do unneeded work after the level's done --- diff --git a/erdslangetjie/__main__.py b/erdslangetjie/__main__.py index bc64f00..8071d30 100644 --- a/erdslangetjie/__main__.py +++ b/erdslangetjie/__main__.py @@ -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)