diff --git a/README.md b/README.md index 0621a6f..7f7c1fb 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,15 @@ - Head of Programming Support: Vince - Head of Inconvenience: Charlie - Head of Marketing: Raf -- Head of Legal Support: Ilia \ No newline at end of file +- Head of Legal Support: Ilia + +## Running + + $ cd src + $ python main.py + +## Running in debug mode + +This will run with a faster player. + + $ python main.py debug diff --git a/src/inventory.py b/src/inventory.py new file mode 100644 index 0000000..4a8727e --- /dev/null +++ b/src/inventory.py @@ -0,0 +1,37 @@ +import collections + +class Bag: + def __init__(self): + self.contents = [] + + def __repr__(self): + representation = "Bag:\n" + representation += "====\n" + for item, count in collections.Counter([item.__repr__() for item in self.contents]).items(): + representation += f"\t{item}: {count}" + representation += "\n" + return representation + + def put(self, item): + self.contents.append(item) + +class Item: + pass + +class FiniteItem(Item): + pass + +class InfiniteItem(Item): + pass + +class Box(FiniteItem): + def __init__(self): + self.descriptor = "Box" + def __repr__(self): + return self.descriptor + +class SecondBox(FiniteItem): + def __init__(self): + self.descriptor = "Second Box" + def __repr__(self): + return self.descriptor diff --git a/src/main.py b/src/main.py index 8125e94..69988a9 100644 --- a/src/main.py +++ b/src/main.py @@ -1,5 +1,6 @@ import pygame, numpy import math +import sys from camera import CameraGroup from player import Player @@ -10,9 +11,10 @@ BACKGROUND = (50, 0, 0) PLAYER_START_X = 1000 PLAYER_START_Y = 1000 +DEFAULT_SPEED = 8 -def main(): +def main(speed=DEFAULT_SPEED): pygame.init() screen = pygame.display.set_mode((WIDTH, HEIGHT)) clock = pygame.time.Clock() @@ -21,7 +23,9 @@ def main(): boxes, collectibles, environment = create_custom_walls(camera_group=camera_group) player = Player( - startx=PLAYER_START_X, starty=PLAYER_START_Y, group=camera_group, boxes=boxes, collectibles=collectibles, environment=environment + startx=PLAYER_START_X, starty=PLAYER_START_Y, group=camera_group, + boxes=boxes, collectibles=collectibles, environment=environment, + speed=speed, ) while True: @@ -36,4 +40,7 @@ def main(): if __name__ == "__main__": - main() + if "debug" in sys.argv: + main(speed=50) + else: + main() diff --git a/src/player.py b/src/player.py index a0fb046..e14c662 100644 --- a/src/player.py +++ b/src/player.py @@ -2,6 +2,8 @@ import numpy as np import pygame +import inventory + SQUARE_ROOT_OF_TWO = math.sqrt(2) @@ -10,7 +12,8 @@ class Player(pygame.sprite.Sprite): The Player class where the player is defined. The player is a sprite that can move around the map and interact with the environment. """ - def __init__(self, startx, starty, group, boxes, collectibles, environment): + def __init__(self, startx, starty, group, boxes, collectibles, environment, + speed=8): super().__init__(group) self.stand_image = pygame.image.load( @@ -34,9 +37,11 @@ def __init__(self, startx, starty, group, boxes, collectibles, environment): self.animation_index = 0 self.facing_left = False - self.speed = 8 + self.speed = speed self.prev_key = pygame.key.get_pressed() + self.bag = inventory.Bag() + def walk_animation(self): """ Animates the player walking. diff --git a/src/terrain.py b/src/terrain.py index 00f64c6..7e6e46f 100644 --- a/src/terrain.py +++ b/src/terrain.py @@ -1,5 +1,6 @@ import pygame +import inventory class Sprite(pygame.sprite.Sprite): """ @@ -87,7 +88,14 @@ class Collectible(Sprite): """ def __init__(self, startx, starty, group): super().__init__("Graphics/terrain/boxAlt.png", startx, starty, group) + self.item = inventory.Box() def event(self, player): + player.bag.put(self.item) self.kill() + +class SecondBox(Collectible): + def __init__(self, startx, starty, group): + super().__init__(startx, starty, group) + self.item = inventory.SecondBox() diff --git a/src/utils.py b/src/utils.py index 254b30e..c2ac480 100644 --- a/src/utils.py +++ b/src/utils.py @@ -10,6 +10,7 @@ SadBarrier, HappyBarrier, Collectible, + SecondBox, ) def get_building_parameters(config_path): @@ -87,6 +88,7 @@ def place_collectibles(collectibles, camera_group): collectibles.add(Collectible(300, 1100, camera_group)) collectibles.add(Collectible(400, 1100, camera_group)) collectibles.add(Collectible(500, 1100, camera_group)) + collectibles.add(SecondBox(500, 600, camera_group)) return collectibles