42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
|
import pygame
|
||
|
import sys
|
||
|
|
||
|
from sprite.Sprite import Sprite
|
||
|
from sprite.Spritesheet import Spritesheet
|
||
|
|
||
|
sys.path.append('./sprite')
|
||
|
|
||
|
|
||
|
class StaticSprite(Sprite):
|
||
|
def __init__(self, spritesheet: Spritesheet):
|
||
|
super().__init__(spritesheet)
|
||
|
|
||
|
self.position = (0, 0)
|
||
|
|
||
|
def collides_with(self, collider: 'StaticSprite'):
|
||
|
if not self.is_collider or not collider.is_collider:
|
||
|
return False
|
||
|
|
||
|
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()
|
||
|
|
||
|
if self_position[0] + self_dimensions[0] < other_position[0]:
|
||
|
return False
|
||
|
|
||
|
if self_position[0] > other_position[0] + other_dimensions[0]:
|
||
|
return False
|
||
|
|
||
|
if self_position[1] + self_dimensions[1] < other_position[1]:
|
||
|
return False
|
||
|
|
||
|
if self_position[1] > other_position[1] + other_dimensions[1]:
|
||
|
return False
|
||
|
|
||
|
return True
|