It is high time to put some moving opponents in the game. And the first candidate is a simple critter, an animal that is trapped in the dungeon and will attack you on sight. This certainly is not a hack and slash game where you will have to defeat every opponent. But the fact that you must fight some opponents will make those that you cannot win from more scary.
My first critter is the wild dog. It will home in on you and inflict a single HP damage when it hits you. After a charge it will flee from you for a certain cool down period, and after this it will charge you again. Thanks to the default building blocks of the JGame package, most of the ‘home in’ and ‘flee’ behavior was already provided, so I could focus on graphics and animations. And soon the wild dog was tearing me apart as soon as the game started.
So I immediately had the urge to defend myself. What is the weapon of choice for our stalwart hero? A broadsword maybe? Or a stylish katana? Yes, you guessed it: since this is a horror game with a mining theme, you get to defend yourself with rocks. (Maybe I’ll throw in a pick axe in the future if I feel generous.) So I rewrote the light stones to become thrown rocks. Also simple with JGame. It was only when I worked on the interaction between the rocks and the wild dog that I had to -for the first time- really understand how JGame handles collisions. And for all its greatness, there is still something to be desired in variable naming in the code of the JGame engine…
Anyway, after that the fun part ensued with deciding how the critters would react to damage. I immediately decided that critters are not suicidal and will have several thresholds of damage to manage their behavior. Up until a certain amount of damage they just keep attacking. After that they will flee away. If you manage to do more damage their speed will gradually decrease until they collapse. Even then they are not dead, you have to consciously add a fair amount of extra damage to a collapsed animal to kill it. That should reduce the ‘arcade’ feel of the combat a fair bit.
One of the JGame tricks I relied upon previously is that it is trivial to place a text on the screen and have it slowly move in some direction, and optionally cycle through colors. I use this as a cheap alternate to animation effects, so I tried to find a text that would best convey that you had hit the dog. I experimented a little and found that an almost trivial approach works wonders. Instead of stating the amount of damage done, I just render a red dot that slowly moves down and quickly disappears. This dot becomes a blood splatter that shows you the impact of your rock.
Now comes the tricky part. Since JGame does not natively support lighting, the critter always renders at maximal light intensity (and does not have to good decency to not render when the player cannot see you) completely ruining the realism. So I had to think of a way to link the line-of-sight and light intensity to the rendering of the image of the animal. And here it greatly helped to ponder the problem for a while without actually touching a keyboard. A few days and trip to the Dolfinarium later I had unconsciously put it all together. I had to introduce a new entity that would represent all non-tile things in the game that appear in a cave. I named it the Sprite inspired by my C64 youth. My good programming habits paid off, and I already had all the hooks in place that I needed to link sprites to the tiles of the map and in one evening I had sprites that changed light intensity with the tiles they inhabited. Voila presto!