Add slice effect

This commit is contained in:
Chris Proctor
2026-03-19 13:08:24 -04:00
parent cfb06479ae
commit d504fd6a05
2 changed files with 47 additions and 1 deletions

View File

@@ -1,6 +1,33 @@
from random import randint
from .fruit import FruitPiece
class SliceEffectPiece:
character = "-"
color = "yellow_on_indigo"
z = 2
def __init__(self, position):
self.position = position
class SliceEffect:
display = False
def __init__(self, game):
self.pieces = []
self.turns_remaining = 8
width, height = game.board_size
for y in range(height - 3, height):
for x in range(width):
piece = SliceEffectPiece((x, y))
self.pieces.append(piece)
game.add_agent(piece)
def play_turn(self, game):
self.turns_remaining -= 1
if self.turns_remaining <= 0:
for piece in self.pieces:
game.remove_agent(piece)
game.remove_agent(self)
class CatcherPiece:
character = "-"
color = "white_on_indigo"
@@ -35,6 +62,10 @@ class Catcher:
self.position = (new_x, y)
self.update_piece_positions()
self.check_fruit_collisions(game)
if str(keystroke) == 'z' and game.state['slices'] > 0:
game.state['slices'] -= 1
game.add_agent(SliceEffect(game))
self._slice_fruits(game)
def check_fruit_collisions(self, game):
agents_by_pos = game.get_agents_by_position()
@@ -45,6 +76,21 @@ class Catcher:
seen.add(id(agent.parent))
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
def create_pieces(self, game):
x, y = self.position
self.pieces = []