Exemple #1
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
 def clampOff(self, thisRect: Rect, otherRect: Rect, side):
     if side == TOP_SIDE:
         thisRect.top = otherRect.bottom
     elif side == RIGHT_SIDE:
         thisRect.right = otherRect.left
     elif side == BOTTOM_SIDE:
         thisRect.bottom = otherRect.top
     elif side == LEFT_SIDE:
         thisRect.left = otherRect.right
Exemple #3
0
def clampOff(thisRect: Rect, otherRect: Rect, side):
    if side == Sides.TOP_SIDE:
        thisRect.bottom = otherRect.top
    elif side == Sides.RIGHT_SIDE:
        thisRect.right = otherRect.left
    elif side == Sides.BOTTOM_SIDE:
        thisRect.top = otherRect.bottom
    elif side == Sides.LEFT_SIDE:
        thisRect.left = otherRect.right
Exemple #4
0
def scaleRect(rect: Rect, n: int) -> Rect:
    copy = rect.copy()
    copy.x *= n
    copy.y *= n
    copy.width *= n
    copy.height *= n
    return copy
Exemple #5
0
 def onDraw(self):
     # transform borders
     surface = pygame.Surface(self.gameObject.transform.size,
                              pygame.SRCALPHA).convert_alpha()
     pygame.draw.rect(surface, (255, 255, 255),
                      Rect(0, 0, *surface.get_size()).toPygameRect(), 1)
     return surface
Exemple #6
0
    def __init__(self):
        super().__init__()

        self._rect = Rect()
        self._offset = Vector2()
        self._order = 0

        from gameengine.managers.InputManager import InputManager
        InputManager().add(self)
Exemple #7
0
 def zoomAt(self, x, y, zoom):
     delta = Vector2(x, y) - self.transform.worldRect.topLeft
     print("delta", delta)
     oldZoom = self.zoom
     self.zoom = zoom
     newRect = Rect(
         *(self.transform.worldRect.topLeft + delta *
           (self.zoom - oldZoom) / self.zoom), *self.transform.size)
     self.transform.worldRect = newRect
Exemple #8
0
 def getCoinAbove(self):
     from gameengine.managers.CollisionManager import CollisionManager
     above: set = CollisionManager().quadtree.intersect(
         bbox=Rect(self.transform.position + (0, 20), 1, 1).bbox())
     if above:
         go = above.pop().gameObject
         if "Coin" in go.tags:
             from game.blocks.QuestionBlock import RotatingCoin
             World.instantiate(RotatingCoin, (go.transform.position))
             World.destroy(go)
Exemple #9
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)
Exemple #10
0
        def updateQuadtreeOnSize(sender, oldSize, newSize):
            # print(self.worldRect, oldPosition)
            from gameengine.util.Rect import Rect
            old = Rect(
                *(self.position -
                  self.gameObject.transform.pivot.ratio.elementwise() *
                  oldSize), *oldSize)

            # print(old)

            try:
                # CollisionManager().quadtree.remove(self, old.tuple())
                CollisionManager().grid.remove(self, old)
                # print("da")
            except:
                # print("FAIL")
                pass

            # CollisionManager().quadtree.insert(self, self.worldRect.tuple())
            CollisionManager().grid.insert(self, self.worldRect)
Exemple #11
0
 def at(self, i, j) -> Rect:
     return Rect(self.center.x + i * self.cellSize.x, self.center.y + j * self.cellSize.y, *self.cellSize)
Exemple #12
0
 def worldRect(self) -> Rect:
     return Rect(
         *(self._position - self.pivot.ratio.elementwise() * self.size),
         *self.size)
Exemple #13
0
    def __init__(self):
        super().__init__()

        self._rect = Rect()
        self._offset = Vector2()
        iTopLeft = int(rect.topLeft.x / self.cellSize)
        jTopLeft = int(rect.topLeft.y / self.cellSize)

        iBottomRight = int(rect.bottomRight.x / self.cellSize)
        jBottomRight = int(rect.bottomRight.y / self.cellSize)

        for i in range(iTopLeft, iBottomRight + 1):
            for j in range(jTopLeft, jBottomRight + 1):
                for otherCollider in self.grid[i][j]:
                    if otherCollider != collider and otherCollider not in colliding:
                        colliding.append(otherCollider)

        return colliding


class Element:
    pass


grid = GridSpacePartition(64)
gridM = GridSpacePartitionModified(1000, 1000, 64)

e = Element()
r = Rect(100, 100, 56, 600)

grid.insert(e, r)
gridM.add(e, r)

grid.remove(e, r)
gridM.remove(e, r)
Exemple #15
0
 def worldRect(self) -> Rect:
     return Rect(
         *(self._position -
           self.gameObject.transform.pivot.ratio.elementwise() * self.size),
         *self.size)
Exemple #16
0
 def localRect(self):
     return Rect(*self._localPosition, *self.size)