Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@
- Head of Programming Support: Vince
- Head of Inconvenience: Charlie
- Head of Marketing: Raf
- Head of Legal Support: Ilia
- 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
37 changes: 37 additions & 0 deletions src/inventory.py
Original file line number Diff line number Diff line change
@@ -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
13 changes: 10 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pygame, numpy
import math
import sys

from camera import CameraGroup
from player import Player
Expand All @@ -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()
Expand All @@ -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:
Expand All @@ -36,4 +40,7 @@ def main():


if __name__ == "__main__":
main()
if "debug" in sys.argv:
main(speed=50)
else:
main()
9 changes: 7 additions & 2 deletions src/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import numpy as np
import pygame

import inventory

SQUARE_ROOT_OF_TWO = math.sqrt(2)


Expand All @@ -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(
Expand All @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions src/terrain.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pygame

import inventory

class Sprite(pygame.sprite.Sprite):
"""
Expand Down Expand Up @@ -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()
2 changes: 2 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
SadBarrier,
HappyBarrier,
Collectible,
SecondBox,
)

def get_building_parameters(config_path):
Expand Down Expand Up @@ -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


Expand Down