Sign in to follow this  
buumchakalaka

Good habits for game development

Recommended Posts

MaelmDev    198

Try to work out what features you want to implement before anything else.  Start with general ideas and work your way down to specific features and requirements.  Once you have all of your features in a list, you can start to design your architecture to implement these features, making sure to find solutions to dependencies between them. (this can be the hardest part!)

 

Don't bother with any pseudo-code after you've finished the architecture, as you've got all the elements needed to begin coding the actual game.  When you do this, make sure to always write code that doesn't depend on a feature you haven't implemented yet.  This should help you keep your game testable and cut down the amount of coding you need to do in between new builds, which will keep you motivated.

Share this post


Link to post
Share on other sites
DekuTree64    1168

Lots of good points in the previous posts. I'll second the point of designing ahead of the code. Don't implement any features you don't really need, and know what you do need before you start implementing stuff :) A 100% detailed design upfront would be nice, but not usually possible. But you at least need an overall game design, and a decent amount of full detailed stuff plotted out before you get coding.

 

For example, you might have a few levels planned out for a side scroller, with various platform and enemy types in them. Once you code all that up, you have all those components to mix and match in new, not-pre-planned levels, and maybe think of ideas for some more things to add. But you need those first levels designed before you start coding, or you risk falling into the trap of "engine" coding, which often results in lots of those unnecessary features :)

 

Also, use a coding style appropriate to the complexity of the game. Full C++/OO/RAII/smart pointer style is great for most things, but maybe a little overboard for Pac Man. If your game is similar to something done on SNES or earlier, chances are it was written in assembly with little if any heap allocation (usually using statically allocated pools for things that are dynamic in nature, but have a maximum number that can be on screen at a given time), and probably wouldn't run into many difficulties coding it in C.

 

And when commenting code, don't go overboard. Usually it will do to give a quick plain-English overview of what a function is trying to accomplish, or a block of code in longer functions. Only comment line by line if you're doing something particularly confusing, such as highly optimized code.

 

Quality content creation is time consuming. Background graphics, animations, sound effects, music, level design. But don't involve other people in your project until you have the design worked out well enough that a) they'll have something moving around on screen soon, and b) you're relatively confident that the project is not going to fizzle out due to excessive complexity or simply not being as much fun to play as you thought it would.

 

Be aware that 50% of the production time is finishing the last 10% of the game. If it doesn't look "almost done", you've got a long way to go :) But sometimes the transition from looking like a bunch of separate components into being a cohesive whole game can happen pretty much overnight.

Share this post


Link to post
Share on other sites
DpakoH    1204

i want to add that during development keep in mind that at some point you will need some debug information displayed in the game. a really simple example: mouse coordinates (screen vs world), number of textures, number of vertices, state of an agent and so on, and so on. so when you think about the structure of the code, think about that too.

Share this post


Link to post
Share on other sites
LorenzoGatti    4443

If you want to design your game (or more precisely your game engine) up front, before coding something wrong and useless, elaborate your requirements in detail: there are features you really need, features which are likely to be useful, with vastly different priorities, and features you don't need.

Apart from discovering important decisions and complications early in the process to adjust your game design towards feasible objectives, knowing what you want is necessary in the choice of libraries, data structures, algorithms, contrasting architectures.

Share this post


Link to post
Share on other sites
rpiller    839

I think an object oriented language is the way to go for organization and maintenance (not speed though but it's fast enough for 99% of the code).

 

- Encapsulate as much as you can. I end up re-factoring my code all the time. To think you'll get it right the first time every time, or that you won't change your mind is silly, and the more you have things encapsulated the easier it'll be to re-factor things around without breaking the things that rely on the code. It also allows for experimenting with new ideas without breaking existing code. Even if you think something is small, encapsulate it because chances are you'll come back and make it more complex eventually and doing this can really make your life easier later.

 

- Make self containing code as much as possible. The more your code relies on each other the harder it'll be to make changes without breaking a bunch of stuff. This again allows for easier changes that don't break as much code if any. I like using event programming for this so that my objects fire events and other objects can subscribe to these events if they want. This way my objects aren't tightly coupled together (ie the HUD object doesn't need to directly know about the Player object), and don't rely on polling systems which waste time.

 

- Always make sure your code compiles each day that you are done with it. Don't leave compile errors overnight. Logical errors are OK to leave, but be sure to note them.

 

- I'll contradict Servant's comment and say, never use goto, global's, or macro's. In my 15 years of programming I've never used goto outside of first learning it. It's simply not needed. Globals took longer for me to realize their danger but eventually I have seen the harm they cause and haven't used one myself (libraries you use might) for probably the last 8 years. Stick to a singleton if you need something like a global. Macro's start out making your code easier and then you start abusing them and they actually end up making your code harder to read & maintain. 

 

- The biggest thing I think is to make your functions small! They should be visible on about 1 "screen". Any bigger than that and it's most likely doing too much and should be split. It will also be harder to maintain than a small specific function. This is important, as it's all to common to see new programmers putting so many things into giant functions. Don't do it! This is worth repeating. Practice doing this until it's second nature. This is a big one.

Edited by rpiller

Share this post


Link to post
Share on other sites
Krohm    5030

Source control. I cannot describe the peace of mind it brings.

Design the game first! Code is a thing but the game has certain things it needs to do. There are no "features you want to implement" but rather features the game needs to run (technically those would be the aforementioned requirements). Anything else should not be there... unless it brings you cleaner, safer code to manage without running out of sanity.

Share this post


Link to post
Share on other sites
HappyCoder    5052

One thing that helps me get things done is having a deadline. Preferably a deadline that you cannot push back like for a contest. When you have a deadline it helps you keeps your project simple and cut out unnecessary features so the focus becomes finishing the game rather than trying to see how many awesome features can make it into the game. Even if you cannot find a contest or other hard deadline still try to set out a realistic timeline for yourself and follow it. If you find your initial estimates weren't accurate adjust them. But break up your project into smaller pieces and tackle one piece at a time.

Share this post


Link to post
Share on other sites
sednihp    241
For C++, I'd recommend reading C++ Coding Standards by Sutter and Alexandrescu. The table of contents by itself is helpful, but the full book contains discussion like reasoning and exceptions to the general rules. The only problem is that it predates C++11.

 

I just came across this the other day. Scott Meyers' range of Effective C++ books are also a great read on best practices

Share this post


Link to post
Share on other sites
rpiller    839

@jbadams

 

I stand by the small section of my comment you decided to quote. IF one wants to go the global route, use a singleton because it offers more benefits than a pure global. You may not think those benefits are worth anything but I do. Benefits in refactoring at a later date to actually be a normal object, better organization & structure, encapsulation, etc. A singleton is clearly better than a global because it's wrapped up in a neat little class and you get the benefits that classes get. Because that allows for more flexibility and organization than a loose global variable. Yes, they have the same scope, but one adds more benefits than the other, does it not?

 

I don't get belittling the benefits of what a class offers and clearly " just because it's wrapped up in a fancy class" is belittling what a class offers in it's tone.

Share this post


Link to post
Share on other sites
jwezorek    2663
And in general, what I should consider for become a better game developer and make better games?

 

Finish what you start ... when you start a game, finish it.

 

This leads to a natural corollary, Don't start things that are too big for you to finish.

Edited by jwezorek

Share this post


Link to post
Share on other sites
wfrye2005    452

I have to agree with the comments suggesting source control, even for relatively small hobby projects. I've found it really helps me stay organized--the free online repository site I'm using has a built-in issue tracker, which has been much more useful than my previous system of scribbling down random problems and planned features as I thought about them in a notebook. It encourages you to set specific, incremental goals--and them meet them before moving on to something else.

Edited by TheSasquatch

Share this post


Link to post
Share on other sites
jwezorek    2663

[quote name='TheSasquatch' timestamp='1358625548' post='5023275']
the free online repository site I'm using has a built-in issue tracker
[/quote]

Which free online repository site are you using?

Share this post


Link to post
Share on other sites
wfrye2005    452

the free online repository site I'm using has a built-in issue tracker

 

Which free online repository site are you using?

Didn't want to sound like I was advertising, nor stir up a Git vs. Hg firestorm, so I didn't name names, but I suppose there's no harm in saying Bitbucket. Github probably has similar features, but the deciding factor for me was Bitbucket's unlimited free account for those with a .edu email address. As a broke grad student, I couldn't turn that down.

Share this post


Link to post
Share on other sites
wodinoneeye    1689

Something from writing/fixing others code :

 

If there is some parameter flags that cause variations of behavior of a subroutine - clearly comment this  at the parameter definition and down in the code where trhe different modes take action.  (Im not talking about simple subroutines but ones hundreds and thousands of lines long that it may not be productive to have a variant copy customized for each 'mode'.)

 

Especially if the scope of the differences cause odd side-effects or have important limitations.

 

Document those (if not anything else) becase of the amount of the time/effort it takes to trace thru the code again  to figure out what it does and once you find it (as when fixing other peoples poorly documemnted/commented code)  it can save the effort or repeating the detailed logic tracing.

 

Anything with weird/atypical/convoluted behavior should get priority for comments if there is little time for any done systematically (its just a fact in the real world that you dont always have the resources to do a full commenting/documentation).

 

----

 

 

And when I make many such comments I make them very plainly stand out so that its hard to miss  (indicating that the codes behavior is something to be wary of)

Share this post


Link to post
Share on other sites
l0k0    278

Some general things, most of them independent of coding style:

 

- Have realistic and well defined goals that are clearly communicated to members on your team

- Scope it down: your game idea is probably too damn big.  Polish takes time, things get cut, features don't exist in a bubble (unless the project fails that is).

- Iteration time is everything: Fail early and fail often, prototype mechanics, and be prepared to cut something you invested a considerable amount of time in

- Knowledge is power: profile your code, run tools that check for leaks, crank up compiler warnings, and use static analysis tools if possible

- Interfaces are king: A well designed one is the root of a clear, maintainable, and productive workflow for others.  A poor one will cut into iteration time.

- Understand that hard problems will inevitably contain immensely complex code: elegant systems rarely survive contact with real users

- Embrace time estimates and embrace making time estimates that might be completely wrong.  Do this over and over and over again.

- "Self Documenting Code" is probably only documented to you

- It's (usually) not done until it's data driven

 

 

 

Edited by l0k0

Share this post


Link to post
Share on other sites
SeraphLance    2603

[quote name='wodinoneeye' timestamp='1358779996' post='5023907']


If there is some parameter flags that cause variations of behavior of a subroutine - clearly comment this at the parameter definition and down in the code where trhe different modes take action. (Im not talking about simple subroutines but ones hundreds and thousands of lines long that it may not be productive to have a cariant copy customized for each 'mode'.)
[/quote]

 

I'm going to agree here, on the caveat that youl should avoid writing this kind of code as often as possible in the first place.  Sometimes it's unavoidable, but it's a code smell that should be minimized.  A function should ideally do one thing.  It's not really one of those lofty architecture astronaut ideals 99% of the time either.

Share this post


Link to post
Share on other sites
Plethora    687

Incredibly helpful thread! 

 

Here's my tip... define your goals ahead of time, both for yourself and for the project.  If you're doing it to learn then take every chance to learn.  Try out new approaches to various coding problems even if you're already comfortable of some other way of doing something.  Having more tools at your disposal for the future is what learning is all about.

 

On the other hand, if your primary goal is to create an awesome game and to hell with everything beyond it, then do the opposite of the above.  If you know a way to solve a problem, don't worry about whether or not its the best way or even necessarily a good way, provided it works and it does the job you wish it to do. 

 

In reality, most projects are going to be somewhere between those two extremes.  Learn how to balance the benefits of taking time out of your project to learn something new versus just powering through with what you have understanding that there might be better ways of doing things out there but knowingly declining them for now.

Share this post


Link to post
Share on other sites
HAM    176

For games, especially if you are designing, you are much less an engineer and much more a sculptor, constantly pushing and pulling things around, removing unneeded bits and adding extra bits.  Plan for things to change, 

 

  1. Get a playable version as fast as possible. Even if it all gets thrown away.
    • Prototyping is a design step, a pre-production step.
    • Its going to help in planning and identifying what really needs to be implemented.
  2. Design up front just enough to get a good idea of what you really need.
  3. Implement the minimal amount.
  4. Schedule the minimal amount.
  5. Art and sound and nice assets can wait.  Make things work first.

 

And the last thing is my personal law for programming.  It might sound stupid but it helps in about a million ways.

  • Never write a function longer than 50 lines (including white space and comments).  Decompose. make it fit on a single page.  
Edited by HAM

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this