Simplifying your game engine for better expanding and optimization

Hello everyone, I’m new to this course but I have thought of a way to cut half the code and make editing your story and extending it easier.

The process:

In the course, you make multiple enum states, for example. “lock_0, lock_1…”

Now if you have different stages in the game, like one where you have the key to the door and one where you don’t, you need to have mutliple states like _0 and _1 right?

Each state takes up a void and that is a large amount of code that is copied and makes the code longer, doing my method makes the game run faster.

All you have to do, is simply add a private int called stageNumber and default it to 1, this will tell you what part of the game you are in, I.E, if you have the key in the cell, or if you are escaping the hallway, and so on and so on. Different parts of the game. You might think of adding different enums, but that still means you need to make double voids and so on. When you are making your void for the state where you pickup the key, you set stageNumber to 2 on that same if statement, that way it progresses the game forward, and in your code, simply make different paths based off of which stage of the game.

To do this you just add in, and stageNumber == 2 or stageNumber == 3 and have two sets in the same void for which state of the game.

This cuts down half of the code, makes the game run faster and is a lot easier to read.
Thanks for reading.

1 Like

Can you show us your code?

I’d like to see your code as well. If this works, it would have saved me a lot of effort.

Privacy & Terms