def setup(self): ''' This method is called by the Gameloop in order to initialise the Display. It provides the implementation of the state change listener such that the Display can react on specific state transitions. ''' Gamestate.get().add_gamestate_change_listener(self.mGamestateChangeListener(self))
def setup(self): self.display = Display() self.sound = Sound() self.gamestate = Gamestate() # given that there is some iteraction between the game view # and the game logic, separate the setup for both self.display.setup() self.sound.setup() self.gamestate.setup()
def setup(self): ''' This method is called by the Gameloop in order to initialise the Display. It provides the implementation of the state change listener such that the Display can react on specific state transitions. ''' setup_window_on_top_signal() set_window_on_top() Gamestate.get().add_gamestate_change_listener( self.mGamestateChangeListener(self))
def __init__(self, display, background): super(FlappyFlyingHUD, self).__init__(display) self.background = background # the score needs to be cleared and drawn everytime it updates self.score_text_sprite = pygame.sprite.Sprite() self.score_text_group = pygame.sprite.Group(self.score_text_sprite) self.update_score(0) # implement the onScoreChanged interface of FlappyFlyingState Gamestate.get().current_state.add_score_changed_listener(self.mScoreChangedListener(self))
def __init__(self, display, background): super(FlappyFlyingHUD, self).__init__(display) self.background = background # the score needs to be cleared and drawn everytime it updates self.score_text_sprite = pygame.sprite.Sprite() self.score_text_group = pygame.sprite.Group(self.score_text_sprite) self.update_score(0) # implement the onScoreChanged interface of FlappyFlyingState Gamestate.get().current_state.add_score_changed_listener( self.mScoreChangedListener(self))
def setup(self): ''' This method is called by the Gameloop in order to initialise the Sound class. It provides the implementation of the state change listener such that it can play various sounds specific to state transitions. ''' # check that the platform supports sound playback # if it doesn't, then it won't implement any listeners initialised = pygame.mixer.get_init() if initialised: debugger("Sound: __init__: Mixer is available and is initialised:" \ " frequency = {}, format = {}, channels = {}" .format(initialised[0], initialised[1], initialised[2])) Gamestate.get().add_gamestate_change_listener(self.mGamestateChangeListener(self)) else: debugger("Sound: __init__: Mixer is not available! Game will not have sounds!")
class Gameloop(object): ''' This class is used by the binary 'bin/flappy-judoka'. It ticks the time, updates the game logic, and draws a new frame. ''' # the maximum fps the game will be running at FRAMES_PER_SECOND = 60 def __init__(self): self.clock = pygame.time.Clock() self.setup() def setup(self): self.display = Display() self.sound = Sound() self.gamestate = Gamestate() # given that there is some iteraction between the game view # and the game logic, separate the setup for both self.display.setup() self.sound.setup() self.gamestate.setup() def run(self): debugger('Gameloop: run: Starting gameloop') while self.gamestate.is_running: # get the elapsed time since last tick and cap the fps delta_t_ms = self.clock.tick(self.FRAMES_PER_SECOND) delta_t_sec = delta_t_ms / 1000.0 fps = self.clock.get_fps() drawables = self.gamestate.update(delta_t_sec) self.display.update(drawables, fps) debugger('Gameloop: run: Exiting gameloop')
class Gameloop(object): ''' This class is used by the binary 'bin/flappy-judoka'. It ticks the time, updates the game logic, and draws a new frame. ''' # the maximum fps the game will be running at FRAMES_PER_SECOND = 60 def __init__(self): self.clock = pygame.time.Clock() self.setup() def setup(self): self.display = Display() self.sound = Sound() self.gamestate = Gamestate() # given that there is some iteraction between the game view # and the game logic, separate the setup for both self.display.setup() self.sound.setup() self.gamestate.setup() def run(self): debugger("Gameloop: run: Starting gameloop") while self.gamestate.is_running: # get the elapsed time since last tick and cap the fps delta_t_ms = self.clock.tick(self.FRAMES_PER_SECOND) delta_t_sec = delta_t_ms / 1000.0 fps = self.clock.get_fps() drawables = self.gamestate.update(delta_t_sec) self.display.update(drawables, fps) debugger("Gameloop: run: Exiting gameloop")
def on_flappy_flying(self): debugger("Sound: mGamestateChangeListener: on_flappy_flying: Setting ScoreChangedListener and FlappyFlapListener") Gamestate.get().current_state.flappy.add_flappy_flap_listener(self.parent.mFlappyFlapListener(self.parent)) Gamestate.get().current_state.add_score_changed_listener(self.parent.mScoreChangedListener(self.parent))