Ben Whittle - Cubular

CPE 471 – Intro to Computer Graphics Final Project

Overall Goal

My goal for this project was to recreate the game Cubefield using some of the techniques learned in this class.

 

Game Objective:

Control the triangular vehicle to avoid the cubes for as long as possible. The longer you survive, the faster the vehicle moves and the more difficult it is to avoid the cubes.

Original Game:


My Game:         

 

Techniques Used

Multiple shaders

In order to change the look of the game as you progress, I used multiple shaders and different materials to be able to change the look of the ground, the squares and the player vehicle.

·         Blinn-Phong shading model was used for the cubes for levels 1 and 3 (pictures 1 and 3 for my game under Overall Goal) and for the player vehicle in all levels

o   Level 1 used a material that had values for the ambient, diffuse and specular components of Phong shading to produce cubes that reflected the light and seemed to shimmer

o   Level 3 used a material that had only the ambient and diffuse components of Phong shading so the color of the cubes was not affected by the light source

o   Player vehicle used a material that also only had the ambient and diffuse components of Phong shading and only the ambient component was changed depending on the level

·         Silhouette shading (similar to the shader used for Assignment 3) was used for the cubes for level 2 (picture 2 for my game under Overall Goal)

o   This shader gave a feel of motion blur to some extent and was unique compared to the other levels

o   I modified the shader slightly from Assignment 3 to include the alpha value for the color and make the cubes somewhat transparent

·         I also used a separate shader for the ground to just have a uniform color for the whole plane

o   The color for the plane was specified by a uniform variable passed into the shader

 

Free look camera

In order to move the player vehicle through the world and have the camera follow the vehicle, I implemented some of the functionality from Assignment 4 for the free look world.

·         The applyViewMatrix() method of the Camera class was modified to use the MatrixStack::lookAt() function in order to implement the Free Look camera

·         Only the position component was used for my Free Look camera since I only needed forward and sideways motion and not yaw or pitch

 

multiple objects

In order to create the objective for the game (avoiding the cubes), I needed to continuously add multiple squares to the world.

·         I used a modified version of my Object class from Assignment 4 to create the cube objects in the world

o   The initial cubes were created in init() with a random position and color

o   Throughout the entire game, only 75 cubes are drawn

§  I found that 75 cubes was the perfect amount to make the game somewhat challenging without being impossible

§  75 cubes are also a good amount to keep the game from having to process too much information and causing it to lag

§  Since I only use 75 cubes, I used a technique similar to that in the Particle class for Lab 11 to update the position of the cubes based on the position of the player

·         Cubes that go behind the player are redrawn in a bounded random position a reasonable distance ahead of the player, otherwise they remain in the same position

 

collision detection

I used collision detection to check if the player vehicle had ran into a cube or not. If the player does hit a cube, the game gets reset.

·         I decided to use Bounding Sphere collision detection

o   Bounding Sphere detection is easy to implement and quick to calculate

o   The game does not require super precise detection so Bounding Sphere was also good enough to accurately detect the collisions

 

Physics

I used a velocity for the player vehicle to update the position of the vehicle and the camera.

·         I used a simplified version of the particle position updates from Lab 11 to calculate the position of the vehicle for my project

o   After a specified amount of time, the speed of the vehicle is slightly increased which increases the difficulty of the game

o   Moving the vehicle left and right changed the velocity of the vehicle in the x direction

o   I did not use acceleration since I wanted the speed of the vehicle to remain the same until the game increased the speed

 

Challenges

The only real challenge I had with this project was getting the movement of the vehicle to be smooth and instantaneous.

 

Problem

The problem with key input for games is how key repetition actually works. There is always a small delay between when the key press action is registered to when the key repeat action starts occurring*. This is a problem since we want the movement of the vehicle to be constant and instantaneous when we press a key and the delay interrupts the constant movement.

*Note: You can test this delay by pressing and holding down a single key. The time between when the first letter appears and the second letter appears is the delay between key press and key repeat.

 

My Solution

The solution that I used to get around the delay was to use 2 bool variables in my Player class. One bool is used for left movement while the other is used for right movement. When the key for left movement is pressed, it sets its corresponding bool to true and lets the Player know that it needs to move left. The player vehicle will then move to the left as long as the key is held down. When the key is let go, the key release action is registered and that sets the same bool back to false notifying the Player that it should no longer move left. The solution is the same for right movement and its corresponding key and bool.

 

When both keys are held down, both bool variables will be true, but there will be no horizontal movement until one key is released since the movement will be canceled out.

 

Controls

A: move the vehicle to the left

D: move the vehicle to the right

Space: starts the game (doesn’t do anything if the game has already started)

P: pauses/resumes the game (doesn’t do anything if the game hasn’t already started)

R: restarts the game (doesn’t do anything if the game hasn’t already started)

Esc: exits the game

L: change the look of the level (does not increase speed, only meant for debugging, level design and demo)

 

Game time (score) is output to the console when either a collision occurs or when the game is restarted.

 

References

Shading, Free Look Camera, Multiple Objects, Physics

·         CPE 471 Labs and Assignments

Bounding Sphere Collision Detection

·         https://polylearn.calpoly.edu/AY_2015-2016/pluginfile.php/528597/mod_resource/content/0/collision.pdf

More in Depth Description of Key Press and Key Repeat States and Why the Delay Exists

·         http://stackoverflow.com/questions/34170998/glfw-input-states

Obj Files

·         Cube.obj was taken from previous assignments

·         Player.obj and Ground.obj were created by myself

Original Game

·         https://www.crazygames.com/game/cubefield