Guest User

Untitled

a guest
Jan 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. # Set up main variables and start main loop
  2.  
  3. def __init__(self,mainApp,returnFunction,mechanics):
  4.  
  5. pygame.init()
  6. pygame.font.init()
  7. self.accountManager = mainApp.accountManager
  8. self.root = mainApp.parent
  9. self.endGame = returnFunction
  10. self.mechanics = mechanics
  11.  
  12. self.screenDimensions = (800,600)
  13. self.running = True
  14.  
  15. # Create screen (starts the program in effect)
  16. self.screen = pygame.display.set_mode(self.screenDimensions,0,32)
  17. pygame.display.set_caption("Invoker Trainer")
  18.  
  19. self.states = {}
  20. self.states[StartMenu]= StartMenu(self,self.accountManager.currentAccount.settings)
  21. self.states[Main] = Main(self,self.mechanics)
  22. self.states[Paused] = Paused(self)
  23. self.currentState = self.states[StartMenu]
  24.  
  25. self.mainLoop()
  26.  
  27. def mainLoop(self):
  28.  
  29. # Get the events and use the current state to handle them
  30. events = pygame.event.get()
  31. self.currentState.handleEvents(events)
  32.  
  33. # Handle quit event and if quit, set running to false so the return function can be called
  34. for event in events:
  35. if event.type == pygame.QUIT:
  36. self.running = False
  37. break
  38.  
  39. # Get current state to render and update
  40. self.currentState.update()
  41. self.currentState.render(surface = self.screen)
  42. pygame.display.flip()
  43.  
  44. # Only loop if still running
  45. if not self.running:
  46. pygame.display.quit()
  47. pygame.font.quit()
  48. pygame.quit()
  49. self.endGame()
  50. else:
  51. self.root.after(17,self.mainLoop)
Add Comment
Please, Sign In to add comment