Skip to main content
GameDev.net gamedev.net
🔒 Locked

Simple 2D Game Architecture

Started by Noegddgeon Sep 17, 2009 at 1:48 PM 14 replies 4k views
Original Post
Noegddgeon
Noegddgeon
Hello, everybody. Are there any resources out there which can show me the general, theoretical architecture behind a simple 2D game which would be portable across all 2D games? For example, I'm taking into consideration making my first game a maze where you control a dot and can move in tile-based increments. So, a rough idea I would have for this would be something as follows (and I'm speaking from limited programming experience, but I'm trying to learn video game theory and programming simultaneously when I can): --Render maze --Render dot actor --Receive inputs --Calculate inputs --If dot touches wall, do not move, else: --Move dot accordingly --If dot is on target, display victory dialog, else repeat To me, that makes a lot of sense, but I'm wondering if there are more (possibly many) other steps involved in insuring that the game runs probably, without going into too much technical detail, though that I'd appreciate too considering that programming requires knowledge of everything to be done properly. Thanks in advance, this is probably the first real game programming step for me. :]
Bacon and Eggs
Bacon and Eggs
Looks okay.

But I like to do all of my logic first and resolve all the variables before displaying anything. So, if you had a clipping step where you removed off screen artifacts it would be done after the logic of positioning your character/dot (especially if the virtual camera follows your character) and before the rendering.

So your list of items to do is good, it's just out of the typical order that I would do the functions at.
Noegddgeon
Noegddgeon
Bacon and Eggs,

What exactly do you mean by off-screen artifacts?
iliak
iliak
Hi

Here's the basic steps for a "game" loop :

Loadcontent() : Load everything your game need (graphics, audio, data...)~~~~~~~~~~~Update() : - Check for inputs (keyboard, gamepad, mouse, network...)~~~~~~     - Game logic (--If dot touches wall, do not move, else:                         --Move dot accordingly                         --If dot is on target, display victory dialog, else repeat                         --....)Draw() : Visual output of your game (draw player, monsters, background, score...)~~~~UnloadContent() : When you are over, free all allocated resources~~~~~~~~~~~~~

With this logic you can do (almost) all kind of game. To have a *full* game logic, you need introduction, main menu, gameand high score screens. Maybe more, like losing, winning, and option screens.
Look at the above code and you have a basic screen manager there.

You can download my starter kit for my 2d game framework here.
- Iliak -
[ ArcEngine: An open source .Net gaming framework ]
[ Dungeon Eye: An open source remake of Eye of the Beholder II ]
Noegddgeon
Noegddgeon
Iliak,

Thanks for the reply. I guess I was in the right direction. ;] I understand there's a lot I have to learn, but it's exciting.

Is your framework cross-platform?
iliak
iliak
It would... short answer :)

A little bit longer answer would be : yes it would. I'm using OpenTK for OpenGL rendering and this library is cross-platform. So, it's a good start. But, I'm using some specific win32 dll. Nothing one can't change to be cross-platform, but it's not my main goal.
- Iliak -
[ ArcEngine: An open source .Net gaming framework ]
[ Dungeon Eye: An open source remake of Eye of the Beholder II ]
Noegddgeon
Noegddgeon
Yeah, so it probably wouldn't work on my Mac... :/
iliak
iliak
Right now out of the box, no. But maybe later, yes
- Iliak -
[ ArcEngine: An open source .Net gaming framework ]
[ Dungeon Eye: An open source remake of Eye of the Beholder II ]
Kada
Kada
Is this the book you are referring to?

http://www.amazon.com/Advanced-Game-Development-Jonathan-Harbour/dp/1598633422/ref=sr_1_1?ie=UTF8&s=books&qid=1253704406&sr=8-1

I have found Advanced 2D Game Development, but not Advanced 2D Game Programming.

I assume this is what you meant, though.

Noegddgeon
Noegddgeon
Kada,

That book looks really good but it's based on DirectX, which I can't use because I'm working with Mac OS X. I think I'm going to purchase a PC at some point solely for game development, but that will probably be a ways down the road once I'm proficient with Java and C++ with cross-platform libraries. Actually I'll probably want to get good with OpenGL first, as well. Who knows, maybe I won't have to get a PC anyway. DirectX is just another tool, though more widespread than many others, but simply that, nonetheless. Oh well, I'll learn just about anything, I'm not too picky. :] Thanks for the suggestion.
iliak
iliak
Try OpenTK. As it's written on the box "an advanced, cross-platform wrapper for OpenGL, OpenAL and OpenCL. Written in C#, it runs on Windows, Linux and Mac OS X and can be used by every .Net language."
- Iliak -
[ ArcEngine: An open source .Net gaming framework ]
[ Dungeon Eye: An open source remake of Eye of the Beholder II ]
Noegddgeon
Noegddgeon
lol Sadly I don't even have Snow Leopard yet, just Leopard still :p But at some point I'll probably want to get OpenCL and OpenTK when I progress to 3D. Thanks for the referral. :]
Exomoto
Exomoto
Just a note, you should check if your dot is colliding with anything after each button press, that way if the user presses right and down to move diagonally, and hits a wall, they'll still slide along it in the open direction.

Also, don't worry too much about the game structure initially, just focus on building the game first, and then find any useful sections of code (collision, input, audio, etc) and refactor them until they can be used in other projects. If you focus too much on making a shiny engine you'll find that a lot of the very nicely written functionality you've added doesn't really apply to the game you want to make.
Noegddgeon
Noegddgeon
Quote:
Original post by Exomoto
Just a note, you should check if your dot is colliding with anything after each button press, that way if the user presses right and down to move diagonally, and hits a wall, they'll still slide along it in the open direction.

Also, don't worry too much about the game structure initially, just focus on building the game first, and then find any useful sections of code (collision, input, audio, etc) and refactor them until they can be used in other projects. If you focus too much on making a shiny engine you'll find that a lot of the very nicely written functionality you've added doesn't really apply to the game you want to make.


That's an interesting point, never really thought about that. I of course don't want to spend any more time than I need to create a game engine, since I just want to see my games finished, but that doesn't mean I want to spend my time creating a slipshod game engine. I think I need to find the perfect balance between functionality and completion.
Exomoto
Exomoto
Quote:
Original post by Noegddgeon
That's an interesting point, never really thought about that. I of course don't want to spend any more time than I need to create a game engine, since I just want to see my games finished, but that doesn't mean I want to spend my time creating a slipshod game engine. I think I need to find the perfect balance between functionality and completion.


The problem is, if you haven't made many games before, you can't really build a nice tidy feature into a game without knowing what exactly it will need to do. Try hacking in features any old way, as messy as you like, just as long as they're working, refactor them a few times until you're satisfied with the balance, and then move on.

To be honest, you'll find that a lot of code you write now, however tidy, will look awful in 6 months anyway.
Noegddgeon
Noegddgeon
Quote:
Original post by Exomoto
The problem is, if you haven't made many games before, you can't really build a nice tidy feature into a game without knowing what exactly it will need to do. Try hacking in features any old way, as messy as you like, just as long as they're working, refactor them a few times until you're satisfied with the balance, and then move on.

To be honest, you'll find that a lot of code you write now, however tidy, will look awful in 6 months anyway.


Yeah I figured that's how the process would go. I'm just excited to get to that point haha it's gonna be a lot of hard work but the most difficult things to accomplish hold the highest rewards, depending on one's mindset. :]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.