Browse Source

Broke the game/gbe/core.py into the time.py and display.py file. Updated the __init__.py files to reflect change.

master
Bryan Miller 6 years ago
parent
commit
5c4f574a5b
4 changed files with 56 additions and 53 deletions
  1. +7
    -7
      game/__init__.py
  2. +2
    -2
      game/gbe/__init__.py
  3. +1
    -44
      game/gbe/display.py
  4. +46
    -0
      game/gbe/time.py

+ 7
- 7
game/__init__.py View File

@@ -1,4 +1,4 @@
import game.gbe
from . import gbe

_RUNNING = False

@@ -18,15 +18,15 @@ def onKeyEvent(event, data):

def start():
global _RUNNING, onKeyEvent
t = game.gbe.Time()
t = gbe.time.Time()
t.reset()

game.gbe.events.Events.listen("KEYDOWN", onKeyEvent)
game.gbe.events.Events.listen("KEYUP", onKeyEvent)
game.gbe.events.Events.listen("KEYPRESSED", onKeyEvent)
d = game.gbe.Display()
gbe.events.Events.listen("KEYDOWN", onKeyEvent)
gbe.events.Events.listen("KEYUP", onKeyEvent)
gbe.events.Events.listen("KEYPRESSED", onKeyEvent)
d = gbe.display.Display()
d.init()
_RUNNING = True
while _RUNNING:
game.gbe.events.pollEmitter()
gbe.events.pollEmitter()
d.close()

+ 2
- 2
game/gbe/__init__.py View File

@@ -1,4 +1,4 @@
from .core import Time
from .core import Display
from . import time
from . import display
from . import events
from . import nodes

+ 1
- 44
game/gbe/display.py View File

@@ -1,54 +1,11 @@
'''
Filename core.py
Filename display.py
Author: Bryan "ObsidianBlk" Miller
Date Created: 8/1/2018
Python Version: 3.7
'''
import time
import pygame


class Time:
def __init__(self):
self._dticks = 0
self._ldelta = 0
self._lastTick = 0

@property
def delta(self):
tick = int(round(time.time() * 1000))
dt = 0
if self._lastTick > 0:
dt = tick - self._lastTick
self._lastTick = tick
self._ldelta = dt
self._dticks += dt
return dt

@property
def last_delta(self):
return self._ldelta

@property
def aliveTicks(self):
tick = int(round(time.time() * 1000))
dt = 0
if self._lastTick > 0:
dt = tick - self._lastTick
return self._dticks + dt

@property
def aliveSeconds(self):
return self.aliveTicks / 1000.0

def reset(self):
self.dticks = 0
self._lastTick = int(round(time.time() * 1000))





class Display:
def __init__(self, width=640, height=480):
self._init = False

+ 46
- 0
game/gbe/time.py View File

@@ -0,0 +1,46 @@
'''
Filename time.py
Author: Bryan "ObsidianBlk" Miller
Date Created: 8/1/2018
Python Version: 3.7
'''
import time

class Time:
def __init__(self):
self._dticks = 0
self._ldelta = 0
self._lastTick = 0

@property
def delta(self):
tick = int(round(time.time() * 1000))
dt = 0
if self._lastTick > 0:
dt = tick - self._lastTick
self._lastTick = tick
self._ldelta = dt
self._dticks += dt
return dt

@property
def last_delta(self):
return self._ldelta

@property
def aliveTicks(self):
tick = int(round(time.time() * 1000))
dt = 0
if self._lastTick > 0:
dt = tick - self._lastTick
return self._dticks + dt

@property
def aliveSeconds(self):
return self.aliveTicks / 1000.0

def reset(self):
self.dticks = 0
self._lastTick = int(round(time.time() * 1000))



Loading…
Cancel
Save