In this episode I introduce quite a few new things, including damage and health, game states with GameplayKit, fragment shader with SpriteKit and I also refactored many parts of the code using more elegant Swift functionality.
I spent quite a lot of time to implement game states which makes quite a difference as it becomes more of a complete game than just a prototype level as previously. With game states the game now have
- A game over state when the player runs out of lives.
- A level completed state. That also comes with switching to a new level after completion.
- A game completed state.
- And also a respawn state for the player craft when all health is gone.
- A state for being at the home screen / main menu.
- And a pause state.
Damage and Health
Every entity can now use a health component and a damage component to track a their health property, so they don't just immediately die when they are hit. The damage property determines how much damage an entity deals. That allows for having different strengths for different bullet types.
As the codebase keeps growing in complexity, I've started documenting the inner workings in a diagram. This has turned out to be really helpful to quickly recollect how things are set up. Highly recommended.
I implemented a fragment shader to handle color changes when entities gets hit. As SpriteKit's own color blend is multiply based it can not flash to white, which I wanted. With a custom shader it now works as I expect it to work.
The game also have moved on from working title to a final title. LunaX Engine is the name of the game.
This is the 10th episode of my devlog following the progress of my indie game, which is a top down shoot'em up, that I am coding in Swift on top of the SpriteKit and GameplayKit frameworks.