As I may stated before, writing an efficient game engine is a hard task, While you are working with a small number of files, with non-dynamic content, everything works fine. You show this sprite there, handle it easily, show some tiles, this engine is a so called test-engine, it can be tested immediately. Some of my games are based on such test-engines, as for example a tetris(-attack) clone. You don't really need much for programming such game. However, once you try to make a game engine more flexible, problems appear: your engine is not ready to handle dynamic content efficiently without giving yourself a headache, as you have to handle much more things in a completely different way as you did before, and that means usually if you haven't planned your engine before blindly writing code, you are going to fail.
That also appears to be the problem with every object-oriented project I start. I just simply write code and write whatever I think, so there's a big mess and this makes my code so miserably, I fear to show it to anyone, as I would have to explain too much why I did that and that. Writing the engine for Galaxy Stations for example cost me a lot of work, as I had to rewrite the whole engine six times!
At least now I learned to plan every code I write beforehand, but even here I discovered different methods that helped me design my code:
- Using a flowchart. Writing the classes as boxes is nice, as you can see the flow of your code visually, and also see where your problems in the code are. While drawing flowcharts, I'd recommend to use a whiteboard or a computer, as erasing and editing is much easier. Stay away from paper!
- Using a list. It's very similar to a flowchart, but different nonetheless. While writing a list you just go from a point in the code, and write what the code should do in a row. Yap, it's a simple algorithm, but it seriously helps you to find where and how to use classes. I use the paper+pencil approach here, as it doesn't require anything too hardcore.
- A mixed approach. Write lists and flowcharts! The best of all three, as you plan where you can, and then convert it into easily maintainable code. Use it when you really need to spend time with your project.
(That game in the screenshot is made by me for mobiles. Contact me if you want the jar file)

0 comments:
Post a Comment