From: Neil Date: Thu, 18 Apr 2013 19:36:15 +0000 (+0200) Subject: refactor reset code. Add extra move to speed up nemesis a bit X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=1f3785002aba3ffe7e905d4f7b86c0782f1ca15c;p=erdslangetjie.git refactor reset code. Add extra move to speed up nemesis a bit --- 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):