-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEngine.py
52 lines (45 loc) · 1.59 KB
/
Engine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pygame
import importlib
import threading as t
from testGame.scenes import TestScene1
from Importer import importer
class Engine:
screen = None
running = True
sceneDict = {}
currentScene = None
loadedPhysicsObjects = []
loadedStaticObjects = []
def init(self, subdir, x,y, scene):
pygame.init()
self.screen = pygame.display.set_mode([x,y])
#screen.fill(255,255,255)
#add all scenes to sceneDict
sceneName = ""
for sceneName in importer(subdir +"/scenes"):
module = importlib.import_module("scenes." + sceneName,subdir)
sceneObj = getattr(module,sceneName)
self.sceneDict.update({sceneName:sceneObj(subdir)})
#load default scene
self.currentScene = self.sceneDict[scene]
#begin game proccessing
self._process()
def _process(self):
while self.running:
#quit program
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.running = False
#check for changed scene
if self.currentScene.setScene != False:
currentScene = self.sceneDict[self.currentScene.setScene]
#get any new objects in scene
physicsObjects = self.currentScene.getPhysicsObjects()
staticObjects = self.currentScene.getStaticObjects()
#proccessing object movements
self.currentScene.process(self.screen)
self.screen.update()
#display all objects
pygame.quit()
def testFunc():
print("test")