Legend of the Gold Box... A game written for the LOWREZJAM 2018 game jam
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.6KB

  1. '''
  2. Filename core.py
  3. Author: Bryan "ObsidianBlk" Miller
  4. Date Created: 8/1/2018
  5. Python Version: 3.7
  6. '''
  7. import time
  8. import pygame
  9. class Time:
  10. def __init__(self):
  11. self._dticks = 0
  12. self._ldelta = 0
  13. self._lastTick = 0
  14. @property
  15. def delta(self):
  16. tick = int(round(time.time() * 1000))
  17. dt = 0
  18. if self._lastTick > 0:
  19. dt = tick - self._lastTick
  20. self._lastTick = tick
  21. self._ldelta = dt
  22. self._dticks += dt
  23. return dt
  24. @property
  25. def last_delta(self):
  26. return self._ldelta
  27. @property
  28. def aliveTicks(self):
  29. tick = int(round(time.time() * 1000))
  30. dt = 0
  31. if self._lastTick > 0:
  32. dt = tick - self._lastTick
  33. return self._dticks + dt
  34. @property
  35. def aliveSeconds(self):
  36. return self.aliveTicks / 1000.0
  37. def reset(self):
  38. self.dticks = 0
  39. self._lastTick = int(round(time.time() * 1000))
  40. class Display:
  41. def __init__(self, width=640, height=480):
  42. self._init = False
  43. self._resolution = width, height
  44. @property
  45. def surface(self):
  46. return self._display_surface
  47. @property
  48. def width(self):
  49. return self._resolution[0]
  50. @property
  51. def height(self):
  52. return self._resolution[1]
  53. def init(self):
  54. if self._init == False:
  55. self._init = True
  56. pygame.init()
  57. self._display_surface = pygame.display.set_mode(self._resolution, pygame.HWSURFACE | pygame.DOUBLEBUF)
  58. def close(self):
  59. pygame.quit()