In many of my software engineering courses in college there’s a lot of talk of writing  good software. You’re supposed to write up documents of how the software will work, and know how all the different parts interact. Before you even start writing the software you should have a design that makes sense.

There’s nothing like doing things the wrong way, to teach you the importance of doing things the right way. Although I’m not really writing any code exactly, the same rules about good design still apply. GameMaker does have a scripting language, but I’m not using it too much cause it has a number of powerful features that don’t require any scripting.

So for an example of some bad design decisions on my part I’ll give a quick example. In GameMaker there are a number of different objects(what GameMaker refers to as objects would be equivalent to classes in object oriented programming, and what GameMaker calls instances of objects are equivalent to objects in object oriented programming, and it is helpful to think of them as such). So we have 2 objects, a bullet and an enemy. When they collide we want 2 things to happen, the bullet gets destroyed and the enemy takes a certain amount of damage.

There are two ways to trigger this event, we can put a collision event with the enemy in the bullet object, or we can put a collision event with the bullet in enemy class. I’m sure there are pros and cons to both methods, but the worst thing to do, is what I did. I did both ways. The bullet contains collision events for some enemies, and some enemies contain collision events for bullets. This problem gets even worse as I added more types of bullets, and even more enemies.

As it turns out GameMaker has inheritance, which basically means I can make an object with certain events, like for example collision with bullet causes it to take damage, and I only have to make it once and other objects can inherit it. There were two tutorials that came with GameMaker neither of which explained how to use inheritance in GameMaker, but some online sources explained how to do it, and it will make things a lot easier in the future.

Another problem with my design, is coupling between two objects. Coupling is when two classes or, as GameMaker calls them, objects are closely tied together that one can’t function properly without the other. Depending on the situation you might merge them into on class, redesign the two classes to be less dependent, or it might be acceptable to leave it the way it is(or so I’m told). The two things I had closely coupled where the Player and the HUD that displays his stats and stuff on the screen.

First of all, health is a global variable in GameMaker. If I wanted I could make my own variable representing health and put it in the player class, but I didn’t, both the HUD and the player access the health variable. When the player gets hit he lowers the health, and the HUD displays health on the screen.What happens when the health reaches 0? The HUD has an event to kill the player and restart the game. Why is it in the HUD and not the player class, not sure, and I don’t think its a big deal either way, a much worse problem comes up later.

GameMaker has a little check box that lets you make an object persistent. What that means is that when you go to a new room, the player and HUD will still be there, even though everything else that was in the room will be gone. To proceed through the game the player needs to collect items and these items will be tracked with variables. Where are these variables stored? Well this is really the problem, I’ve got a whole mess of variables that should either be in the player class, or maybe in they’re own class, and they are split, some are in the player class and some are in the HUD.

It didn’t matter a lot to me since the player and HUD were both persistent, and that was what was most important. I needed the variables to be there all the time. Now it seems pretty foolish and there needs to be a redesign in order to keep this project manageable.

And that’s pretty much all I have to say about that. Go ahead and leave comments on how foolish I am.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s