From 1f3785002aba3ffe7e905d4f7b86c0782f1ca15c Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 18 Apr 2013 21:36:15 +0200 Subject: [PATCH] refactor reset code. Add extra move to speed up nemesis a bit --- erdslangetjie/__main__.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/erdslangetjie/__main__.py b/erdslangetjie/__main__.py index d8904ef..b4c25c2 100644 --- a/erdslangetjie/__main__.py +++ b/erdslangetjie/__main__.py @@ -49,6 +49,7 @@ class GameWindow(RelativeLayout): self.player_tile = None self.nemesis_tile = None self.timer_set = False + self.move_counter = 0 self.player.pos = self.level_obj.enter_pos if platform() != 'android': @@ -191,6 +192,7 @@ class GameWindow(RelativeLayout): def do_nemesis_move(self): self.nemesis.move(self.level_obj, self.player.pos) + self.move_counter += 1 self.check_state() self.reset_timer() self.draw_nemesis() @@ -204,7 +206,12 @@ class GameWindow(RelativeLayout): def reset_timer(self): self.timer_set = True Clock.unschedule(self.timed_move) - Clock.schedule_once(self.timed_move, 0.5) + if self.move_counter > 4: + self.move_counter = 0 + # The superhero is faster than the player + Clock.schedule_once(self.timed_move, 0.02) + else: + Clock.schedule_once(self.timed_move, 1) def check_caught(self): return self.nemesis.pos == self.player.pos @@ -212,9 +219,12 @@ class GameWindow(RelativeLayout): def reset_level(self): Clock.unschedule(self.timed_move) self.timer_set = False + self.move_counter = 0 if self.nemesis_tile: self.remove_widget(self.nemesis_tile) self.nemesis.reset_pos() + + def load_level(self): if self.level_obj: self.level_obj.load_tiles() self.player.pos = self.level_obj.enter_pos @@ -231,13 +241,16 @@ class GameWindow(RelativeLayout): if not self.level_obj: return if self.level_obj.at_exit(self.player.pos): + self.reset_level() # Jump to next level self.level_obj = self.level_list.advance_to_next_level() - if not self.reset_level(): + if not self.load_level(): self.app.game_over(True) return elif self.check_caught(): # Caught + self.reset_level() + self.load_level() self.app.game_over(False) return elif self.level_obj.is_button(self.player.pos): -- 2.34.1