Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
939bcaa
motherload with inifinite world generation to the left
willythor Mar 7, 2016
fb0a3cf
finite map to left and right
willythor Mar 7, 2016
8e80b00
collision detection works
willythor Mar 7, 2016
4ceceb8
Add different frequency for blocks
SungwooPark Mar 7, 2016
0ba296d
Add timer
SungwooPark Mar 7, 2016
4bd1d1c
Add fuel station
SungwooPark Mar 7, 2016
3f24603
Separate the game model to model.py
SungwooPark Mar 7, 2016
d9b132b
Change the name of model.py to game_model.py
SungwooPark Mar 7, 2016
9c3674d
"minor changes to key class"
willythor Mar 8, 2016
7d710af
"infinite downward works, but memory alocation may suck"
willythor Mar 8, 2016
b947bf2
"bunch of stuff works, but terribly disorganized"
willythor Mar 8, 2016
f684f03
"a little more shiz works"
willythor Mar 8, 2016
ded3a12
Add functionality for fuel station
SungwooPark Mar 8, 2016
82759dd
random shiz
willythor Mar 8, 2016
4bd0ca0
"yo"
willythor Mar 8, 2016
708732d
Add mineral counter
SungwooPark Mar 8, 2016
4caeadf
sprite bricks working
willythor Mar 8, 2016
c7acbdd
Merge branch 'master' of https://github.com/david-hershey/Interactive…
willythor Mar 8, 2016
f1a2891
yo
willythor Mar 8, 2016
a86fb97
fixed location start
willythor Mar 8, 2016
c844298
Add shop
SungwooPark Mar 8, 2016
f935a06
Merge branch 'master' of github.com:david-hershey/InteractiveProgramming
SungwooPark Mar 8, 2016
fbc0aa7
Add money counter
SungwooPark Mar 8, 2016
f8ab826
sprites
willythor Mar 8, 2016
9ee627f
fixed merge
willythor Mar 8, 2016
d9cfa21
Update movement behavior for shop
SungwooPark Mar 8, 2016
165ef2d
fixed bug
willythor Mar 8, 2016
ec183f7
sprites working like a mofo
willythor Mar 8, 2016
efe25d4
Add functionality to sell minerals
SungwooPark Mar 8, 2016
01e2781
Add fuel station and shop image
SungwooPark Mar 8, 2016
c4bbe64
fixed infinite terrain
willythor Mar 8, 2016
636562a
Merge branch 'master' of https://github.com/david-hershey/Interactive…
willythor Mar 8, 2016
6a92b4e
Add image to the repo
SungwooPark Mar 8, 2016
fb6242b
Merge branch 'master' of https://github.com/david-hershey/Interactive…
willythor Mar 8, 2016
6e383bc
Add ruby image
SungwooPark Mar 8, 2016
29d2d83
fixed infinite terrain
willythor Mar 8, 2016
f46eb35
fixed terrain gen
willythor Mar 8, 2016
f1dfeeb
fixed infinite terrain
willythor Mar 8, 2016
bf56ce1
Fix merge conflict
SungwooPark Mar 8, 2016
e1e45cb
Add shop functionality
SungwooPark Mar 8, 2016
7e5cd18
fixed gravity
willythor Mar 8, 2016
088aa38
fixed gravity
willythor Mar 8, 2016
05a25be
make ruby image transparent
SungwooPark Mar 8, 2016
7ae455f
Merge branch 'master' of github.com:david-hershey/InteractiveProgramming
SungwooPark Mar 8, 2016
9030b29
Fix merge conflict
SungwooPark Mar 8, 2016
9294edc
Add transparent ruby image
SungwooPark Mar 8, 2016
2592b78
Add all minerals
SungwooPark Mar 9, 2016
2eb3dc9
improved collision detection
willythor Mar 9, 2016
b65b4ae
Changed typo
SungwooPark Mar 9, 2016
e09000b
fixed merged conflicts
willythor Mar 9, 2016
67ef9d1
Merge branch 'master' of https://github.com/david-hershey/Interactive…
willythor Mar 9, 2016
d644bd5
fixed full station
willythor Mar 9, 2016
8252b35
Fix a bug in which the enlarged world is blue
SungwooPark Mar 9, 2016
7288481
Merge branch 'master' of github.com:david-hershey/InteractiveProgramming
SungwooPark Mar 9, 2016
ea173e1
Fix a bug that makes empty holes to be not generated
SungwooPark Mar 9, 2016
c45a3ae
idk what this is
willythor Mar 9, 2016
62b5e48
Merge branch 'master' of https://github.com/david-hershey/Interactive…
willythor Mar 9, 2016
7c4b9bd
Fix empty spot glitch
SungwooPark Mar 9, 2016
f9b4de9
Merge branch 'master' of https://github.com/david-hershey/Interactive…
willythor Mar 9, 2016
165ff63
made vehicle smaller
willythor Mar 10, 2016
5b3ca2a
fixed gravity bug
willythor Mar 10, 2016
adc9e08
digging a little better
willythor Mar 10, 2016
c4f3a1d
Add workshop
SungwooPark Mar 10, 2016
901a59b
Merge branch 'master' of github.com:david-hershey/InteractiveProgramming
SungwooPark Mar 10, 2016
93c0e50
saving work
willythor Mar 10, 2016
a0f8251
Merge branch 'master' of https://github.com/david-hershey/Interactive…
willythor Mar 10, 2016
0654ce5
Add workshop image
SungwooPark Mar 10, 2016
ae6d92a
Merge branch 'master' of https://github.com/david-hershey/Interactive…
willythor Mar 10, 2016
d9602d4
Add functionality for workshop
SungwooPark Mar 10, 2016
99e55ea
broke gravity again
willythor Mar 10, 2016
d3f0366
Merge branch 'master' of https://github.com/david-hershey/Interactive…
willythor Mar 10, 2016
ab8f91b
Fixed workshop positioning
SungwooPark Mar 10, 2016
0ca2ad7
better gravity
willythor Mar 10, 2016
934a822
Merge branch 'master' of github.com:david-hershey/InteractiveProgramming
SungwooPark Mar 10, 2016
357757d
Add score functionality
SungwooPark Mar 10, 2016
805e6b0
idk
willythor Mar 10, 2016
b75dd82
Merge branch 'master' of https://github.com/david-hershey/Interactive…
willythor Mar 10, 2016
48feea9
cant drill up
willythor Mar 10, 2016
41cb1a3
Add game-over
SungwooPark Mar 10, 2016
a462359
added different collision detect
willythor Mar 10, 2016
46e9f2f
Merge branch 'master' of https://github.com/david-hershey/Interactive…
willythor Mar 10, 2016
d9dd89c
Fix collision stuff
SungwooPark Mar 10, 2016
77fb7c0
Fix merge conflict
SungwooPark Mar 10, 2016
23f3ade
motherload2
willythor Mar 10, 2016
4b46b72
Merge branch 'master' of https://github.com/david-hershey/Interactive…
willythor Mar 10, 2016
ad072cc
Add collision detection for up movement
SungwooPark Mar 10, 2016
d5b8fac
Implement drill left and right
SungwooPark Mar 10, 2016
72ed9ea
cabbage
SungwooPark Mar 10, 2016
1c16dd0
Renamed the file
SungwooPark Mar 10, 2016
11c992f
renamed a class
willythor Mar 10, 2016
5a1d493
changed some class names
willythor Mar 10, 2016
6053435
Add installation instruction to readme
SungwooPark Mar 10, 2016
55dd7b1
Merge branch 'master' of github.com:david-hershey/InteractiveProgramming
SungwooPark Mar 10, 2016
fdf846b
Update README
SungwooPark Mar 10, 2016
7b50cb9
Updated the code to run in README
SungwooPark Mar 10, 2016
31eb139
Add documentation for game_model
SungwooPark Mar 10, 2016
9fe7c45
added comments
willythor Mar 10, 2016
5d86de6
Merge branch 'master' of https://github.com/david-hershey/Interactive…
willythor Mar 10, 2016
35da2a5
Add writeup file
SungwooPark Mar 10, 2016
f8d502a
Changed the top title of README
SungwooPark Mar 18, 2016
077ecd8
new classes
willythor Apr 19, 2016
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
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
# InteractiveProgramming
This is the base repo for the interactive programming project for Software Design, Spring 2016 at Olin College.
# Motherload: Cabbage Rendition
@authors: Sung Park, Willem Thorbecke

*Motherload: Cabbage Rendition* is a recreation of Motherload using pygame. This project was created as a part of Olin College Software Design course for Spring 2016.

##Install

To run *Motherload: Cabbage Rendition*, you need to install pygame.

Run below code in your terminal to intsall pygame.

```
$ sudo apt-get install python-pygame
```

Download the repository to your local environment through cloning this repository or downloading as a zip.

##Run

Run motherload.py to start the program.

```
$ python motherload.py
```

You are all set. Enjoy the game.
Binary file added amazonite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added emerald.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fuel_station.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
280 changes: 280 additions & 0 deletions game_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
import random
from random import choice
import pygame
from pygame.locals import QUIT, KEYDOWN, MOUSEMOTION
import time
"""
Class containing the game model and all its components
"""


class Brick(pygame.sprite.Sprite):
"""
Creates a brick class

Key attributes: color, type
"Brown" color represents soil and "Black" color represents an empty spot
"""


# Constructor. Pass in the color of the brick,
# and its x and y position
def __init__(self, left, top, width, height, first):
# Call the parent class (Sprite) constructor
pygame.sprite.Sprite.__init__(self)

# Create an image of the block, and fill it with a color.
# This could also be an image loaded from the disk.
self.image = pygame.Surface([width, height])


# Fetch the rectangle object that has the dimensions of the image
# Update the position of this object by setting the values of rect.x and rect.y
self.rect = self.image.get_rect()

#This if statement is executed during initalized of the world at the start of the game.
if first:
self.rect.x = left*width - width*9 #renders 9 extra columns of blocks off screen to the left
self.rect.y = top*height #top*height + height*2 - 1 #starts the world with a 2 block high sky
self.width = width
self.height = height
self.top = top*height #+ height*2 -1
self.left = left*width - width*9

if top == 0 or top == 1:
self.color = "black"
return
random_seed = random.random()
if random_seed < 0.1:
self.color = "black"
self.brick_type = "empty"
elif random_seed <0.9:
self.color = "brown"
self.brick_type = "soil"
else:
self.color = "brown"
self.brick_type = choice(["ruby", "emerald", "amazonite", "sapphire", "watsonite"])
if self.brick_type == "ruby":
self.image = pygame.image.load('ruby.png').convert()
self.image.set_colorkey((255,255,255))
elif self.brick_type == "emerald":
self.image = pygame.image.load('emerald.png').convert()
self.image.set_colorkey((0,0,0))
elif self.brick_type == "amazonite":
self.image = pygame.image.load('amazonite.png').convert()
self.image.set_colorkey((0,0,0))
elif self.brick_type == "sapphire":
self.image = pygame.image.load('sapphire.png').convert()
self.image.set_colorkey((0,0,0))
elif self.brick_type == "watsonite":
self.image = pygame.image.load('watsonite.png').convert()
self.image.set_colorkey((255,255,255))
#This else statement is executed during "terrain generation" phase of the game
else:
self.rect.x = left
self.rect.y = top
self.top = top
self.left = left
self.width = width
self.height = height
random_seed = random.random()
if random_seed < 0.1:
self.color = "black"
self.brick_type = "empty"
elif random_seed <0.9:
self.color = "brown"
self.brick_type = "soil"
else:
self.color = "brown"
self.brick_type = choice(["ruby", "emerald", "amazonite", "sapphire", "watsonite"])
if self.brick_type == "ruby":
self.image = pygame.image.load('ruby.png').convert()
self.image.set_colorkey((255,255,255))
elif self.brick_type == "emerald":
self.image = pygame.image.load('emerald.png').convert()
self.image.set_colorkey((0,0,0))
elif self.brick_type == "amazonite":
self.image = pygame.image.load('amazonite.png').convert()
self.image.set_colorkey((0,0,0))
elif self.brick_type == "sapphire":
self.image = pygame.image.load('sapphire.png').convert()
self.image.set_colorkey((0,0,0))
elif self.brick_type == "watsonite":
self.image = pygame.image.load('watsonite.png').convert()
self.image.set_colorkey((255,255,255))


class FuelStation(pygame.sprite.Sprite):
"""
Fuel station object. It has the fixed position of (400,40)
"""

def __init__(self):
pygame.sprite.Sprite.__init__(self)

self.image = pygame.image.load('fuel_station.gif').convert()

self.left = 400
self.top = 40
self.width = 40
self.height = 40
#self.image.fill((0,255,255))

# Fetch the rectangle object that has the dimensions of the image
# Update the position of this object by setting the values of rect.x and rect.y
self.rect = self.image.get_rect()
self.rect.x = 400
self.rect.y = 40


class Workshop(pygame.sprite.Sprite):
"""
Workshop tile where the vehicle can upgrade its fuel tank
Fixed position at (560, 40)
"""
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('workshop.png')
self.rect = self.image.get_rect()

self.left = 560
self.top = 40
self.width = 40
self.height = 40
self.rect.x = 560
self.rect.y = 40


class Shop(pygame.sprite.Sprite):
"""
Shop tile where the vehicle can sell its minerals.
It has the fixed position at (480,40)
"""

def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('store.jpg').convert()
self.rect = self.image.get_rect()

self.left = 480
self.top = 40
self.width = 40
self.height = 40
self.rect.x = 480
self.rect.y = 40



class Vehicle(pygame.sprite.Sprite):

""" Represents the vehicle"""

def __init__(self, left, top, width, height):
pygame.sprite.Sprite.__init__(self)

self.image = pygame.Surface([width, height])


#Attributes that checks for the available action at the vehicle's current position
self.rect = self.image.get_rect()
self.can_drill_left = False
self.can_drill_right = False
self.can_drill_down = False
self.can_move_up = True
self.can_move_left = True
self.can_move_right = True

self.left = left
self.top = top
self.width = width
self.height = height
self.thruster = False
self.speed = 0

self.gravity = .1
self.thruster_veloc = -.1

self.rect.x = left
self.rect.y = top
self.image.fill((0,220,255))


class BrickModel(object):
""" Stores the game state for our brick breaker game """
def __init__(self):
#self.bricks = [][]
self.enlarger_helper = None
self.can_move_down = True #checks if the blocks free to fall downward
self.world = []
self.MARGIN = 0
self.BRICK_WIDTH = 40
self.BRICK_HEIGHT = 40
self.SCREEN_WIDTH = 640
self.SCREEN_HEIGHT = 480
self.FAR_LEFT = 320
self.FAR_RIGHT = 320
self.FAR_BOTTOM = self.SCREEN_HEIGHT + self.BRICK_HEIGHT*4 #the threshold for adding more blocks is 5 blocks from the bottom of the screen


self.init_height_dist = 32 #number of rows of blocks
self.init_width_dist = 34 #number of columns of blocks

self.sprite_list = pygame.sprite.Group() #a list of sprites to be drawn


#initialize world
for top in range(0,self.init_height_dist):
self.world.append([])
for left in range(0,self.init_width_dist):
brick = Brick(left, top, self.BRICK_WIDTH, self.BRICK_HEIGHT, True)
self.world[top].append(brick)
if not (top ==1 or top ==0):
if brick.brick_type != "empty" and brick.brick_type != "soil":
self.sprite_list.add(brick)
self.temp_world = self.world

self.fuel = 3000
self.max_fuel = 3000

#counter for minerals
self.red_block = 0
self.green_block = 0
self.orange_block = 0
self.blue_block = 0
self.purple_block = 0

self.money = 0

self.score = 0

self.vehicle = Vehicle(40*8,25, 25, 25)

self.fuel_station = FuelStation()
self.sprite_list.add(self.fuel_station)
self.shop = Shop()
self.sprite_list.add(self.shop)
self.workshop = Workshop()
self.sprite_list.add(self.workshop)

def world_enlarger(self, what_side):
"""
Function that enlarges the array that represents the map in our game when the vehicle reaches the bottom of the array
"""

if what_side == "left":
pass

elif what_side == "right":
pass

elif what_side == "down":

for top in range(0,5): # cycles through 5 blocks
self.world.append([]) #creates a row (list) to be filled with bricks
for left in range(0,self.init_width_dist):


brick = Brick(self.world[0][0].left+left*self.BRICK_WIDTH, self.world[-2][0].top + self.BRICK_HEIGHT, self.BRICK_WIDTH, self.BRICK_HEIGHT, False)
self.world[-1].append(brick)
if brick.brick_type != "soil" and brick.brick_type != "empty":
self.sprite_list.add(brick)
Loading