So I thought I could get the “character” editor for my game (you know, the only one I’m working on like a good developer! See the relevant “squirrel” post previously) up and running quickly. There’s not a lot of options to select from in creating a “character” in the game, so I figured it would be a quick screen to whip up. I should have known better.
Usually, if a chunk of code isn’t that complicated I don’t take the time to make it object-oriented. Why do we use OOP methodologies anyway? For me it comes down to a couple of things:
- Ease of understanding
- Ease of re-use
- Ease of maintenance
- Piecing chunks of code together is usually easier than writing one huge chunk of code (this ties in to the other three somewhat)
For small, uncomplicated screens in a game (which I anticipated this being) usually none of these 4 things are lost if you code the screen in a non-OO manner. Menu screens in most games are a good example. There’s not much going on except detecting the selection of a menu item and moving to the next screen. An option screen isn’t that much harder – you just have to read and write out some data to a file to save the state of the options the player selects.
I wrongly believed the editor screen wouldn’t be much more difficult than a typical options screen. That’s come back to bite me.
The problem is mainly due to handling navigation between all the graphical elements on the screen that the player can select and drawing those elements with the option for each the player has selected. I’ve ended up with a bunch of variables for each object that obviously would be better suited to bundling up in a class and just having a list of each class object. I did this with the in-game level editor and it made it a lot easier. I don’t know why I figured I wouldn’t need it here. Oh, that’s right, I know why – I didn’t plan the screen out before I started coding.
Luckily ripping everything out and making it more OO shouldn’t be much more than a good night’s coding. I am thinking a bit beforehand about how I’ll do it though.
Lesson learned. Hopefully others will benefit from my mistake.