Refactoring
Or; "Time to throw out all that hard work and rewrite it"
This narrative is a work of fiction, mostly based on true stories.
Let's say you want to make a top-down roguelike. So you have some character and monster sprites, some item bitmaps, and some spell sprites. You even have animations.
So, you wire up some code. Move the player's character left when the player presses '4' on the numpad, up and left on '7' on the numpad, generate some random numbers influenced by stats and items when the PC hits a monster (and vice-versa), reduce health and make dead as appropriate, and wands cast spells. You websearch dungeon generation, and presto, our little dude is running around killing monsters. It's all good, and you're exhausted.
Then you hand it to some friends to playtest it, with an eager sense of anticipation.
One friend is on a terrible laptop that doesn't have a numpad. Another is missing a library you thought came standard on that operating system (let's hope the error message is helpful, there). Yet another is on a different OS. Another comments that the game is "way to easy, you just <insert strategy(ies) here> and the monsters <insert how they become way too easy to kill>." And they want multiplayer. And the last complains about lack of sound.
So you add sound. You research flocking behaviour (it's game "AI" code designed around how birds move and avoid each other. Fairly common to manage swarms of enemies) so your AI has some semblance of tactics. You find a replacement library that you can legally include at least an installer for, or find you can legally include an installer for your current library. (good luck)
You add alternate movement using the arrow keys and the right side of the keyboard (and re-assign some of the controls).
You look into porting to a different OS, which is when you either find out that your current code is pretty much tied to your current OS like a ball of yarn. Or, these days, that you can just build a version for that OS, because you're using a modern, widespread game engine (problem solved!)
You look into adding multiplayer, and run headfirst into something called "MVP", or Model-View-Presentation (or one of its offshoots, derivatives, or cousins), which everyone says is the best set of ideas for making your game multiplayer. Except you'd have to re-write half your game around this. So you regretfully include a notice that the game is "singleplayer only".
You hand it off to your friends to playtest test it, this time with a sense of not-that-vague dread.
Your friend on the terrible laptop notes that one of the keys you re-assigned doesn't work on their laptop, and asks "Why don't you just include a control panel so you can re-assign keys?" (with the implicit assumption that this will be easy. MVP or event-based would help there, people tell you)
Your next friend says the game is "fun, but lacking in story." The one after that complains that your game's installer tried to run an installer for a library for a different OS, not the version that works on their OS. The next friend gives a five-page essay analyzing your game to the smallest detail (you will grow to love this friend. Just, possibly not right now). The one after that comments that "Eh, pretty good. I'm gonna play some <insert much more popular game that your soundtrack reminds them of>."
At this point, it is advisable to stay off FriendFace and away from the "unfriend" button.
Also at this point, you have researched enough new information about programming in the course of everything else that your code now looks horrible. To you. And you can see how MVP, component design, and other patterns could make your game much more flexible
So you sigh, metaphorically (or literally) roll up your sleeves, start Project 2, and half-way through, kick yourself for just learning about version control now.
Because your code seemed easy beautiful and could do everything...If only you could finish it. Except you have so many abstractions, and everything is split into so many small bits, that you have no idea what anything does, and you could literally assign the colour blue to the sound of a random rock wall yodelling... If you could remember how. And people are telling you to "design first". It's at this point you realize what "Your code is trying to do too much" means.
Some time through Project 3.0, it's all coming together, but your energy level resembles that of a zombie (and not one of those modern fast zombies that are not actually zombies).
And that's when you find a time travel machine, and find yourself agreeing with that oddly haggard-looking fellow who sort of resembled you, who walked up to you on the street a year ago, and, without saying anything, promptly kicked you in the shin, then walked off.
No comments:
Post a Comment