Re: What to do when you feel like you've made a monster?
Reply #5 –
I'll put some of my cents in. I'm not sure if this will be helpful.
The first organization of code that I do is state vs representation. The state says what is currently in the game/battle system, while the representation shows the graphics and sound. The representation parts never modify the state, and are idempotent (running it twice gives the same output both times), and the output is determined by the state. The last required part is the code that updates the state. It only modifies the state based on the current state and user input. In programming speak, this is the model-view-controller idea.
Second, when making a battle system, you have to determine if you need a scripting engine or not. In some cases you do, but most cases not so much. In an engine it's possible to have multiple actions happen at once (for example, multiple people moving at the same time in the default map engine), but there's added complexity with the control flow. An active battle system like FF6, should be in an engine since a monster can attack while the player is in a menu, while a turn based system like Dragon Quest can be done without one. Without an engine, the battle loop goes through the players and enemies running the DoTurn(character) functions until victory or defeat, and the control flow is much easier to follow. In an engine, the engine is constantly running and you're queuing events to happen n units of time later, which breaks the control flow, but is needed. In short engines are asynchronous, so only create one if you need it.
Third, don't be afraid of globals. You're making a game by yourself, it's not a web application. I could give a long speech about what is a global, what is not a global, and what types of globals there are, but in short for this, the rules change according to what the program has to do and how many people are working on it.
Fourth, get a non-moving spec in place for what the battle system has to do before anything else. Once you're fine with what you have to make, start with the most abstract layers and lay them out, and work your way down through the abstraction until you're done.