By Brian Cheng, Kauri Mai, Andrew Yanez, Perry Thampiratwong
This game is a simple arcade game where the player must avoid obstacles in order to survive. The player can control their character by either using the mouse or the keyboard. As the game progresses, the obstacles will move faster and faster, making it harder to avoid them. To get the highest score, the player must survive for as long as they can by avoiding the obstacles that appear after a short warning period.
- The character is able to move up and down by either pressing the up/down arrow keys or by holding down the left mouse button and releasing it to move down.
- Press the R key to restart the game.
- Press the Q key to quit the game.
- If the character goes out of bounds, it will be moved to the opposite side of the screen.
- Before a new obstacle appears, there will be a short warning period where the player can prepare to avoid it.
- As time progresses, both the character and the obstacles will move faster and faster, there will be more obstacles, and the warning period will be shorter.
- The game ends when the character collides with an obstacle.
Build the exectuable with:
make csil
To run the game:
./arcadeCsil
If you get an error about the png library run the following command and then try building again:
sudo apt-get install libpng-dev
Install Homebrew if you haven't already:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then install the necessary libraries:
brew install freeglut xquartz
Build the exectuable with:
make mac
To run the game:
./arcadeMac
If you get an error about the png library run the following command and then try building again:
brew install libpng
The code governing the player object is mostly within Character.h and Character.cpp
-
In Character.h, all the getter/setters methods for the player's position and state are declared as well as any methods relating to user input.
-
In Character.cpp the
updateMovePosition()
checks themovingUp
state of our player and adjusts its position accordingly. ThemoveKey()
andmoveMouse()
methods check for their respective user inputs and updates themovingUp
state depending on the input. -
The
checkCollision()
method checks if the player has collided with an obstacle, and thedraw()
method draws the player on the screen.
The code governing the NPC objects is mostly within npc.h and npc.cpp
-
There are two types of NPCs, warning signs that appear on the far right side of the screen and bullets, which emerge from the warning signs, move towards the player, and must be avoided.
-
NPCs contain two doubles that store the coordinates of their center point, a Type enum to determine the type of NPC.
-
The main functions for each NPC are
draw()
andmove()
.draw()
takes no parameters and checks whether the NPC is active, and then calls the specialized draw function for the NPC type to print it on the screen. Themove()
functions takes two doubles, dx and dy, and changes the center of the NPC by those respectively, if it goes outside the bounds of the screen, the center is reset to the opposite side that it was moving (moving off towards the left puts on the right side of the screen)
There are various miscellaneous\helper functions that are used throughout the codebase, such as drawing basic shapes, loading textures, and checking for collisions. These functions are located in util.h and util.cpp, texture.h and texture.cpp, and background.h and background.cpp respectively.
- Background.h and background.cpp are simple helper files to create a textured background of the game
- Texture.h and texture.cpp are used to load textures from png files and draw them on the screen
- Util.h and util.cpp contain various helper functions such as drawing circles, rectangles, triangles, render text, randomly activate the bullet streams and draw the end screen
The main code is located in main.cpp and where the main game logic is located.
-
The main function initializes the npcs and the game window and sets up the game loop, it also calls glut functions to handle user input.
-
To initialize the NPCs, the function
setupNPCs()
is called, which creates the warning signs and bullets and sets their initial positions. The game window is setup in theInitialize()
function, which sets the window size and loads the textures for the endScreen, background, and player -
The game loop is split between the
update()
anddisplay()
functions.update()
is called every 33ms, which results in about 30fps, and while the game is not over, updates the positions of the player and NPCs, increases the points and difficulty, and checks for collisions.display()
is also called every frame and draws the background, player, and NPCs on the screen. It also draws the end screen if the game is over. -
User input is handled through GLUT functions. When the mouse is used, it calls the
mouse()
andmoveMouse()
function in Character.cpp, which checks if the left mouse button is pressed or released and updates the isMovingUp state accordingly. When the keyboard is used, it will call the proper keyboard related function to check if R is pressed to restart the game or if the up/down arrow keys are pressed to move the player up or down.