Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Set up main variables and start main loop
- def __init__(self,mainApp,returnFunction,mechanics):
- pygame.init()
- pygame.font.init()
- self.accountManager = mainApp.accountManager
- self.root = mainApp.parent
- self.endGame = returnFunction
- self.mechanics = mechanics
- self.screenDimensions = (800,600)
- self.running = True
- # Create screen (starts the program in effect)
- self.screen = pygame.display.set_mode(self.screenDimensions,0,32)
- pygame.display.set_caption("Invoker Trainer")
- self.states = {}
- self.states[StartMenu]= StartMenu(self,self.accountManager.currentAccount.settings)
- self.states[Main] = Main(self,self.mechanics)
- self.states[Paused] = Paused(self)
- self.currentState = self.states[StartMenu]
- self.mainLoop()
- def mainLoop(self):
- # Get the events and use the current state to handle them
- events = pygame.event.get()
- self.currentState.handleEvents(events)
- # Handle quit event and if quit, set running to false so the return function can be called
- for event in events:
- if event.type == pygame.QUIT:
- self.running = False
- break
- # Get current state to render and update
- self.currentState.update()
- self.currentState.render(surface = self.screen)
- pygame.display.flip()
- # Only loop if still running
- if not self.running:
- pygame.display.quit()
- pygame.font.quit()
- pygame.quit()
- self.endGame()
- else:
- self.root.after(17,self.mainLoop)
Add Comment
Please, Sign In to add comment