Space Junk is a Qt game about space junk submitted as my final project for USC's CSCI 102L. It has been tested on Ubuntu 10.04 using Qt 4.6.2, but should work on other Linux systems and possibly Windows and Macs.
I changed the maximum player health from 100 to 150 at the last moment before turning in the assignment. If you think that is too easy, I suggest setting the HealthMax constant near the top of game.h to 100.
Here are some of the more interesting aspects of the game from a technical perspective:
- Since everyone asks me, the gravity calculation uses Newton's law of universal gravitation and is implemented in a slightly optimized way in Obj::updateVel(). However, this is not the most interesting technical aspect of the game...
- Apart from floating point precision errors, the physics and AI in the game are independent of velocity. That means that if the velocity of all objects were changed by the same amount, the resulting behaviors would be identical from any object's perspective.
- To ensure objects start in a stable orbit, the second Obj constructor starts objects moving perpendicularly to the sun at a velocity about 1/2 to 1 times that required to put it in a circular orbit.
- If you change the frame rate, the game will adjust to make everything still happen at approximately the same speed.
- In space, you CAN hear sounds, but only sounds that don't have to travel through the vacuum of space to reach your spaceship. Therefore, in the game, you only hear sounds when the player runs into something. The sounds of propellant hitting the player are actually taken from the public domain NASA video at http://www.nasa.gov/mp4/157765main_srbiPod.mp4 from the part where pieces of propellant hit the solid rocket booster shortly after solid rocket booster separation, where the atmosphere is much thinner than it is at the ground.
- When objects explode, they don't remove health from the player directly. Instead, they create a bunch of propellant objects at a position colliding with the player, and the collisions with propellant are what remove health from the player. Therefore, the number of propellant objects the player runs into is a good and consistent measure of damage taken.
- The number of particles some explosions make are equal to a constant value plus an amount proportional to the change in kinetic energy of the player.
- All object creations and deletions conserve momentum from the frames of reference of the objects involved except for unobtainium and health pack collection, which I didn't think that made sense for. (They don't conserve momentum from other frames of reference because the game doesn't conserve mass. To conserve both momentum and mass would require propellant to have a tiny mass, objects to lose that amount of mass when they emit propellant, and for objects to emit propellant at ridiculously high speeds. You can see what that would look like by setting PrMass in game.h to "(MissileMass - MissileEmptyMass) / MissileMaxPropel" (no quotes) and watching the missiles in the War of the Worlds level. Real rockets do emit propellant at that sort of speed, but that didn't make sense for the game because it wouldn't let propellant clutter up the solar system and act as space junk.)
- In my opinion, the homing missiles in the last level are by far the coolest part of the game from a technical perspective. Basically, they take a sort of estimate of where the player will be by the time the missile arrives at the player's current location, then go to that location. More precisely, they find where the player would be if the missile moved in the current direction (relative to the player) for a distance slightly less than its distance to the player, then accelerate towards that location. If I had them accelerate directly towards the player rather than implementing this, they would've missed the player consistently. Also, homing missiles have limited propellant and lose mass as they shoot out propellant.
Space Junk is licensed under the MIT License, which you can read at license.txt.
To generate the full design document, run the following command: doxygen ./doxygen.txt