Search This Blog

Friday, September 12, 2014

Damage Collector & Callback Explosions Oh-and a Shader Effect

Damage Collector

When you get hit, a bullet, or impact delivers its damage to your "damageTaken" variable --and nothing happens --until the Damage Collector gets wind of it --which it does about once a second.

In this game, I wanted damage to be more than just yourHealth - BulletDamage when a bullet hits you. When you start talking about regenerating shields, armor, and systems damage --followed by smoke, sparks flying and maybe parts flying off, it starts to get more complicated.

To follow the Single Responsibility Principle and keep my code manageable I created an event that fires each second to go through all ships and assess their damage and figure out what happens to them.  This Event is called the Damage Collector.

This is gonna cost ya, pal...
To handle Shields is pretty simple. Take the damage out of shields first... if that's all used up, take the rest out on the armor --which is a little more complicated... no more armor?  Well now I'm gonna have to verify you have photon bolt coverage on your insurance policy! Things can potentially get interesting here.

Armor doesn't suck up damage the way shields does.  After all you could get hit in the armor in the exact same spot a couple of times and start taking real damage --or get hit in a critical spot--a weak point in the armor.  So Armor is more of, well, armor, than a shield.  Damage has much more chance of hitting armor as it does of causing internal damage... but you can still get killed with full armor and just a few choice insults to your ship. The good news is Armor doesn't necessarily go down when it gets hit.  There's a good chance it will deflect the bad energy like a yoga class with no damage at all.

I used to play Star Fleet Battles...  their damage system is great.
Which squares are the red-shirts?
After all the shooting, the damage was doled out either randomly or the player got to decide where to take the hits.  Different parts of the ship had different amounts of hit-points --squares on this picture, and when those were all used up, they would no longer function --or in the case of generators or weapons, work to the extent that they're not damaged.

The point is, now that I have a single place where all damage is figured out, I'm free to make it as complicated as I want behind the scenes.   

None of this complexity should involve the player much --it should always feel like an 80s shoot-em-up arcade game.  I don't want to bog the action down too much in minutia --I'm loathe to allow the player to set forward vs aft shields for example or repair things beyond very basic aggregate systems.  Like Shields Armor and Engines. And then only then briefly between action.  This is an action game. 

But I loved it in Wing Commander when parts of the HUD became cracked and sparky and inoperable and you had to limp home, barely surviving a mission-- and I want to capture that skin-of-your-teeth feeling in Captain Zero if possible.

Cracks in your windshield? Call EasyGlass! The Windshield Specialists!

So I'd like to have cracks in the player's view, and maybe parts of the hud broken off and sparkie or have the scanner show video noise and be cracked... stuff like that.  If the player is damaged, I want him or her to know it!

Callback Explosions

The Function object in Construct 2 is a very powerful programming tool.  It allows recursion, facilitates encapsulation and abstraction, and, because you can call functions by their name--even if that name is stored in an instance variable of an object-- a little reflection as well.  This allows cool programming tricks like late-binding and callbacks.  Things you would need delegates to do in, say, c#, you can do easy in Construct 2 with a function call. 

I can send a parent "explode" function a string containing the name of some or other specific minor or effect explosion functions for it to call based on whose doing the exploding.  Thus functions can easily call functions named explicitly in their parameters.  Instead of different ships having different explosion effects, I have them pick from a buffet of explosion effects --they can mix and match.

Shader Effect

One platter in that explosion  buffet is a cool shader effect that warps space in an expanding circle giving the idea of expanding gas or a shock wave from the explosion.  Oooo.  Aaaah. 

No comments:

Post a Comment