It's time to add some kind of "player health" system.
When thinking about the game, I had a vague idea about directly representing player health with the number of particles that will constitute your visible "body" parts.
Getting damage from enemies could strip away some particles, as if they stole/absorbed them.
One would become gradually less "material" and visible (made of less particles), until basically disappearing, and so losing the game.
Conversely, successfully destroying enemies should give some kind of bonus to the player.
It could give back some health, but I'm not sure I want to do that. It might be more interesting to give them some kind of special energy. And that energy could be used for... the ranged attack that I've been writing that I want to add since a few days back.
What about health? It could probably be progressively recovered with the passing of time (a regeneration system), as it's been common in games for some years.
Let's recap:
two energy values, let's call them "health" and "mana"
enemy attacks decrease the "health" level
destroying enemies increases the "mana" level
"mana" can be used to perform the ranged attack (which depletes it)
"health" automatically restores with the passing of time
I don't know if anything of this will get into the actual game, but surely it sounds good enough for the prototype.
Of course, I could also throw in some energy pick-ups of both kinds for the player to grab.
I guess that's plenty to do for today, let's dive in!
We don't have the "particular" visualization yet, but anyway for the debug visualization we'd need something more easily readable so that we can gain confidence that the systems work properly.
So, to get started, I'm going to add two little bars near the wrists and use those to represent the two energy levels.
Without having to deal with custom shaders and textures, we can quickly get working a simple 3D health bar using three properly scaled and positioned cubes. I'm also changing color of the "background" cube to signal a full bar.
Why three cubes? To make a decent health bar, you should not instantly update the foreground area when changing the health level because of a hit, as it's not well readable by the player and gives a glitchy feeling. It's much better add in a simple animation of the energy level change. But at the same time, one should instantly make the player aware of where the animation will end, which requires three elements:
background, always at full length
target level (instantly changes)
foreground, current level (constantly animating towards target level)
After attaching the bars to the wrists, I went and bound them to two values in the player entity.
In the spirit of the "energy stealing idea", I then went and changed the enemies so that, when they get close to the player, they start damaging them. To introduce a simple visual feedback, I went for a color change.
It's naturally emerging (partially because it's something I had in the back of my head, partially because I try to not introduce too many colors) that there are two kinds of energy, the player's health (cyan) and the enemies' (magenta), which acts as mana for the player.
So, it makes sense that when the enemies are leeching the player's health, they turn to cyan.
Of course, I also added the code to increase the player mana when they destroy an enemy.
I'm keeping things super simple and it's paying off because I'm seeing progress fairly quickly.
To make testing easier, I also implemented a minimal game state handling, which simply does this
if there's no enemy alive, spawn the next wave (increasing number and speed of enemies)
if the player is dead (
health == 0
), reset to the initial state
Basically, an endless survival mode with automatic restart on game over.
The next logical step is letting the player make good use of the mana. Tomorrow, I'll take care of that and hopefully I'll also add some other sound effects related to the gain/loss of health and mana.