Spaceship Game
Language: C++, Middleware: Box2D, OpenGL
Overview of the project
Motivation
- How to build space game world having low gravity and friction.
Problem which I had
- Motion of spaceship should be different from any other vehicle in the Earth. Space should be infinite and objects in space have to be randomly generated. Various augmented information should be supported for better gaming experience.
Which features are included in this project
- Procedural generation of space and objects
- Accurate physics world and collision test
- Simple mathematics (computing inertial force and intersecting test) to improve gameplay
Detail of the project
1.Introduction
This project has focused on implementing physics based space game. Space has two distinctive features. First, there is no gravity so that the velocity will only be affected by driving force of space ship. Second, since there is no friction and no major gravity in space, the inertial force is maximum and driving power is a key factor to change direction. For such a reason, the effect of driving force of space ship plays significant role in this game. In addition, I have tried to implement infinite space so that space is procedurally generated. Finally, the difficulty of the game will be increase as time goes on since time is major scoring factor.
2.Specification
First of all, the movement of space ship was the key factor of this game. Basic manoeuvre of the ship is rotation and acceleration. The former determines the direction of the ship and the latter is used to change linear velocity (see Figure 1).
Figure 1. Manoeuvre of the ship
Figure 2. Before and after velocity interpolation
The trajectory of space ship in space is a lot different from that in ground.The interpolation between inertial force and current velocity determines it, which means that space ship goes previous direction before turning for few seconds, and then once current velocity becomes bigger than that, the ship follows in the direction of acceleration (see figure 3).
Figure 3. Interpolation of velocity
Secondly, the movement of enemy is similar to that of space ship. However, enemy ship has some distinctive features. First, its acceleration speed is much faster than space ship, but it loses its velocity while it turns the direction. In other words, enemy ship is much faster than space ship so that user’s ship is easily caught by enemy, but users can avoid this situation as turning its direction as frequently as possible, and then enemy ship will lose its speed. Second, it has radar frequency for detecting user’s ship. In detection phase, enemy ship updates target velocity toward user’s ship so that it always follows user. Also, if user changes the direction, enemy ship will have difficulty in setting target velocity (see Figure 4).
Figure 4. Movement of enemy having radar frequency
Third, ammo will be emitted along the direction of space ship (not along velocity). When ammo collides with enemies or asteroids, it will explode. In order to detect the moment of collision, the contact listener has been used in Box2D. Ammo will be alive for 2 seconds (see figure 5).
Figure 5. Collision check
Next, since universe is infinite space, it has to be generated procedurally, because it is impossible to render all at a time. Universe is divided into 9 zones which is 3 by 3 matrix structure and each zone has individual space texture, which will be randomly assigned from database. User’s space ship always locates in the middle zone so that the system only draw adjacent zones. Once it flies to next zone, new zone has to be drawn and some zone needs to be removed (see figure 6).
Figure 6. Zone creation
The level of difficulty is determined by the number of enemies and asteroids (obstacles). Enermies will be deployed every 10 seconds. Each zone contains equal numbers of asteroids and the number increases every 30 seconds. The health of space ship will decrease when it is hit by enermy or obstacles.
The indicators, which are on the boundary, inform users about the location of enemies. It computes a intersecting point of the line between the player's rocket and enemies with boundaries.
Finally, the game ends when the health of user’s ship becomes zero, and high score table will be displayed (see figure 7).
Figure 7. High score table
Figure 7. High score table