I have been spending a lot of time building up the storytelling elements of the game by using the stuff I build in my adventure engine project, but half of this game is action, not drama! The interactive stuff until now basically was the stuff I did in the "asteroids" engine. So it was time to actually start working on the action game play proper.
I started an NPC lib, which may be poorly named as it is entirely possible that player function will also be stashed away there, but for now, the name applies! This library does the collision detection, NPC actions and manages the on screen assets.
In the following short demo, you can see how the Defiant is firing its phasers on a Jem Hadar ship. When hit, the shields will show, but they will also weaken. When the shield is gone, the ship explodes.
The methodology is pretty straight forward. When the enemy ship is spawned, it gets it's attributes and a starter function. This function sets the attributes like shield and strength. Finally it attaches the relevant NPC function to the active object, which means that every loop, this function will be executed.
It is the NCP function that checks for its own damage and subtracts the "points". When the shield reaches zero, the media object for the ship is altered to the explosion sprite and the attached function is set to the explosion function, which will play the sound, animate the KaBooooOOOom for 15 frames/cycles and then set the object inactive so it will be invisible and not have it's function called.
The in game object can now be reused for a new enemy. The number of in game objects like this can be anything but for now it is just 1. These are defined in advance in the game script.
The next thing to do is to build some gauges to see the shield and hull strength for the Defiant and perhaps the enemy ship, tweak the game play, add some more weapons and enemies and call it a workable demo which I'll be putting online for all to try out.
In advance.. it will be buggy! And now... CARNAGE!