generated from mwc/project_game
Allow knife to slice into fruit
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from random import randint
|
||||
from .fruit import FruitPiece
|
||||
|
||||
class CatcherPiece:
|
||||
character = "-"
|
||||
@@ -28,10 +29,21 @@ class Catcher:
|
||||
new_x = max(0, x - 3)
|
||||
self.position = (new_x, y)
|
||||
self.update_piece_positions()
|
||||
self.check_fruit_collisions(game)
|
||||
if keystroke.name == "KEY_RIGHT":
|
||||
new_x = min(width - self.width, x + 3)
|
||||
self.position = (new_x, y)
|
||||
self.update_piece_positions()
|
||||
self.check_fruit_collisions(game)
|
||||
|
||||
def check_fruit_collisions(self, game):
|
||||
agents_by_pos = game.get_agents_by_position()
|
||||
seen = set()
|
||||
for piece in self.pieces:
|
||||
for agent in agents_by_pos.get(piece.position, []):
|
||||
if isinstance(agent, FruitPiece) and agent.parent.alive and id(agent.parent) not in seen:
|
||||
seen.add(id(agent.parent))
|
||||
agent.parent.check_catcher_collision(game)
|
||||
|
||||
def create_pieces(self, game):
|
||||
x, y = self.position
|
||||
|
||||
Reference in New Issue
Block a user