refactor reset code. Add extra move to speed up nemesis a bit
authorNeil <neil@dip.sun.ac.za>
Thu, 18 Apr 2013 19:36:15 +0000 (21:36 +0200)
committerNeil <neil@dip.sun.ac.za>
Thu, 18 Apr 2013 19:36:15 +0000 (21:36 +0200)
erdslangetjie/__main__.py

index d8904ef239f3b3814413490a9480742f749412ac..b4c25c2814b7e60d9e02470dbd0d1b4e19dead0a 100644 (file)
@@ -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):