Legend of the Gold Box... A game written for the LOWREZJAM 2018 game jam
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

42 lines
1.2KB

  1. import time
  2. import pygame
  3. from pygame.locals import *
  4. class Application:
  5. def __init__(self, width=640, height=480):
  6. self._running = False
  7. self._init = False
  8. self._resolution = width, height
  9. self.lastFrameTime = 0
  10. def init(self):
  11. pygame.init()
  12. self._display_surface = pygame.display.set_mode(self._resolution, pygame.HWSURFACE | pygame.DOUBLEBUF)
  13. self._init = True
  14. def on_event(self, event):
  15. if event.type == pygame.QUIT:
  16. self._running = False
  17. def on_cleanup(self):
  18. pygame.quit()
  19. def execute(self):
  20. # We want to automatically exit if app is already running or if app hasn't yet been init.
  21. if self._running or not self._init:
  22. return False
  23. self._running = True
  24. while self._running:
  25. # Calculate delta time since last frame.
  26. currentTime = time.time()
  27. dt = 0
  28. if self.lastFrameTime != 0:
  29. dt = currentTime - self.lastFrameTime
  30. self.lastFrameTime = currentTime
  31. for event in pygame.event.get():
  32. self.on_event(event)
  33. self.on_cleanup()