Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5cc8356
Setting up GitHub Classroom Feedback
amonmillner Apr 7, 2020
f8e5d15
Basic Gameplay And Assets
toluooshy Apr 7, 2020
3d92499
Switched Track Generation Algorithm To Strings, Read/Write System Imp…
toluooshy Apr 13, 2020
2af7636
Added Working Menu System, Additional Course Scenes, MVP Completed
toluooshy Apr 17, 2020
481ccc1
Tweaked Menu System, Added Additional Individuality To Cars, Added Un…
toluooshy Apr 18, 2020
de82c77
Improved Timing Mechanic, Added Obstacles, Added Music, Tweaked Minor…
toluooshy Apr 19, 2020
36033e1
Added Win/Loss Frames, Implemented Data Saving System, Created Overal…
toluooshy Apr 21, 2020
5fc7bc9
Added Win/Loss Frames, Implemented Data Saving System, Created Overal…
toluooshy Apr 21, 2020
a190ac9
Updated Collision Detection, Balanced Gameplay, Added Docstings, Fixe…
toluooshy Apr 22, 2020
00ccb70
Finished Docstrings, Removed Redundancies, Balanced Gameplay
toluooshy Apr 23, 2020
45ca3f0
Added README
toluooshy Apr 23, 2020
40e2cdd
Updated README
toluooshy Apr 23, 2020
fa0167f
Updated README
toluooshy Apr 23, 2020
5fe2392
Continued Updates to README
toluooshy Apr 23, 2020
ecfedd4
Implemented Supplementary Features, Edited README, Added More Source …
toluooshy Apr 23, 2020
d98ccb9
Edited README, Updated Menus To Accommodate New Features, Updated Scr…
toluooshy Apr 24, 2020
966a967
Distributed Functionality Of 'main.py' Into New 'KeyInput' Class, Cre…
toluooshy May 1, 2020
4f36cdf
Fixed Bugs In Music Handling
toluooshy May 1, 2020
419712f
Added Cross-Platform Compatibility, Updated README, Fixed Bugs
toluooshy May 5, 2020
bd53202
Updated README, Fixed Grammar
toluooshy May 5, 2020
3403586
cew
pat4life360 May 5, 2020
0b7473d
GIF Files
pat4life360 May 5, 2020
1cbacc6
GIF Files
pat4life360 May 6, 2020
415a3a6
Updated README
toluooshy May 7, 2020
92d47af
Set theme jekyll-theme-minimal
toluooshy May 8, 2020
d9323e6
Updated README
toluooshy May 8, 2020
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
1 change: 1 addition & 0 deletions DepthProject-tolu-patrick
Submodule DepthProject-tolu-patrick added at bd5320
141 changes: 141 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# PyRacer:
<img src="gifs/intro.gif" alt="Game Title Screen/Main Menu" width="400" height="250"/> <img src="gifs/coursedrive.gif" alt="Gameplay" width="400" height="250"/>

## Running The Game:
PyRacer was developed with Python 3 and requires Python 3.4 or higher installed on your machine to play. In addition to this, cross-platform support is available but on Windows all the necessary libraries must be visible to the directory where the game files are kept.

- In order to run PyRacer you must have PyGame, as this is the library much of the code is based on.

- To install PyGame run the following code that best fits your situation in your terminal:

- Globally on your OS- `python3 -m pip install -U pygame`
- For a singular user- `python3 -m pip install -U pygame --user`

- Some other libraries that may need to be installed are `numpy`, `pathlib`, and `contextlib`.

PyRacer was developed in Ubuntu and is designed to work on Linux and Mac OS, but can also run on Windows with the proper file specifications.

Once PyGame is installed open the directory in which the game files are saved and run `python3 scripts/main.py` in the terminal of that directory.

## Gameplay Overview:
Here, we have a 2.5D car racing game, in which you have to drive your selected car through obstacles, and on the road in order to complete the track.

The goal of this game is to beat all 6 stages to unlock the last car. Each stage of this racing game is a track, that a car that completes 3 rounds through a selected track chosen in the menu.

For car choices, we have an option of the fastest car, but low durability, a medium speed car with medium durability, and a low speed car with high durability, and your objective is to complete the stage without your car getting destroyed.

There are laser beams coming overhead which enact damage to your car if it comes into contact with the beams. We have turbochargers as icons, which signify the number of stages you have completed. A golden turbocharger means you have completed one of the six stages.

In order to reset number of turbochargers and the saved game data, simply press "r" in the menu.
In the folder, if you navigate to `data/gamedata/gamedata.txt`, you will see any collection of seven numbers that are either 0's or 1's, which represent the completion values of each course completed. Changing them all to 0, sets all courses as uncompleted.

You also have different background music for each of the stages, as well as a HUD and stage completion indicator, giving you all the information you need to finish the stage.
To toggle the music on or off at any time, press "m".

To open the web-page for PyRacer's information (it will be a link to this page on GitHub), press "i".

In summation, this game is a modern adaptation of the classic SEGA game 'Outrun', with a remix to the original game play where the you can choose between three different cars and race along 6 different courses. The primary objective of this game is to complete all six courses successfully, and if this goal is achieved you will be rewarded with the special fourth car. Below are the basic descriptions of each car.

*P.S. If you have unlocked the special fourth car press "l" at any time for a surprise!*

### The Sprinter:
<img src="images/player/side1.png" alt="Sprinter Profile View" width="94" height="31"/>

This car is the fastest but least durable.

### The Sport-Utility:
<img src="images/player/side2.png" alt="Sport-Utility Profile View" width="96" height="36"/>

This car is somewhere in between in terms of speed and durability.

### The Big Rig:
<img src="images/player/side3.png" alt="Big Rig Profile View" width="100" height="50"/>

This car is the slowest but most durable.

### The ?????? ??????:
<img src="images/player/silhouette.png" alt="?????? ?????? Profile View" width="95" height="26"/>

???


## Under The Hood:
This game utilizes the PyGame library to accomplish several tasks; from rendering images and playing music to displaying the head-up display and handling user input. Used in accordance with object-oriented programming this game is brought to life.
<img src="gifs/coursefinish.gif" alt="Gameplay -Mission Passed" width="400" height="250"/>

### Classes & Methods:
There are five files and four classes that help create the game, with some handling the objects in the game and others handling the data the game uses.

---
#### The `Player` Class & File:
This `Player` class is used to display and update the player object (the car that the user controls).

The `__init__()` function defines the source images for each car as well as some positioning and collision defaults.
The `move()` makes the car move sideways.

---
#### The `Road` Class & File:
This `Road` class is used to display and update the road object (the simulation of forward movement in the game).

The `__init__()` function defines the aesthetics of each road that can be rendered and pulls the appropriate track data to read from.
The `update()` function defines how each slice of the road/ground/sidelines will render depending on self.tilt, and the index of the respective list.
The `readtrack()` function reads through the track data file and dictates how the overall course will react on each frame switch.

---
#### The `Laserbeam` Class & File:
This `Laserbeam` class is used to display and update the laserbeam object (the obstacles that the user must avoid).

The `__init__()` function defines the source image for the lasers and the possibilities of how the lasers will act, as well as some positioning and collision defaults.
The `update()` function defines how the lasers will act depending on a random given number, and controls the speeds at which they move.

---
#### The `TrackGenerator` Class & File:
The `TrackGenerator` class is used to generate a list of numbers that will correlate to how the in-game road will operate.
Each number from 1 through 5 will cause the road to act differently:
1 - Road holds to the left.
2 - Road turns to the left.
3 - Road holds to the center.
4 - Road turns to the right.
5 - Road holds to the right.

The `__init__()` function defines the possible pieces of the track that can be put together.
The `generate()` function uses the predefined pieces for a track written with strings to make a complete track.

---
#### The `KeyInput` Class & File:
The `KeyInput` class is used to handle user input from the keyboard.

The `read()` handles the game's reactions to the user's input.

---
#### The `GlobalVariables` Class & File:
The `GlobalVariables` handles the all the global variables in the game.

The `__init__()` function initializes every single global variable that all the other objects can access during runtime.

##### In addition to these classes there is the fundamental 'main' function.

#### The `main` Function:
The `main()` function is used to run the game, manage which objects render, and play music, along with saving data and pulling data to be read by the objects that need it.
First all the objects are initialized and then in the following while loop all of the interactions (from user input, to collision detection, to the head-up display and UI) are handled.
##### The while loop:
Although dispersed, the while loop in this function can be split into three overall concepts: Graphics Rendering, User Input, and Collision Detection.
Two of the three concepts are presented in the `ingame == False` statement while all three are presented in the `ingame == True` statement.


## Usage Rights:
**Source Image Citations:**
Car Sprites:
Chase H.Q. II/Super H.Q. (Sega Mega Drive/Genesis); Ripped by Yawackhary; Developed by I.T.L.; Taito Corporation 1992.

Lotus Turbo Challenge (Sega Mega Drive/Genesis); Ripped by Yawackhary; Developed by Magnetic Fields, Gremlin Graphics Software; Electronic Arts 1992.

Music Sources:
Lil Uzi Vert; "Lotus"; Eternal Atake (Deluxe); WMG (on behalf of Atlantic Records); Warner Chappell, Kobalt Music Publishing; Instrumental Remake By OBITX.

Vivid Sound × Hybrid Colors: Sonic Colors Original Soundtrack; Wave Master.

*All other source files were either royalty-free or made in-house.*

# System Diagram:
<img src="System Diagram.png" alt="System Diagram" width="960" height="540"/>
Binary file added System Diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-minimal
1 change: 1 addition & 0 deletions data/gamedata/gamedata.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1111111
1 change: 1 addition & 0 deletions data/tracks/track1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
33333333333333333333333333333333333333333333333333444444444444444444444444444444445555555555555555555555555555555522222222222222222222222222222222444444444444444444444444444444445555555555555555555555555555555522222222222222222222222222222222333333333322222222222222222222222222222222111111111111111111111111111111114444444444444444444444444444444433333333333333333333333332222222222222222222222222222222211111111111111111111111111111111444444444444444444444444444444443333333333333333333333333333334444444444444444444444444444444455555555555555555555555555555555222222222222222222222222222222223333333333333333333333333222222222222222222222222222222221111111111111111111111111111111144444444444444444444444444444444333333333333333333333333333333
1 change: 1 addition & 0 deletions data/tracks/track2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
33333333334444444444444444444444444444444455555555555555555555555555555555222222222222222222222222222222222222222222222222222222222222222211111111111111111111111111111111444444444444444444444444444444444444444444444444444444444444444455555555555555555555555555555555222222222222222222222222222222223333333333333333333322222222222222222222222222222222111111111111111111111111111111114444444444444444444444444444444433333333333333333333333333333344444444444444444444444444444444555555555555555555555555555555552222222222222222222222222222222233333333333333333333333333333333333333332222222222222222222222222222222211111111111111111111111111111111444444444444444444444444444444444444444444444444444444444444444455555555555555555555555555555555222222222222222222222222222222222222222222222222222222222222222211111111111111111111111111111111444444444444444444444444444444444444444444444444444444444444444455555555555555555555555555555555222222222222222222222222222222222222222222222222222222222222222211111111111111111111111111111111444444444444444444444444444444443333333333333333333333333333333333333333
1 change: 1 addition & 0 deletions data/tracks/track3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
33333333333333333333333333333322222222222222222222222222222222111111111111111111111111111111114444444444444444444444444444444433333333333333333333333333333344444444444444444444444444444444555555555555555555555555555555552222222222222222222222222222222233333333332222222222222222222222222222222211111111111111111111111111111111444444444444444444444444444444444444444444444444444444444444444455555555555555555555555555555555222222222222222222222222222222223333333333222222222222222222222222222222221111111111111111111111111111111144444444444444444444444444444444444444444444444444444444444444445555555555555555555555555555555522222222222222222222222222222222333333333333333333333333333333444444444444444444444444444444445555555555555555555555555555555522222222222222222222222222222222333333333333333222222222222222222222222222222221111111111111111111111111111111144444444444444444444444444444444
1 change: 1 addition & 0 deletions data/tracks/track4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3333333333444444444444444444444444444444445555555555555555555555555555555522222222222222222222222222222222222222222222222222222222222222221111111111111111111111111111111144444444444444444444444444444444333333333333333333334444444444444444444444444444444455555555555555555555555555555555222222222222222222222222222222223333333333222222222222222211111111111111114444444444444444444444444444444444444444444444445555555555555555555555555555555522222222222222222222222222222222333332222222222222222111111111111111144444444444444444444444444444444555555555555555522222222222222223333333333333333333333333333334444444444444444555555555555555522222222222222223333333333333333333333333222222222222222222222222222222221111111111111111111111111111111144444444444444444444444444444444222222222222222222222222222222221111111111111111111111111111111144444444444444444444444444444444333333333333333333333333333333333333333333333
1 change: 1 addition & 0 deletions data/tracks/track5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
44444444444444445555555555555555222222222222222233333333333333333333444444444444444455555555555555552222222222222222222222222222222211111111111111114444444444444444333333333333333333332222222222222222111111111111111144444444444444443333333333222222222222222211111111111111114444444444444444333333333333333444444444444444455555555555555552222222222222222333333333333333333333333333333333333333344444444444444445555555555555555222222222222222233333333333333333333333333333333333222222222222222211111111111111114444444444444444444444444444444455555555555555552222222222222222333333333333333333333333333333333333333333333222222222222222222222222222222221111111111111111111111111111111144444444444444444444444444444444
1 change: 1 addition & 0 deletions data/tracks/track6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
44444444444444444444444444444444555555555555555555555555555555552222222222222222222222222222222222222222222222222222222222222222111111111111111111111111111111114444444444444444444444444444444433333333334444444455555555222222222222222211111111444444444444444455555555222222222222222211111111444444444444444455555555222222222222222211111111444444443333322222222222222221111111111111111444444444444444433333222222222222222211111111111111114444444444444444444444445555555522222222222222222222222222222222222222221111111111111111111111111111111144444444444444444444444444444444444444444444444455555555555555552222222222222222333333333333333444444444444444444444444444444445555555555555555555555555555555522222222222222222222222222222222333332222222211111111444444444444444455555555222222222222222211111111444444444444444455555555222222222222222211111111444444443333333333333332222222222222222111111111111111144444444444444444444444444444444444444444444444455555555555555555555555555555555222222222222222222222222222222223333333333444444444444444455555555555555552222222222222222222222221111111144444444444444444444444444444444444444445555555555555555555555555555555522222222222222222222222222222222222222222222222211111111111111114444444444444444333333333333333333333333333333
Binary file added fonts/Retron2000.ttf
Binary file not shown.
Binary file added fonts/SPEERG__.TTF
Binary file not shown.
Binary file added gifs/coursedrive.gif
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 gifs/coursefinish.gif
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 gifs/intro.gif
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 gifs/trackselection.gif
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 images/backgrounds/bg1.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 images/backgrounds/bg2.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 images/backgrounds/bg3.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 images/backgrounds/bg4.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 images/backgrounds/bg5.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 images/backgrounds/bg6.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 images/menuframes/frame1.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 images/menuframes/frame2.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 images/menuframes/frame3.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 images/menuframes/frame4.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 images/menuframes/frame5.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 images/menuframes/frame6.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 images/objects/finishline.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 images/objects/goldenturbo.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 images/objects/laserbeam.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 images/objects/startline.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 images/player/front1.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 images/player/front2.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 images/player/front3.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 images/player/front4.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 images/player/left1.png
Binary file added images/player/left2.png
Binary file added images/player/left3.png
Binary file added images/player/left4.png
Binary file added images/player/right1.png
Binary file added images/player/right2.png
Binary file added images/player/right3.png
Binary file added images/player/right4.png
Binary file added images/player/side1.png
Binary file added images/player/side2.png
Binary file added images/player/side3.png
Binary file added images/player/side4.png
Binary file added images/player/silhouette.png
Binary file added images/player/straight1.png
Binary file added images/player/straight2.png
Binary file added images/player/straight3.png
Binary file added images/player/straight4.png
Binary file added images/screenshots/gameplay.png
Binary file added images/screenshots/mainmenu.png
Binary file added music/music0.mp3
Binary file not shown.
Binary file added music/music1.mp3
Binary file not shown.
Binary file added music/music2.mp3
Binary file not shown.
Binary file added music/music3.mp3
Binary file not shown.
Binary file added music/music4.mp3
Binary file not shown.
Binary file added music/music5.mp3
Binary file not shown.
Binary file added music/music6.mp3
Binary file not shown.
Binary file added music/musicc.mp3
Binary file not shown.
Binary file added music/musicf.mp3
Binary file not shown.
Binary file added music/musicl.mp3
Binary file not shown.
Binary file not shown.
Binary file added scripts/__pycache__/keyinput.cpython-37.pyc
Binary file not shown.
Binary file added scripts/__pycache__/laserbeam.cpython-37.pyc
Binary file not shown.
Binary file added scripts/__pycache__/main.cpython-37.pyc
Binary file not shown.
Binary file added scripts/__pycache__/player.cpython-37.pyc
Binary file not shown.
Binary file added scripts/__pycache__/road.cpython-37.pyc
Binary file not shown.
Binary file added scripts/__pycache__/trackgenerator.cpython-37.pyc
Binary file not shown.
Binary file added scripts/__pycache__/variables.cpython-37.pyc
Binary file not shown.
60 changes: 60 additions & 0 deletions scripts/globalvariables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#import pygame and other necessary libraries
from pathlib import Path
import contextlib
with contextlib.redirect_stdout(None):
import pygame, sys
from pygame.locals import *

class GlobalVariables():
"""
The `GlobalVariables` handles the all the global variables in the game.
"""
def __init__(self):
"""
The `__init__()` function initializes every single global variable that all the other objects can access during runtime.
"""
self.WIDTH = 800
self.HEIGHT = 500
self.DISPLAY = pygame.display.set_mode((self.WIDTH,self.HEIGHT),0,32)
#boolean to determine if the game is in driving mode and should render the player, road, and obstacles or not
self.INGAME = False
#set default menu frame: 1-start, 2-car select, 3-course select, 4-win frame, 5-lose frame
self.FRAME = 1
#set default course to render as defined in road.py
self.COURSENUM = 1
#set default car to render as defined in player.py
self.CARNUM = 1
#boolean to determine if the game is on the start screen
self.STARTSCREEN = True
#value to determine the condition of the user's car (if 0 then mission failed)
self.CONDITION = 100
#boolean to toggle music on or off
self.PLAYMUSIC = True
#load game data file
datafile = Path('data/gamedata/gamedata.txt')
with open(datafile) as file:
self.GAMEDATA = file.readline()
file.close()
#boolean to toggle music on or off
playmusic = True
#render background image
menufilepath = Path('images/menuframes/frame1')
menufile = str(menufilepath)+'.png'
self.WINDOW = pygame.transform.scale(pygame.image.load(menufile), (self.WIDTH,self.HEIGHT))
#initialize dummy car scalings and vertical adjustments
self.CARXSCALE = 0
self.CARYSCALE = 0
self.CARYADJUST = 0
#initialize dummy road object
self.STREET = None
#initialize dummy player object
self.RACER = None
#initialize dummy laser object
self.LASERS = None
self.RACERDX = 1
self.STREETSPEED = 0
self.STREETSP = 0

#define the global object with all the varibles defined inside
global gvar
gvar = GlobalVariables()
Loading