2023-03-27 11:46:03 +02:00
|
|
|
from typing import Optional
|
|
|
|
|
2023-03-25 15:41:32 +01:00
|
|
|
from sprite.Sprite import Sprite
|
|
|
|
from sprite.Spritesheet import Spritesheet
|
|
|
|
|
|
|
|
|
|
|
|
class StaticSprite(Sprite):
|
2023-03-27 11:46:03 +02:00
|
|
|
def __init__(self, spritesheet: Optional[Spritesheet] = None):
|
2023-03-25 15:41:32 +01:00
|
|
|
super().__init__(spritesheet)
|
|
|
|
|
2023-03-25 17:18:43 +01:00
|
|
|
def collides_with(self, collider: 'StaticSprite', tolerance: float = 0.0):
|
2023-03-25 15:41:32 +01:00
|
|
|
self_bounds = self.get_bounding_box()
|
|
|
|
other_bounds = collider.get_bounding_box()
|
|
|
|
|
|
|
|
self_dimensions = self_bounds.get_dimensions()
|
|
|
|
other_dimensions = other_bounds.get_dimensions()
|
|
|
|
|
|
|
|
self_position = self_bounds.get_position()
|
|
|
|
other_position = other_bounds.get_position()
|
|
|
|
|
2023-03-25 17:18:43 +01:00
|
|
|
if self_position[0] + self_dimensions[0] < other_position[0] + tolerance:
|
2023-03-25 15:41:32 +01:00
|
|
|
return False
|
|
|
|
|
2023-03-25 17:18:43 +01:00
|
|
|
if self_position[0] > other_position[0] + other_dimensions[0] - tolerance:
|
2023-03-25 15:41:32 +01:00
|
|
|
return False
|
|
|
|
|
2023-03-25 17:18:43 +01:00
|
|
|
if self_position[1] + self_dimensions[1] < other_position[1] + tolerance:
|
2023-03-25 15:41:32 +01:00
|
|
|
return False
|
|
|
|
|
2023-03-25 17:18:43 +01:00
|
|
|
if self_position[1] > other_position[1] + other_dimensions[1] - tolerance:
|
2023-03-25 15:41:32 +01:00
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|