Browse Source

Initial commit with very rough pygame application class.

master
Bryan Miller 6 years ago
commit
2bced431ba
6 changed files with 50 additions and 0 deletions
  1. +1
    -0
      game/__init__.py
  2. BIN
      game/__pycache__/__init__.cpython-36.pyc
  3. BIN
      game/__pycache__/application.cpython-36.pyc
  4. +41
    -0
      game/application.py
  5. +0
    -0
      game/gbe/__init__.py
  6. +8
    -0
      gb.py

+ 1
- 0
game/__init__.py View File

@@ -0,0 +1 @@
from game.application import Application

BIN
game/__pycache__/__init__.cpython-36.pyc View File


BIN
game/__pycache__/application.cpython-36.pyc View File


+ 41
- 0
game/application.py View File

@@ -0,0 +1,41 @@

import time
import pygame
from pygame.locals import *

class Application:
def __init__(self, width=640, height=480):
self._running = False
self._init = False
self._resolution = width, height
self.lastFrameTime = 0

def init(self):
pygame.init()
self._display_surface = pygame.display.set_mode(self._resolution, pygame.HWSURFACE | pygame.DOUBLEBUF)
self._init = True

def on_event(self, event):
if event.type == pygame.QUIT:
self._running = False

def on_cleanup(self):
pygame.quit()

def execute(self):
# We want to automatically exit if app is already running or if app hasn't yet been init.
if self._running or not self._init:
return False
self._running = True

while self._running:
# Calculate delta time since last frame.
currentTime = time.time()
dt = 0
if self.lastFrameTime != 0:
dt = currentTime - self.lastFrameTime
self.lastFrameTime = currentTime

for event in pygame.event.get():
self.on_event(event)
self.on_cleanup()

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


+ 8
- 0
gb.py View File

@@ -0,0 +1,8 @@

import game


if __name__ == "__main__":
app = game.Application()
app.init()
app.execute()

Loading…
Cancel
Save