Work is coming along nicely. I’ve been mainly focused on the hud, which is of importance to testing the power-ups. I’ve also implemented some power-ups.
The hud is displayed on the left side and shows player information like health, lives, score and power-ups.
In this post I want to explain how I further Swiftified the source code, this time by adopting a more functional style of programming.
When the timer expires, the monsters enrage. At this moment the enrage is just a movement speed increase on the monsters.
The original code for enraging monsters looked like the following:
To Swiftify the source code, we can use the
forEach functions when processing collections:
Another situation where I adopted this functional style would be when activating power-ups. Initially the code looked like this:
The functional approach is as follows:
It’s certainly more concise and I can appreciate that.
At the moment I wonder what the benefits and downsides of this approach are. The Swiftified code might be slightly harder to debug, as breakpoints might not work as well. I do think the Swiftified source code is nicer to read though.