Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
3f69ebd
Update README.md
charlievweiss Oct 19, 2016
8dcc07c
Testing how git works
charlievweiss Oct 19, 2016
dcfb121
Adding main file for computer game
charlievweiss Oct 21, 2016
8407753
Merge pull request #1 from charlievweiss/charlie
charlievweiss Oct 21, 2016
f009f8b
The screen shows up and closes when you hit x
charlievweiss Oct 25, 2016
01d7b6c
Merge pull request #2 from charlievweiss/charlie
charlievweiss Oct 25, 2016
7abb20f
Added simple sprites for player and train, and simple train collision
charlievweiss Oct 26, 2016
03d31c3
Merge pull request #3 from charlievweiss/charlie
charlievweiss Oct 26, 2016
ba041a8
Added player movement
dfgarciag Oct 26, 2016
182dbe7
Merge pull request #4 from charlievweiss/diego
dfgarciag Oct 26, 2016
4286746
fixed collision
charlievweiss Oct 28, 2016
fbf99f4
Merge pull request #5 from charlievweiss/charlie
charlievweiss Oct 28, 2016
d3e7101
got the level to move!
charlievweiss Oct 28, 2016
7901602
Merge pull request #6 from charlievweiss/charlie
charlievweiss Oct 28, 2016
d79df61
level moves when player reaches certain point, need to change when pl…
charlievweiss Oct 28, 2016
76e4359
Merge pull request #7 from charlievweiss/charlie
charlievweiss Oct 28, 2016
e4abf1e
added level scrolling and continuous key presses
charlievweiss Oct 31, 2016
edbf0ed
Merge pull request #8 from charlievweiss/charlie
charlievweiss Oct 31, 2016
1dd5800
Train moves in relation to ground and player slows down
charlievweiss Oct 31, 2016
9da29a7
Merge pull request #9 from charlievweiss/charlie
charlievweiss Oct 31, 2016
9ea8ac1
added sadness
charlievweiss Oct 31, 2016
8487da5
Merge pull request #10 from charlievweiss/charlie
charlievweiss Oct 31, 2016
8666426
added end screen
charlievweiss Oct 31, 2016
9721213
game no longer closes on collision
charlievweiss Oct 31, 2016
f6919c8
Merge pull request #11 from charlievweiss/charlie
charlievweiss Oct 31, 2016
cdcbeef
Added some type of jumping
dfgarciag Nov 2, 2016
7487521
Merge pull request #12 from charlievweiss/diego
charlievweiss Nov 2, 2016
b274cbe
made jumping get slower over time
charlievweiss Nov 2, 2016
d125709
Merge pull request #13 from charlievweiss/charlie
charlievweiss Nov 2, 2016
49c026b
Added falling off ground and losing
charlievweiss Nov 2, 2016
4565a10
Merge pull request #14 from charlievweiss/charlie
charlievweiss Nov 2, 2016
a11fca5
This version of the cube jumps correctly, but does not fall when on g…
dfgarciag Nov 3, 2016
01cc006
Merge pull request #15 from charlievweiss/diego
dfgarciag Nov 3, 2016
f04b19f
Update README.md
dfgarciag Nov 3, 2016
c93b179
Added some more comments
dfgarciag Nov 3, 2016
628c9f6
Merge pull request #16 from charlievweiss/diego
dfgarciag Nov 3, 2016
3ccfed3
made the ground longer
charlievweiss Nov 10, 2016
c633d3f
playfile now both falls and jumps
charlievweiss Mar 9, 2017
b152d35
fixed accidental change
charlievweiss Mar 9, 2017
4663297
playfile can actually only jump once, fixing now
charlievweiss Mar 9, 2017
f65f328
easy fix
charlievweiss Mar 9, 2017
bb6c744
Update README.md
charlievweiss Mar 18, 2017
90735b4
Updated README
charlievweiss Mar 23, 2017
e1609af
Update README.md
charlievweiss Mar 23, 2017
b265fcc
testing code quotes
charlievweiss Mar 23, 2017
c24c839
testing code quote
charlievweiss Mar 23, 2017
9a4b334
testing code quotes
charlievweiss Mar 23, 2017
7b8a264
testing code quotes
charlievweiss Mar 23, 2017
4142ae7
testing code quotes
charlievweiss Mar 23, 2017
8ba4361
update README
charlievweiss Mar 23, 2017
5dbfc23
finished How Does It Work
charlievweiss Mar 23, 2017
a159e04
updated how you play
charlievweiss Mar 23, 2017
4f971b0
Updated everything but the license
charlievweiss Mar 23, 2017
e3ba1b0
added platform collisions, need fix from below
charlievweiss Mar 23, 2017
23db33b
platform collisions ready
charlievweiss Mar 23, 2017
ef7ae81
experimenting with images
charlievweiss Mar 24, 2017
add2b75
fixed sideways collisions
charlievweiss Mar 24, 2017
9eb4d3e
working on level design
charlievweiss Mar 24, 2017
f57aa1d
added some high quality graphics
charlievweiss Mar 27, 2017
31b3070
removed useless file
charlievweiss Mar 27, 2017
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
140 changes: 136 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,138 @@
# InteractiveProgramming
# "Pain Train" the Video Game
### by Charlie Weiss and Diego Garcia

This is the base repo for the interactive programming project for Software Design, Fall 2016 at Olin College.
## What is this?
This is a video game created using Python's pygame library and an MVP (model-viewer-player) framework. It is a platform game with a player, a chaser, and some obstacles. The player loses by either being overtaken by the chaser, or by falling to their death.

This file is not a good project README.
Replace the contents of this file before you submit your project.
## How does it work?
The code is split into three collections of classes: The Model classes, the View classes, and the Controller classes. The functions in these classes are called by the main function (found at the bottom of the file), which runs the game with a while loop. Here's some more detail about those sections:

### Model Classes
These contain the definition of the models of each type of object in the game, and their interactions with other objects or events. Each class defines things such as an object's postion, height, width, and distance traveled per loop. Here's an example of the chaser model class, named PainTrain:

```
class PainTrain(object):
def __init__(self,x=0,y=0,width=200,height=200,constdx=.05,dx=0,shiftdx=-1):
# places train centered above coordinate given
self.x = x
self.y = y-height
self.width = width
self.height = height
self.constdx = constdx
self.dx = dx
self.shiftdx = shiftdx

def step(self):
self.x += self.constdx
```

The classes you will find here are
- Player
- PainTrain
- Ground
- Platform

### Viewer Classes
These classes project the information contained in the model classes onto your screen. Each contains an initial function to define the class, and a draw function that says what the object should look like. For consistency's sake, here's the example of the PainTrain's Viewer class:

```
class PainTrainView(object):
def __init__(self, model):
self.model = model

def draw(self, surface):
model = self.model
# this takes (x,y,width,height)
pygame.draw.rect(surface,BLACK,(model.x,model.y,model.width,model.height))
```

The classes you will find here are
- PlayerView
- PainTrainView
- GroundView
- ObstacleView

### Controller Classes
This is actually one class called the Controller class. It has an initial function to define it, and a handle_event function. This class interacts with the main function, which passes it an event. The handle_event function then determines which event it is (i.e., which key has been pressed), and says what to do in that case. Here's the class:

```
class Controller(object):
def __init__(self,models):
self.models = models
self.player = models[0] # make sure this aligns with controlled_models in main

def handle_event(self):
# time passed isn't actually time based... based on while loop efficiency
player = self.player
models = self.models
keys = pygame.key.get_pressed() # checking pressed keys
for model in models:
if keys[pygame.K_LEFT]:
if player.go_back():
model.x -= model.shiftdx
else:
model.x -= model.dx
if keys[pygame.K_RIGHT]:
if player.shift_world():
model.x += model.shiftdx
else:
model.x += model.dx

if keys[pygame.K_UP] and player.dy == 0:
player.dy = player.jumpdy
```

The class you will find here is
- Controller

### Main Function
Now this function is the thing that pulls the whole game together, and thus, it is probably the most confusing. Here's what it does:

- Initializes pygame and the screen
- defines objects and their views and puts them in appropriate arrays
- defines controller
- Runs main while loop, which updates object positions, draws the corresponding views, and checks for events. This stops running if the player dies or closes the window.
- If the player dies, it runs another while loop which displays the losing screen.

And that's it!

## So how do I play?
Assuming you're working in Linux, it's really as simple as installing Pygame, downloading playfile.py, and calling it in Python using your terminal. This is what this will look like in your command window:

First,
```
pip install pygame
```
Next,
```
python playfile.py
```
And look out, because now you're playing!

If you run into some issues installing Pygame or even Python, [this is a nice guide to refer to](https://www.pygame.org/wiki/GettingStarted).

## Other questions

#### It's running too slow, what can I do to fix it?
Try lowering the mod on the counter in the first if statement of the main while loop. For example, try turning this:

```
while running == True:
counter += 1
if counter%5 == 0: # adjust this
controller.handle_event()
```
into this:
```
while running == True:
counter += 1
if counter%2 == 0: # adjust this
controller.handle_event()
```
Beyond that, this really isn't the most efficient thing in the world right now... sorry about that.

#### Why do I always lose?
Life isn't fair, buddy. Neither is this.

## License
Hmm.
Binary file added images/gameover1.bmp
Binary file not shown.
Binary file added images/ground.bmp
Binary file not shown.
Binary file added images/ground2.bmp
Binary file not shown.
Binary file added images/lovinlife.bmp
Binary file not shown.
Binary file added images/platform.bmp
Binary file not shown.
Binary file added images/player.bmp
Binary file not shown.
Binary file added images/player_jump.bmp
Binary file not shown.
Binary file added images/train.bmp
Binary file not shown.
Loading