Engine Programming

Started by
23 comments, last by Servant of the Lord 13 years, 1 month ago
Hi everyone, I just started with Game Development and I'm currently working on a 2d engine for my game. I'm using C++ and SDL and I wanted to ask you guys a few questions about the engine structure.
I've been reading articles and tutorials on the web on the subject and it looks like there's really no "perfect design" it's a personal choice how to structure classes etc... I was thinking about it and I came up with this:

  1. System class: inits/closes the library, handles input and rendering and checks for collision
  2. Image class: loads/frees images and returns an SDL_Surface * (because i'm using SDL) when needed
  3. Audio class: same as Image class just with audio
  4. Font class: save as above with fonts
  5. Sprite class: has a SDL_Rect wich is used to render the sprite and also for collision and all the flags like is_solid is_transparent is_animated
  6. Tile class: same as above (infact i think i should link Sprite and Tile together in some way)

And that's the basic structure (wich is probably bad), what do you think?

Also i have a question about collision... I don't know when to check for collision, I guess i'd have to check inside the main loop if all the sprites in the game are solid and if they are solid if they are colliding with each other OR with the tiles wich are solid... because if i just check for collision on a key down for example, i'm only checking for the player and I want to check for the enemies also...
But that looks like it's gonna eat too much cpu and I'm sure there are better ways to do that.

Thanks in advance, I hope my english is comprehensible.
(This is my first attempt at making a game engine by the way, go easy on me smile.gif)
Advertisement
Ask yourself, how will your engine be used to make a game or other type of app? How useful will it be to make the game you want to make? What are you building the engine for.. ie do you have a game in mind, what does that game need?

There's millions of ways to make an engine... or framework. If they accomplish the goal you set out to accomplish then you made it the way it needs to be. Not to be harsh but you post looks like youre staring down the barrel of a loaded gun but have to ask other people how to pull the trigger.
[ dev journal ]
[ current projects' videos ]
[ Zolo Project ]
I'm not mean, I just like to get to the point.
Write Games, Not Engines

You might want to give that a read...

Ask yourself, how will your engine be used to make a game or other type of app?


The engine will be used to make 2d games, at the moment i have one particular game in mind but i want the engine to be flexible.


How useful will it be to make the game you want to make?


I don't know if it'll be "useful", I'm just doing it because I love programming and videogames.


What are you building the engine for.. ie do you have a game in mind, what does that game need?


2d platformer kind of game.


There's millions of ways to make an engine... or framework. If they accomplish the goal you set out to accomplish then you made it the way it needs to be.


Thanks for that.


Not to be harsh but you post looks like youre staring down the barrel of a loaded gun but have to ask other people how to pull the trigger.


I'm just asking to experienced game developers if my design is solid for a good 2d game engine wich would be flexible and also i asked a specific question about collision checking, I naively thought a forum about game development would be a good place for it.

Write Games, Not Engines

You might want to give that a read...



I don't want to delude you but i'm actually making a game alongside the engine... I just want the engine to be usable in the future too.
But nevermind, really....
If you don't got alot of experience in writing 2D game then writing a flexible game engine that can be used in several games is really hard to pull off. Since you said you just started with game development I suggest you write games first. Every game needs some kind of engine, but it's a big difference between an engine made for a specific game and one made for several.

If you don't got alot of experience in writing 2D game then writing a flexible game engine that can be used in several games is really hard to pull off. Since you said you just started with game development I suggest you write games first. Every game needs some kind of engine, but it's a big difference between an engine made for a specific game and one made for several.


Allright thanks.
You can close the topic rolleyes.gif
Several times in the past I've tried to go the route of designing an engine and a game... usually it starts to work at first, but then gets really complicated as unexpected things pop up.
Currently, I'm writing a game, and I'm doing my best to keep my code clean and concise. As I'm writing the game, I see logically how it's separating into three different types of code: general code, genre-specific code, and game-specific code. So I then separate those types of code into three different folders (which I call, 'Common', 'Engine', and 'Game', respectively).

As I'm writing my game, the engine falls out of it if the game is coded well. If the game isn't coded well, me trying to make an engine will result in an engine that isn't coded well and can't be used anyway.smile.gif

Your solutions are:
1) Code a game poorly. Result: You have a completed game.
2) Code an engine poorly, and a game alongside it. Result: [color="#1C2837"]You have a not-working engine, and stop working on the game, because the engine doesn't work.
[color="#1C2837"]3) Code a game properly. Result: You have a completed game... and a completed engine that pops out of nowhere!
[color="#1C2837"]4) Code an engine properly. Result: You have an completed engine. But to code an engine properly, you have to have experience coding a finished game properly in the past anyway, so you are probably a professional already.

[color="#1C2837"]The game to learning how to make good game engines in the future is to make good games in the present. If you aren't focusing on the game, then all you are doing is making a fancy API by wrapping whatever API you are already using.mellow.gif

[color="#1C2837"]
Also i have a question about collision... I don't know when to check for collision, I guess i'd have to check inside the main loop if all the sprites in the game are solid and if they are solid if they are colliding with each other OR with the tiles wich are solid... because if i just check for collision on a key down for example, i'm only checking for the player and I want to check for the enemies also...[/quote]
[color="#1C2837"]After a keypress, call something like Player->Move(). After the AI thinks, the AI calls something like Enemy->Move(). The 'Move()' function could check for collision, not the keypress handling function.

[color="#1C2837"]
But that looks like it's gonna eat too much cpu[/quote]
[color="#1C2837"]If your CPU can run advanced 3D games from two or three years ago, why worry about a few 2D images like what they used to make 20 years ago?
[color="#1C2837"]It can handle your game. Only start optimizing your game when your game drops below 20 frames per second. Otherwise, wait until your game is
[color="#1C2837"]complete, then optimize it using a proper profiler, not guesswork.wink.gif

[color="#1C2837"]
[color="#1C2837"]And that's the basic structure (wich is probably bad), what do you think?[color="#1C2837"][/quote]
[color="#1C2837"]Don't second guess yourself or put yourself down. Just run hard, and when you hit a wall, dust yourself off and run again.
[color="#1C2837"]It's good to have something to run toward, though, otherwise you are running at the wrong goal. Making an engine, even for learning, isn't the best goal. It's an 'acceptable' goal, but a better goal is to make a game. Simple and friendly advice that a lot of people are offering you - you can accept it, reject it, or store it away for later, it's your call!
[color="#1C2837"]
[color="#1C2837"]I fully understand the desire to make an engine because it sounds so cool. Just don't let it stop you from making your game; and if you fail, don't let it stop you from picking yourself up again, and if you succeed, don't let it go to your head. tongue.gif
I can understand where you're coming from with the question you posed, however it is very hard to answer, which is the reason some of the responses haven't been to your liking it seems.

I'm a programmer in my day job (not games though), but in my spare time I have coded several games projects, and my advice to you is to go ahead and write the game and not dwell too much on trying to making an awesome engine to run it. You'll make mistakes, but that's the way we learn what works and what doesn't. It takes a great deal of talent and experience to build a reusable, extensible framework and it's not a realistic goal as a first project to be honest.

That said, the classes you've described sound ok to me. Once you get cracking on the project you'll find you need a whole bunch more classes you never even considered, but that's the nature of coding where the design is in your head, not specced out by a designer into a 200 page requirements document. :)

Re: Collisions, typically collision detection is done in the main game loop, once per frame. Modern hardware should be able to handle even fairly naive brute-force tests here, if performance is an issue there are plenty of optimisations you can do.

Good luck!
[size="2"]Currently working on an open world survival RPG - For info check out my Development blog:[size="2"] ByteWrangler
As others have pointed out, why reinvent the wheel. For 2d platformer there are the HGE or Löve engine. Both are very good. Just recently checked them out.

This topic is closed to new replies.

Advertisement