Enemy Collisions / TypesWhat I've been focusing on this week is reviewing the way that collisions work when enemies and objects collide with each other, improving the behaviour, and cleaning up the code that handles it. (I will just refer to "enemies" for the rest of this post but the same rules apply to other interactive object like coconuts too).
I've been setting up little test areas to help with testing this stuff, which is really helpful!
This area tests some enemies of different types by using the springs to roll them into other enemies.
Enemies in the game have a concept of "armour" which is basically their collision type. Enemies can have different armour on their top, bottom, front, and back, although all the current enemies have the same armour all over. Armour has two properties which change the behaviour.
- Soft or hard: hard armour causes a rolling enemy to reflect off walls rather than squashing against them and dying. If two hard enemies roll into each other then they will both reflect off each other. The coconut and spiky ball are examples of hard enemies. I've added a new particle effect to indicate when this 'reflect' type of collision occurs.
- Spiky or not spiky: Spiky armour hurts Leilani if she touches it. For example - you guessed it - the spiky ball.
There are some exceptions to the cases where hard-armoured enemies will reflect off walls that they roll into. For example, the big watermelon has hard armour, but it smashes into bits when it hits a wall.
The major change here from previous behaviour is that spiky armour only hurts leilani, and no longer hurts other enemies. It's just simpler and allows the player to more easily predict enemy interactions when there are a few enemies rolling around.
At the moment enemies can still be hurt by environmental spikes - I haven't made a decision yet on whether to change that or not. I'm leaning towards changing it as it'll make the behaviour of spikes consistent regardless of whether they're spikes on enemies or spikes in the environment.
Enemies also have a weight class. The big watermelon in the above example is a heavy object. This causes a bit of screen shake, as well as allowing the heavier enemy to crush any smaller enemy that it rolls into or lands on top of.
(Leilani disappears for a while because her sprite is flashing, and the low FPS of the gif just happens to keep missing the sprite.)
In this room I was tweaking the collisions to allow a large number of objects to eventually come to rest. Previously every time the objects touched each other they would magically a gain velocity and they would bounce around for a long time, or forever.
This isn't a realistic situation, the game will never have this many objects lying around in one place, but it's good to push the code a bit. Notice that I put in a bit of a hack - if two objects have exactly zero X velocity and are bouncing on top of each other then it'll push one of them to the left, and one to the right. That will rarely happen during normal gameplay but just helps to prevent weird situations with objects bouncing on top of each other forever.
I'm starting to feel happier with how these collisions work, which has been through a number of revisions over the last couple of years. It's good to get these core systems nailed down finally.
Please make it so when you press a key she fires out of the volcano and we slow pan around to the first level with her landing.
I was currently just thinking she would be lazing around in a hammock at the start of the game. Not flashy enough for you?
The volcano will be the final world of the game so would unfortunately be a bit weird if Leilani started there.