diff --git a/__pycache__/catcher.cpython-311.pyc b/__pycache__/catcher.cpython-311.pyc index 978f128..5fbf164 100644 Binary files a/__pycache__/catcher.cpython-311.pyc and b/__pycache__/catcher.cpython-311.pyc differ diff --git a/__pycache__/fruit.cpython-311.pyc b/__pycache__/fruit.cpython-311.pyc index f71363c..ae2f4e7 100644 Binary files a/__pycache__/fruit.cpython-311.pyc and b/__pycache__/fruit.cpython-311.pyc differ diff --git a/__pycache__/manager.cpython-311.pyc b/__pycache__/manager.cpython-311.pyc index 783fdfe..1018a12 100644 Binary files a/__pycache__/manager.cpython-311.pyc and b/__pycache__/manager.cpython-311.pyc differ diff --git a/catcher.py b/catcher.py index a93dedd..141985f 100644 --- a/catcher.py +++ b/catcher.py @@ -8,7 +8,7 @@ class CatcherPiece: def play_turn(self, game): fruit = game.get_agent_by_name("fruit") - if new_position == fruit.position: + if self.position == fruit.position: game.state['Score'] += 1 class Catcher: @@ -36,6 +36,14 @@ class Catcher: if x + self.width < width: self.position = (x+1, y) self.update_piece_positions() + self.checkforfruitcollision(game) + + def checkforfruitcollision(self, game): + for piece in self.pieces: + if piece.collision(game): + game.remove_agent(fruit) + game.state['Score'] += 1 + def create_pieces(self, game): x, y = self.position diff --git a/fruit.py b/fruit.py index 2c76f43..a7e84f0 100644 --- a/fruit.py +++ b/fruit.py @@ -23,8 +23,8 @@ class Fruit: def __init__(self, position, game, shape_offsets): self.position = position - self.blocks = {} - for shape in shape_offsets: + self.pieces = {} + for offset in shape_offsets: self.create_shape(game, offset) def play_turn(self, game): @@ -32,22 +32,17 @@ class Fruit: x, y = self.position if y == 29: game.remove_agent(self) - game.state['Score'] -= 3 + game.end() else: 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 def create_shape(self, game, offset): x, y = self.position ox, oy = offset - fruit = Fruit((x + ox, y + oy)) - self.fruits[offset] = fruit - game.add_agent(fruit) + piece = FruitPiece((x + ox, y + oy)) + self.pieces[offset] = piece + game.add_agent(piece) def update_piece_positions(self): if game.turn_number % 3 == 0: @@ -55,12 +50,7 @@ class Fruit: x, y = self.position if y == 29: game.remove_agent(self) - game.state['Score'] -= 3 + game.end() else: 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 \ No newline at end of file + new_position = (x, y + 1) \ No newline at end of file diff --git a/game.py b/game.py index 1de0f9c..4e7af94 100644 --- a/game.py +++ b/game.py @@ -2,6 +2,7 @@ from random import randint from retro.game import Game from catcher import Catcher from manager import FruitManager +import json WIDTH = 27 HEIGHT = 30 @@ -13,4 +14,4 @@ agents = [ state = {'Score': 0} game = Game(agents, state, board_size=(WIDTH, HEIGHT), framerate=24, color="white_on_indigo") -game.play() \ No newline at end of file +game.play() \ No newline at end of file diff --git a/manager.py b/manager.py index a69fe37..9fdefbf 100644 --- a/manager.py +++ b/manager.py @@ -1,5 +1,5 @@ from fruit import Fruit, SHAPE_DEFINITIONS -from random import choice +from random import choice, randint from retro.errors import AgentNotFoundByName class FruitManager: @@ -13,5 +13,6 @@ class FruitManager: self.create_piece(game) def create_piece(self, game): - fruit = Fruit((14, 1), game, choice(SHAPE_DEFINITIONS)) + x = randint(0, 26) + fruit = Fruit((x, 1), game, choice(SHAPE_DEFINITIONS)) game.add_agent(fruit) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index f7df288..0cc4733 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,9 @@ [project] -name = "project-game" +name = "fruit-catcher" version = "0.1.0" description = "" authors = [ - {name = "Chris Proctor",email = "chris@chrisproctor.net"} + {name = "Kayden Dang, Connor ",email = "chris@chrisproctor.net"} ] license = {text = "MIT"} readme = "README.md" @@ -12,6 +12,14 @@ dependencies = [ "retro-games (>=1.1.1,<2.0.0)" ] +[project.scripts] +play = "game:play" + +[tool.retro] +authors = "Kayden, Connor" +description = "Use your buttons to help the catcher catch the falling fruits. Don't drop too many fruits!" +instructions = "SCore as many points as possible before losing by using the two designated buttons to move left and right." +result_file = "result.json" [build-system] requires = ["poetry-core>=2.0.0,<3.0.0"]