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.

47 lines
986B

  1. '''
  2. Filename time.py
  3. Author: Bryan "ObsidianBlk" Miller
  4. Date Created: 8/1/2018
  5. Python Version: 3.7
  6. '''
  7. import time
  8. class Time:
  9. def __init__(self):
  10. self._dticks = 0
  11. self._ldelta = 0
  12. self._lastTick = 0
  13. @property
  14. def delta(self):
  15. tick = int(round(time.time() * 1000))
  16. dt = 0
  17. if self._lastTick > 0:
  18. dt = tick - self._lastTick
  19. self._lastTick = tick
  20. self._ldelta = dt
  21. self._dticks += dt
  22. return dt
  23. @property
  24. def last_delta(self):
  25. return self._ldelta
  26. @property
  27. def aliveTicks(self):
  28. tick = int(round(time.time() * 1000))
  29. dt = 0
  30. if self._lastTick > 0:
  31. dt = tick - self._lastTick
  32. return self._dticks + dt
  33. @property
  34. def aliveSeconds(self):
  35. return self.aliveTicks / 1000.0
  36. def reset(self):
  37. self.dticks = 0
  38. self._lastTick = int(round(time.time() * 1000))