Source

pymissile / pymissile.py

Full commit
from pygamebootstrapper import *
from scene import SceneManager
from menu import Menu
from battle import Battle
from intermediate import Intermediate
from constants import FPS

class Game(object):

  def __init__(self):
    self._screen = screen_factory()
    self._running = True
    self._clock = clock_factory()
    self._fps = FPS
    self._set_up_scenes()
    self.tick = 0
    
  def _set_up_scenes(self):
    self._scenes = SceneManager()
    menu, battle, intermediate = Menu(self), Battle(self), Intermediate(self)
    self._scenes.register(menu)
    self._scenes.register(battle, menu)
    self._scenes.register(intermediate, battle)
  
  def stop(self):
    self._running = False
  
  def navigate(self, key, **kwargs):
    self._scenes.navigate(key, **kwargs)
  
  def run(self):
    while self._running:
      self.tick += 1
      self._clock.tick(self._fps if not pygame.key.get_pressed()[pygame.K_t] else 999999)
      for event in event_generator():
        self._scenes.handle_event(event)
      self._scenes.update_state()
      self._scenes.draw_state(self._screen)
      update_screen()
      
if __name__ == '__main__':
  Bootstrapper().create_game(Game).run()