def on_update(cls, dt: float): cls.dt = dt while not cls.callableQueue.empty(): callable = cls.callableQueue.get() callable() for gameObject in cls.gameObjects: for script in gameObject.scripts: script.onUpdate() from gameengine.managers.CameraManager import CameraManager for camera in CameraManager().collection: for script in camera.scripts: script.onUpdate() from gameengine.managers.PhysicsManager import PhysicsManager PhysicsManager().onUpdate(dt) from gameengine.managers.CollisionManager import CollisionManager CollisionManager().onUpdate(dt) Timer.tick() for gameObject in cls.gameObjects.copy(): for script in gameObject.scripts: script.onLateUpdate() from gameengine.managers.CameraManager import CameraManager for camera in CameraManager().collection: for script in camera.scripts: script.onLateUpdate() cls.frameCount += 1
def draw(self): for camera in CameraManager().collection: glClearColor(camera.backgroundColor[0] / 255, camera.backgroundColor[1] / 255, camera.backgroundColor[2] / 255, camera.backgroundColor[3] / 255) camera.worldProjection() sprites = self.frustumCulling.intersect( (*camera.transform.position, *(camera.transform.position + camera.size / camera.zoom))) for sprite in sprites: sprite.draw() glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) ### for elem in self.GUI: for camera in CameraManager().collection: camera.hudProjection() elem.draw() glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
def _getCameraAt(self, x, y) -> Camera: for camera in CameraManager().collection: rect = Rect(*camera.windowPosition, *camera.size) if rect.collidePoint(x, y): return camera return None
def __init__(self): super().__init__() self.managers = [] # TODO minor fix CameraManager().addObject(self) self.enabled = True self.windowRect = Rect(0, 0, 0, 0) self._zoom = 1.0 self.backgroundColor = (128, 128, 255)
def draw(cls): if cls.display == None: print("Pygame display not set") cls.shutdown() # Clear display cls.display.fill((0, 0, 0)) # Draw CameraManager().draw() # Update screen pygame.display.update()
def getCamerasAt(self, windowX, windowY): for camera in CameraManager().objects: if camera.windowRect.collidePoint(windowX, windowY): yield camera
def destroy(self): super().destroy() CameraManager().removeObject(self)