示例#1
0
    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
示例#2
0
    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)
示例#3
0
	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
示例#4
0
    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)
示例#5
0
    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()
示例#6
0
 def getCamerasAt(self, windowX, windowY):
     for camera in CameraManager().objects:
         if camera.windowRect.collidePoint(windowX, windowY):
             yield camera
示例#7
0
 def destroy(self):
     super().destroy()
     CameraManager().removeObject(self)