Beginner Question About Game Design

Started by
5 comments, last by BenjaminSergent 12 years, 4 months ago
So, this is something that no one ever seems to talk about in either programming, or game design books/tutorials. (That I've seen anyway.)

I've actually started coding my first real game in python, and I'm wondering... when should I start using multiple files, and what parts of the game should go into their own separate files? I'm assuming it shouldn't all be in one 20 thousand line file. (I mean minecraft has a few hundred, though it's obviously a million times more complex than my game.)

Probably a really stupid nooby question, but I'm really not sure. lol
Advertisement
This older article might help shed some light on the topic, but in general you split it up however makes sense to your project. Depending on the language you could be forced to split at the class-level (Doesn't java require that each class is its own .java file?). But you might break up code into files that match the general sections of the game's functionality. It used to be that the biggest benefit to split files is that you didn't have to recompile your entire project just because you changed one small aspect of a single function, now it might just as well be about saving you time by letting you first search your project by files, then by lines when you find the right file.

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

I will recommend you to study software design pattern. You can split classes into separate files but still get spaghetti-code. You better learn how to design a good structure so later you can add and expand the project easily
NuliNuli admin
nEngine Physics - Quality engine to create AS3 Physics Games
Don't worry, it's very much not a stupid question. There actually arent a ton of materials on the topic. I put together a tutorial that covers this subject but its for C++, so I am not sure how much help it would be for you as a Python programmer. To be frank, even as an experienced programmer, I had some issues structuring my code when it came to Python. For structuring Pythons way, you probably want to read this next.

After that, hunt for as much good code as you can find. This is one of the major downsides to python, lots of the code ive seen has been simply awful, basically just a giant .py file.
Thanks for the links, I'm still having some trouble with it though. So, if anyone has a tutorial on this for python, please let me know.
http://artofgamedesign.com/

This book covers an incredible amount of information regarding game design with the authors own personal touch and experience on each matter and this book is regarded as the best on the subject.

Python is a very clean and very good language to learn scripting/programming with, if you have never done any programming before it is fine to learn with. Please check out the pygame framework here http://pygame.org/news.html. Have a look around on youtube for tutorials using python and pygame to make simple games (there are a few).

I generally have a rule where by I put a single class and all of its methods in a single file and then co-join everything as a package. You can of course use nested classes but there are pro's and cons for this.

Hope this helps.
Please Add Rep if I helped // Working on untitled 2D platformer (more to come soon)
Twitter - @MarkPashby
Your question is more general than game design. I'd recommend reading Clean Code, a book by Robert Martin which covers several aspects of good program design and effective code layout which most other books ignore. In general, small files with small classes and small methods is ideal for making code easy to test, debug and extend. I recall that he specifically recommends in his java example staying under 500 lines per file and trying to keep them around 200 lines

This topic is closed to new replies.

Advertisement