generated from mwc/project_game
Fix bug in fruit slices
This commit is contained in:
@@ -77,19 +77,20 @@ class Catcher:
|
||||
agent.parent.check_catcher_collision(game)
|
||||
|
||||
def _slice_fruits(self, game):
|
||||
width, height = game.board_size
|
||||
agents_by_pos = game.get_agents_by_position()
|
||||
seen = set()
|
||||
for y in range(height - 3, height):
|
||||
for x in range(width):
|
||||
for agent in agents_by_pos.get((x, y), []):
|
||||
if isinstance(agent, FruitPiece) and agent.parent.alive and id(agent.parent) not in seen:
|
||||
seen.add(id(agent.parent))
|
||||
game.state['score'] += 1
|
||||
for p in agent.parent.pieces.values():
|
||||
game.remove_agent(p)
|
||||
game.remove_agent(agent.parent)
|
||||
agent.parent.alive = False
|
||||
_, height = game.board_size
|
||||
slice_rows = set(range(height - 3, height))
|
||||
manager = game.get_agent_by_name("fruit_manager")
|
||||
for fruit in list(manager.active_fruits):
|
||||
if not fruit.alive:
|
||||
continue
|
||||
for piece in fruit.pieces.values():
|
||||
if piece.position[1] in slice_rows:
|
||||
game.state['score'] += 1
|
||||
for p in fruit.pieces.values():
|
||||
game.remove_agent(p)
|
||||
game.remove_agent(fruit)
|
||||
fruit.alive = False
|
||||
break
|
||||
|
||||
def create_pieces(self, game):
|
||||
x, y = self.position
|
||||
|
||||
@@ -4,6 +4,7 @@ from random import choice, randint
|
||||
class FruitManager:
|
||||
|
||||
display = False
|
||||
name = "fruit_manager"
|
||||
|
||||
def __init__(self):
|
||||
self.active_fruits = []
|
||||
|
||||
Reference in New Issue
Block a user