Game Structure

Before I begin I would like to say that this is a very broad question , so I’d be happy with a very broad answer.

How do I structure a 2D Java Game? Like the object hierarchy. Putting all my knowledge of my game programming together to create a game has been really difficult for me. How do you plan out your games when making them.

Well i may not be the best for this but here goes nothing

so u have it look like this:

JFrame
|
Canvas
|
GameStateManager
|
States
|
Objects

in the JFrame u just make a simple JFrame and add the Canvas to that. In the canvas you make it extends Canvas(duhh) and implement runnable because ur main game loop will be in there. Now in you canvas your going to want a gamestatemanager object so that in each method (draw, tick, keyPressed, keyREleased etc.) you will just put gsm. (Assuming you named ur object gsm) now in your game state manager you going to need and array list holding all your states and in the constructor add those states to your array list… now in each method inside the gamestatemanager (draw, tick, etc.) just put states.get(currentState). (assuming u named your array list states) now you got the basic structure set up! now make your states like menu and play. in you play class (where the game would take place) you would then draw and tick all your objects (That would flow all the way down the line back to the canvas) so in your objects is where the game takes place, and all the other stuff just links them all together.

Srry for the wall of txting language text but i hope this helped ^.^ (Also this might not be the most efficent way of handling this but this is how i do it)

P.S. Next time you have a question post it in the Newbie section… you will get more responses wayyyy faster

Don’t assume anything when you have only been on this forum for less than a few days. He would not have gotten a faster reply, we are a tight knit community that answers questions regardless of experience or board.

srry about the assumption but it appeared to me tht he had went 70 minutes with out a single reply and when id post to the newbie section id get a reply within minutes so i just wanted to help a brother out. Also i even look in the newbie section first just to find question tht i could answer so from my short experiences so far thats the best place for questions

I don’t check boards, I just click unread posts since epoch (which is what most do, I think). Also, your first answer is probably too specific; you should answer with concepts not the exact way you do it in your game.

haha i just realized tht button exists… ill have to start using that… also i had no other way i could explain it… there is no method to my madness its just how all the tutorials i’ve watched or read (there have been many) have told me how to do it… he also said he was fine with a broad answer but tht doesnt mean he doesnt want a precise one

I stopped doing that for a while because I was afraid of the backlog I would find. Finally got the courage to clear it. 65 pages. :o

Recently I’ve found that making a design document works quite well for me. The difficult part is when to stop adding further details, this is something best learned through experience, IMHO.

Here’s what I put in:

  • overview / summary: describe in a couple of lines what the game is like, what the main challenges for the player are and what makes it fun and unique
  • story: an overview of the storyline / progression through the game
  • screens: short description of each screen in the game (incl. a mockup, short description and transitions between screens)
  • game concepts & mechanics: the core gameplay mechanics and important concepts, in as much detail as I can manage
  • assets: art style, sound effects, music description, and how to obtain them
  • technology: what platforms to deploy on, libraries to use
  • development plan: global planning of when to do what

This is not that different from a project plan for any different kind of project, e.g. a research or software development plan.

Coming up with a consistent and detailed set of game concepts & mechanics is the most difficult part for me: its so easy to skip over some ‘unimportant details’ only to realise later these ‘details’ are actually huge issues that need to be overcome or force you to rethink pretty much everything.

Structuring an object hierarcy: what usually works for me is to start with the most encompassing object type (e.g. a World or Galaxy) and place less encompassing object types as children under it. E.g.:

  • Galaxy

    • List of Star
    • List of Ship
  • Star

    • Position
    • List of Planet
  • Planet

    • Surface image
    • Orbital range
    • List of Building

… etcetera

drawing up designs is a satisfying and exciting part of game making. you can take your ideas where ever they flow without having to work out how to make everything work untill afterwards.