if true_point[0] >= self.view.size[0]:
self.view.scroll_x += self.x_scroll_margin
true_point = self.to_parent(*check_point)
- #print '-x', self.view.scroll_x, self.view.scroll_y
elif true_point[0] < 0:
self.view.scroll_x -= self.x_scroll_margin
true_point = self.to_parent(*check_point)
- #print '+x', self.view.scroll_x, self.view.scroll_y
elif true_point[1] >= self.view.size[1]:
self.view.scroll_y += self.y_scroll_margin
true_point = self.to_parent(*check_point)
- #print '+y', self.view.scroll_x, self.view.scroll_y
elif true_point[1] < 0:
self.view.scroll_y -= self.y_scroll_margin
true_point = self.to_parent(*check_point)
- #print '-y', self.view.scroll_x, self.view.scroll_y
- #print true_point, self.view.size
def included(self, point, margin):
if point[0] < margin:
def do_nemesis_move(self):
self.nemesis.move(self.level_obj, self.player.pos)
- self.move_counter += 1
self.check_state()
- self.reset_timer()
+ if self.move_counter > 4:
+ self.move_counter = 0
+ self.draw_nemesis()
+ self.nemesis.move(self.level_obj, self.player.pos)
+ self.check_state()
+ else:
+ self.move_counter += 1
self.draw_nemesis()
self.draw_player()
+ self.reset_timer()
def timed_move(self, event):
if not self.level_obj:
def reset_timer(self):
self.timer_set = True
Clock.unschedule(self.timed_move)
- 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)
+ Clock.schedule_once(self.timed_move, 3)
def check_caught(self):
return self.nemesis.pos == self.player.pos
# Jump to next level
self.level_obj = self.level_list.advance_to_next_level()
if not self.load_level():
- self.app.game_over(True)
+ app = self.app
+ self.app = None
+ self._closed()
+ app.game_over(True)
return
elif self.check_caught():
# Caught
self.reset_level()
- self.load_level()
- self.app.game_over(False)
+ app = self.app
+ self.app = None
+ self._closed()
+ app.game_over(False)
return
elif self.level_obj.is_button(self.player.pos):
self.level_obj.trigger_button(self.player.pos)
def __init__(self):
super(GameApp, self).__init__()
self.levels = LevelList()
+ self.game = None
def build(self):
root = ScrollView(size_hint=(None, None))
def start_game(self, label, ref):
"""Start the game"""
- game = GameWindow(self.levels, self)
- game.build()
+ self.game = GameWindow(self.levels, self)
+ self.game.build()
self.root.clear_widgets()
- self.root.add_widget(game)
+ self.root.add_widget(self.game)
# Ensure the player is visible
self.root.scroll_x = 0
self.root.scroll_y = 0
- game.draw_player()
- game.draw_nemesis()
+ self.game.draw_player()
+ self.game.draw_nemesis()
def game_over(self, won):
if won:
self.levels.reset()
else:
screen = LostScreen(self)
+ del self.game
+ self.game = None
self.root.clear_widgets()
self.root.add_widget(screen)