JULY 2019

Chapter 18 -  Collision Detection


I now have the Aliens and their missiles hitting the player's ship and causing damage. Every collision takes away a bit of your Gunstar's energy, as indicated in the bars displays in the top right area of the screen. When that energy is depleted, any hit afterwards will destroy you... at least, when I add the Gunstar destruction routine. When this happens, it will be Game Over.

Takium and Fusion Energy charges will appear frequently and you must shoot these to collect their energy whenever possible. Collision with these does not affect your Gunstar but to obtain the energy they contain, you must shoot them.

How collision detection works in Gunstar

Unlike a proper hardware sprite system, it's very difficult and slow to do a pixel-for-pixel collision detection on a flat bit plane when that plane has a lot of moving graphics and every pixel of the screen is being changed on every video frame. Hardware sprites are isolated from the background and the electronics can act on direct pixel collisions.

The Color Computer doesn't have a hardware sprite system and so we must use software techniques to achieve this.

Collision detection in Gunstar works by comparing the X and Y coordinate positions of each moving sprite (Aliens, Gunstar and Missiles). It tests the boundaries of a square area around each moving object. This takes more CPU time so the tests have to be done efficiently so as not to waste time.

Looking at the image on the right... the yellow outline around the Gunstar sprite represents the area tested. Likewise, the blue outline around the Alien sprite represent the area tested for it.

When these two areas overlap each other, a collision is reported.

Notice the yellow outline area around the Gunstar omits the nose cone area of the ship. This is to ignore the open space areas on the left and right side of the nose cone. An Alien entering that area should not be reported as a collision, hence why I check for a lower region to get a more accurate indication of a collision. This also means that a collision with the nose cone will go undetected.

I could test for another outline area around just the nose cone but this just uses up more cpu cycles and is hardly worth doing because in most cases, the Alien ship will fly downwards and strike the lower regions anyway.

It does mean that you could collide with an Alien and veer downward and to the left or right, avoiding the collision, just for the fun of saying "See that cool maneuvre!".   :)


Click on the YouTube link below to see the actual game so far.


Video Blog #7


For the next chapter of the GunStar Development Blog, I will begin designing the graphics tiles for Levels 2 to 4.



Copyright 2017 by Nickolas Marentes