Problem: Spaghetti (Code)


Reported By: David Tarnowski

October 30th, 2023

Figure A. Not your mom's spaghetti

THE PROBLEM

As we navigated the complex maze of game development, we stumbled upon a codebase conundrum that was anything but trivial. Our state scripts, once a well-oiled machine, began to show signs of chaos. The intricate web of logic started to snarl, leading to erratic enemy behaviors and intermittent functional glitches (FIGURE A). Moreover, the redundancy of nearly identical scripts for different enemy types was becoming a source of inefficiency and confusion.

THE SOLUTION

Figure B. So fresh. So clean.

Our path to clarity began with a meticulous restructuring of our class scripts. We introduced a parent class for each state, letting unique behaviors manifest in child scripts. This not only eliminated redundancy but also gave us the agility to implement diverse enemy actions with minimal code manipulation.


Figure C. We're all moving towards virtual anyways. Right?

Yet, the heart of our refactoring lay in a seemingly simple change—relocating the labyrinthine 'if' check conditionals into independent functions (FIGURE B). This design decision had profound implications. By isolating conditions and results, the new architecture offered a cleaner, clearer view of each state's logic. Additionally, it opened the door to overridable functions, allowing for easy customization without tampering with the core logic (Figure C).

Through this endeavor, we've not only streamlined our code but also set a foundation for more robust and versatile enemy behaviors. This recent overhaul stands as a reminder of our relentless pursuit for perfection and innovation. And as always, our commitment is to you, the player, to offer an unrivaled gameplay experience that leaves you on the edge of your seat, in awe and wonder.

Stay tuned for more insights and thrilling updates on our game development odyssey!

Thank you for your continued support!

Get Psyche

Leave a comment

Log in with itch.io to leave a comment.