@chris My fruit offset does not work

This commit is contained in:
kdang
2026-01-09 09:49:15 -05:00
parent d6adfef5a1
commit 267fffa9b0
9 changed files with 69 additions and 54 deletions

View File

@@ -1,71 +1,66 @@
from random import randint
SHAPE_DEFINITIONS = [
[(0,0)],
[(0, 0), (1, 0), (0, 1), (1, 1)],
]
class FruitPiece:
character = "@"
color = "green_on_indigo"
display = True
def __init__(self, position):
self.position = position
class Fruit:
width = 2
height = 2
height = 1
display = False
pieces = []
name = "fruit"
character = "@"
color = "green_on_indigo"
def __init__(self, position):
def __init__(self, position, game, shape_offsets):
self.position = position
self.blocks = {}
for shape in shape_offsets:
self.create_shape(game, offset)
def play_turn(self, game):
if not self.pieces:
self.create_pieces(game)
if game.turn_number % 2 == 0:
if game.turn_number % 3 == 0:
x, y = self.position
if y == 24:
if y == 29:
game.remove_agent(self)
game.state['Score'] -= 3
else:
catcher = game.get_agent_by_name("Player")
catcher = game.get_agent_by_name("catcher")
new_position = (x, y + 1)
if new_position == catcher.position:
catcher.explode()
game.end()
game.remove_agent(self)
game.state['Score'] += 1
else:
self.position = new_position
def create_pieces(self, game):
def create_shape(self, game, offset):
x, y = self.position
self.pieces = []
for i in range(self.width):
piece = FruitPiece((x + i, y))
self.pieces.append(piece)
game.add_agent(piece)
for i in range(self.height):
piece = FruitPiece((x, y + i))
self.pieces.append(piece)
game.add_agent(piece)
ox, oy = offset
fruit = Fruit((x + ox, y + oy))
self.fruits[offset] = fruit
game.add_agent(fruit)
def update_piece_positions(self):
if game.turn_number % 2 == 0:
if game.turn_number % 3 == 0:
self.set_color()
x, y = self.position
if y == HEIGHT - 1:
if y == 29:
game.remove_agent(self)
game.state['Score'] -= 3
else:
ship = game.get_agent_by_name("Player")
new_position = (x, y - 1)
if new_position == ship.position:
ship.explode()
game.end()
catcher = game.get_agent_by_name("catcher")
new_position = (x, y + 1)
if new_position == catcher.position:
game.remove_agent(self)
game.state['Score'] += 1
else:
self.position = new_position
class FruitSpawner:
display = False
def play_turn(self, game):
if self.should_spawn_fruit(game.turn_number):
asteroid = Fruit((randint(0, WIDTH - 1), 0))
game.add_agent(fruit)
def should_spawn_fruit(self, turn_number):
return randint(0, 1000) < turn_number
self.position = new_position