Home

Awesome

Asteroid game with minimal physics

Asteroid game thumbnail

Click the image for video of gameplay

The asteroids can collide between themselves and the ship. They all have linear momentum and angular momentum. Depending on how they collide, they may change rotation. All collision are elastic and this is not an accurated physics model. There are references in the code for more precise physics if anyone wants to know how to make something better. The game has a very 8-bit sounds the closest I could do to match the original sounds of the asteroid game. I only made 5 sounds for shooting normal bullets, particle wave cannon shot, shield, explosion, and ship's thrusters.

I made this game just to test how well the GJK algorithm can detect collisions with some minimal physics involved (done in Processing v3.5). I didn't create any unit tests for this, testing all while it progressed, adding more components until it got to this point. I wanted minimal number of classes, so I skipped any abstract parent class with common resouces for asteroids, bullets and ship. The GJK algorithm works fine in the simple scope I did for handling the collision detections. That caused some bugs, but I'm satisfied with the results as I was not expecting this to work at all without any refinements. In fact, this is not optimized in any way, and if you are interesting on such a thing, check this book as reference, Real-Time Collision Detection, and my other geometric algorithms repository as it has a bit explored in the subject.

Game mechanics:

Controls inputs are A,D [spin the ship] / S [shield] / W [thrusters] / Spacebar [shoot/charge energy] / Enter [new game]. Only one control input action per frame. And while charging the particle wave cannon, little control on other inputs. Destroying a big asteroid will create 2 or 3 small ones from its debris. Big asteroids generate 20 points and need 2 shots to be destroyed, while small ones generate 10 points and need only 1 shot. The ship colliding with activated shields can destroy small asteroids, but only weakens big ones (only one extra shot needed to destroy it).

Knowing bugs:

Geometric Algorithms references

Now the actual usefull stuff! The references used on each function are in their header comment.

Good luck space-cadets! Use for reference!

     Space folding!
       .      .   . .   .  +   .    .         
                         .       .      .
          .     *
     .       *               . .     +  *
        .               :.       +   . 
      .  .   .  + .                         .  *
           _____________________     .
          / +.         .   *    "-_           .
         /   .- Y -.               \      +
        /   : \ | / ;    +   .      \      .
       /  +  '-___-'   .   .    + .  \
      /_______________________________\    .     .
           ____| |________________.J' #L
          /.+  J L   .   .     . +..    \    *  .   +
         /    / ! \     +   .            L
        /   :'  x  ':         :     .    F      .
       / .   '-___-'  +..  .     *      /    .
      /______________________________-="
              .    * . . .  .              +     .
      . .     .      .            *
            .      .   .        ! /       + .   .
       *             .        - O -   .
           .     .          . / |
      +             .  ..             +  .
           .   .  *   .      +..  .          *