Replace prey on hit.
This commit is contained in:
parent
5d33259119
commit
31e85ee33b
@ -14,8 +14,21 @@ class Prey(GameObject):
|
||||
self.__bounding_box.center = [random.randint(0, max_val)
|
||||
for max_val in self.__window_size]
|
||||
|
||||
|
||||
|
||||
def __collides_with_other(self, game_objs: list[GameObject]) -> bool:
|
||||
for obj in game_objs:
|
||||
if not isinstance(obj, Prey) and self.get_bounding_boxes()[0].collidelist(obj.get_bounding_boxes()) > -1:
|
||||
return True
|
||||
|
||||
def draw(self, surface: pygame.surface.Surface) -> None:
|
||||
pygame.draw.rect(surface, color=self.__color, rect=self.__bounding_box)
|
||||
|
||||
|
||||
def update(self, user_input: int, game_objs: list[GameObject]):
|
||||
while self.__collides_with_other(game_objs):
|
||||
self.__place_randomly()
|
||||
|
||||
|
||||
def get_bounding_boxes(self) -> list[pygame.rect.Rect]:
|
||||
return [self.__bounding_box]
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user