def Quit( self ): #print 'mm quitting' newModel = self.nextModelClass() mvcState.SetModel( newModel ) controller = mvcState.GetController() controller.gameEventListeners.remove( self )
def HandlePygameEvents(self): events = pygame.event.get() view = mvcState.GetView() model = mvcState.GetModel() for event in events: if event.type == QUIT: #model.Quit() mvcState.SetModel(SystemQuitFlag()) elif event.type == KEYDOWN and event.key == K_ESCAPE: model.Quit() elif event.type == KEYDOWN: #KeyDown( event ) pass elif event.type == KEYUP: #KeyUp( event ) pass elif event.type == MOUSEBUTTONDOWN: for listener in self.mouseListeners: listener.OnMouseDown(event.pos) elif event.type == MOUSEBUTTONUP: for listener in self.mouseListeners: listener.OnMouseUp(event.pos) elif event.type == MOUSEMOTION: for listener in self.mouseListeners: listener.OnMouseMove(event)
def OnWin( self, time, money ): #log.debug( "FMODEL GOT WIIIIIIIIIIIIIIIIIIIIIN" ) controller = mvcState.GetController() controller.gameEventListeners.remove( self ) for s in self.objects.sprites(): s.kill() mvcState.SetModel( WinScreenModel( time, money ) )
def Quit( self ): controller = mvcState.GetController() controller.gameEventListeners.remove( self ) for s in self.objects.sprites(): s.kill() #log.debug( "SETTING MM FLAG" ) mvcState.SetModel( MainMenuFlag() )
def Quit( self ): #print 'mm quitting' controller = mvcState.GetController() controller.mouseListeners.remove( self.freestyleButton ) controller.mouseListeners.remove( self.freestyleTrickyButton ) controller.mouseListeners.remove( self.speedyButton ) controller.mouseListeners.remove( self.firehoseButton ) controller.mouseListeners.remove( self.sharpshooterButton ) controller.mouseListeners.remove( self.debugButton ) if not self.nextModelClass: self.nextModelClass = SystemQuitFlag newModel = self.nextModelClass() mvcState.SetModel( newModel )
def main(): """this function is called when the program starts. it initializes everything it needs, then runs in a loop until the function returns.""" #Initialize Everything global screen screen = None pygame.init() screen = pygame.display.set_mode(RESOLUTION) pygame.display.set_caption('Steam Jet Blower') #pygame.mouse.set_visible(0) #Prepare Game Objects #main menu handles the responsibilities of both: M and V model = MainMenu(screen, pygame.display) mvcState.SetModel(model) controller = DefaultController() mvcState.SetController(controller) view = None sMangr = SoundManager() #Main Loop clock = pygame.time.Clock() oldfps = 0 while 1: timeChange = clock.tick(40) newfps = int(clock.get_fps()) #if newfps != oldfps: #print "fps: ", newfps #oldfps = newfps if mvcState.justChanged: model = mvcState.GetModel() log.debug('state was jsut changed') if mvcState.GetModel() == None \ or isinstance( mvcState.GetModel(), SystemQuitFlag ): log.debug('quittin') break if isinstance(mvcState.GetModel(), MainMenuFlag): log.debug('flagged for MM') model = MainMenu(screen, pygame.display) mvcState.SetModel(model) view = model mvcState.SetView(view) elif isinstance(model, FreestyleModel): view = GameView(screen, pygame.display) mvcState.SetView(view) elif isinstance(model, WinScreenModel): view = WinScreenView(screen, pygame.display) mvcState.SetView(view) elif isinstance(model, MainMenu): view = model mvcState.SetView(view) mvcState.justChanged = False #print 'calling start() on', model model.Start() #Handle Keyboard / Mouse Input Events controller.HandlePygameEvents() #if the mvcState changed because of some event, skip next steps if mvcState.justChanged: continue #Clear Everything view.Clear() #Update view.Update(timeChange) model.Update(timeChange) sMangr.Update(timeChange) #if the mvcState changed because of the update, skip next steps if mvcState.justChanged: continue #Draw Everything view.Draw() #Game Over log.debug("Game is over") pygame.quit()