Time trial racing game in OpenGL
Alexander - 17/04/2014
Developed by myself as part of the coursework for the Graphics module of the Computer Games Technology MSc degree which I am currently reading.
This game is a time trial racing game with additional scoring in the form of pickups which reward you with one point each. The player must try and complete three laps in the shortest possible time while picking up as many points as possible in that time. There are many obstacles in the player’s path which they must avoid or they will be immediately halted until they navigate their way around the obstacle. Players can move around the inside of the tube and adjust their forward speed between two pre-set values. Additionally players can shoot bullets which will clear out obstacles that they collide with making the game easier, but they won’t earn so many points.
The track is created by specifying a series of points in the scene and using interpolation to created a smooth curve linking the points together. From there a specified number of points is created around each point along that centreline forming dotted circles. These circle points are indexed so that they can be reused when forming the triangles between the circle points. The backface of these triangles are culled so that we only see the sides pointing inward inside the tube. This allows us to see in from outside as well as not see outside from inside.
Obstacles in the scene are simply textured cubes created using primitives, as well as the point pickups which are textured regular tetrahedrons. I created a function which takes a series of values based of how many obstacles / pickups you want in the scene, the spacing between them, the angle between them, and so on, and returns a vector of pairs which each hold the position and orientation of a single object to be rendered. The orientations are adjusted to always be relative to their position in the tube so that their up vector is pointing towards the centreline as opposed to simply up in the y axis. This vector allowed me to initialise the positions at the start of the game and simply iterate through the vector when rendering or handling collision detection.
The lighting in the scene by default uses the Phong model with no colour so it is clearly lit, but when toggling the spotlights in the scene, the main lighting is turned off setting the scene into a dark or night time mode. In this mode the lighting is done using the Blinn Phong model and the spotlight(s) are positioned from the ship pointing forward. When using one light, it is directed straight forward and is white, and when using two lights they are angled outward slightly and one is blue while the other is red with an overlapping purple area in the middle. The different lights can be seen in the second and third lap of the video.
Also during the dark mode the ship and the finishing sign models are rendered using toon shading with an edge mask. to emphasise the night time effect and also just for fun because toon shading can look pretty cool.
There is a minimap in the bottom corner throughout which uses no lighting at all but instead just renders the texture colour of the objects in the scene creating a 2D effect. This map is done using a Framebuffer Object and multipass rendering. In the first render pass, the scene is rendered without lighting from a top down view without a minimap, and then in the second pass the scene is rendered as normal with the data rendered from the first pass being displayed on a quad in the bottom right corner of the camera’s 2D projection matrix (in the same way the HUD text is rendered to always be on the screen).
The camera and ship are positioned relative to the centreline so that the ship always stays inside the tube and the camera is always in a third person position behind the ship. When the player presses left or right the ship is rotated about the centreline to move along the edge of the inside of the tube. The camera can also be toggled to a top down perspective which also follows the ship, as well as a separate camera which is directed with the mouse from outside the tube, which both can be seen at the end of the video.
The spaceship, the bullet, finishing line sign and benches (which are outside the tube) are all premade models which I downloaded and imported into the scene. The bullet is fired from the ship’s position and uses the ship’s forward axis for its direction, and the finishing line is in a fixed position at the end of the track and is oriented to stay the same way up as the ship so it can always be read.