Kill snake on collision with itself.
This commit is contained in:
parent
0e72331f45
commit
d19c45abbc
@ -20,9 +20,13 @@ class Snake(GameObject):
|
||||
return isinstance(obj, Wall) and self.get_bounding_boxes()[0].collidelist(obj.get_bounding_boxes()) > -1
|
||||
|
||||
|
||||
def __collides_with_self(self, obj: GameObject):
|
||||
return isinstance(obj, Snake) and self.get_bounding_boxes()[0].collidelist(obj.get_bounding_boxes()[1:]) > -1
|
||||
|
||||
|
||||
def __update_on_collision(self, game_objs: list[GameObject]) -> None:
|
||||
for obj in game_objs:
|
||||
if self.__collides_with_wall(obj):
|
||||
if self.__collides_with_wall(obj) or self.__collides_with_self(obj):
|
||||
self.__is_dead = True
|
||||
|
||||
|
||||
@ -34,6 +38,7 @@ class Snake(GameObject):
|
||||
if not self.__is_dead:
|
||||
self.__update_on_collision(game_objs)
|
||||
|
||||
if not self.__is_dead:
|
||||
self.__state_machine.update(user_input)
|
||||
new_head = self.__state_machine.get_state().get_next_head(self.__segments[0])
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user