Jump to content
  • Advertisement
Sign in to follow this  
tecfreak

2D platformer Game Engine

This topic is 2953 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, I'm new to this forum and I think, its the appropriate section for posting my question. I was thinking about making a 2D platformer like mario. My language of choice is Cpp and API is SDL. I have made a few smaller games earlier and this is going to be my first big one. I was wondering how should I design the game engine.
To be more specific,
I thought to make a engine having a cGame/cEngine class which handles everything. A GameState abstract class from which several classes inherit like MenuState, PlayState and the like. Player class which handles everything related to the player. Tile-based map etc.

The question here is: Should every game object class have its own input handling, rendering functions? In this design, all the parameters like the SDL_Event structure and rendering surface (screen) must be passed as arguments to the objects. Also, some class X needs data from class Player, for this purpose too, the player object (or its data) needs to be passed. All this stuff seems like a very bad design to me.

Later, I found another method, which was to make all objects, common structures like event structure global in a separate file, using extern. Then include all this file in whichever class that needs it.

Then, I found Singletons, which seemed superb to me, but still some people recommend against it. This is confusing me a lot.

Final Question: In any approach, how should I design the input handling and rendering system ?
I saw an example where there was a input class with static boolean functions which returned whether the key passed as argument was held or not.
In yet another game, which was quite a big RPG, he had a singleton Graphics class which had all the game art and it loaded everything at the start, then there were several functions like RenderPlayer(); RenderMap(); and so on.. which were called from their respective classes.

I'm totally confused over what to do, please help me.
Hope I made myself clear.

Thanks in advance..

Share this post


Link to post
Share on other sites
Advertisement
Quote:
I was wondering how should I design the game engine.
Don't get too hung up on the idea of making a 'game engine'; instead, just write what's needed for the game (whatever that may be).
Quote:
I thought to make a engine having a cGame/cEngine class which handles everything.
If your goal is an object-oriented design, you might Google/search 'single responsibility principle', as it has some bearing on this.

Also, I suggest not using name prefixes such as 'c' for 'class' and so on.
Quote:
A GameState abstract class from which several classes inherit like MenuState, PlayState and the like.
That's not an uncommon solution, I'm pretty sure.
Quote:
In this design, all the parameters like the SDL_Event structure and rendering surface (screen) must be passed as arguments to the objects. Also, some class X needs data from class Player, for this purpose too, the player object (or its data) needs to be passed. All this stuff seems like a very bad design to me.
It's not bad design, IMO; passing things forward as needed is fairly standard practice for object-oriented software. (For more info, look up 'dependency injection'.)

I think it's fairly common for people to balk at the prospect of having to pass lots of data around like that. However, one of the arguments for doing it that way is that it makes explicit the dependencies within your software. In some cases, this will alert you to excessive or unnecessary dependencies, and can give you an opportunity to reduce the dependencies between modules. Also, you may find that you actually don't have to pass around as much stuff as you thought you would (assuming your individual modules are well-designed).
Quote:
Later, I found another method, which was to make all objects, common structures like event structure global in a separate file, using extern. Then include all this file in whichever class that needs it.
Sure, that would be a more procedural approach, which is also valid. (In general, that approach is probably more workable for projects that are fairly small in scope.)
Quote:
Then, I found Singletons, which seemed superb to me, but still some people recommend against it. This is confusing me a lot.
Forget about singletons. The chances of them being the right solution for whatever you have them in mind for is small (IMO, at least). If you want global access to something, just make it a global.
Quote:
Final Question: In any approach, how should I design the input handling and rendering system ?
I saw an example where there was a input class with static boolean functions which returned whether the key passed as argument was held or not.
In yet another game, which was quite a big RPG, he had a singleton Graphics class which had all the game art and it loaded everything at the start, then there were several functions like RenderPlayer(); RenderMap(); and so on.. which were called from their respective classes.
My own preference is to poll for events in a single location, and then pass them forward to any objects that might be interested in them. That's certainly not the only way to do it though.

Also, I'd suggest not getting too hung up on looking for the 'perfect design'; just come up with something that seems workable, and move ahead.

Share this post


Link to post
Share on other sites
I'm not thinking much about a perfect design. I just wanted to now which was the best approach since something is needed to start.
So, I've decided to follow the second approach making global whatever should be.
The event handling is fine, what do you say about the Graphics class ?
Should I make each class hold its own SDL_Surface structure or should I have a Graphics class which contains all the resources and handles the rendering accordingly?

Share this post


Link to post
Share on other sites
Quote:
Original post by g-force game engine
i agree with jyk, don't be hurry to make a game engine, sometimes a game engine is born from a successful game, so making game first, then you can think about making a game engine.


I agree. I also understand that in such 2d games, the engine is closely related to the game itself. My final question here is whether I should make a graphics class with all resources OR every game-object class should have its own sprites and call a static function from the graphics class to render it ?

No reply yet ?

[Edited by - tecfreak on July 26, 2010 12:57:42 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!