| Designing a 2D Engine |
|
riksweeney
|
Most game engines aren't generic, so for instance you couldn't take minesweeper engine and apply it to Halo 3. A lot of commercial games will however write most of their engine from scratch but will then also licence an engine for the physics part.
If you're only starting out, then an RPG will be a lot of work, and so will using OpenGL. I'd personally start off with something simple like a side scrolling shooter, as basic as you can make it (move your ship with the arrow keys and press space to fire a bullet). For a *very* basic game the loop would be something like
Your graphics manager could contain an array of SDL_Surfaces which you can store your loaded images into. The image loading function could return the array index of the image you loaded and you can store that to recall it later.
and when you want to get one of them back, you could call something like
So, if you loaded up your ship image, you could do something like
Then, when you want to retrieve the image for drawing, you could call
How much SDL have you already done by the way? |
|||||||||||||||||||||
|
|
||||||||||||||||||||||
|
Wrtent
|
Hello.
Sorry I had a busy week. About the SDL experience, I haven't done much, mostly colorkey, loading, surface manipulating, haven't started with animations yet (Getticks and more) and input. The problems I always have is the algorithms and structuring of the project. One question about what you posted. If I, for example, start creating a game and say I release it in beta, and then I begin fixing bugs and adding new content, do I have to manually increase the SDL_Surface* array every time I add a new image, like should it be hardcoded into the engine? I don't know, it just bugs me everytime, isn't everything supposed to be as simple as possible, just using the functions from the engine? Also, about the loop, a problem I've had is with rendering, when I write down some basic ideas of what the game should look like, I come up with 10 different render functions, meaning, I need lots of parameters. Lets say I have a function that renders parts of an image, I can use that to render something to the whole screen or just some parts, but what if I have to check for a condition, like for example, "Is mouse over Guardian Tower" if yes then render range, or maybe say I have an inventory that has gear slots which when pointed at get highlighted. But one thing here is important, if I have to render multiple surfaces, do I have to include all of them in the render function or should it be in a loop, and if I have to include them all, how do I tell the function that it must only render a few, not all, without using a bunch of IFs or switch? (just an idea - I could implement something like a call stack, just like te game states stack, that puts everything in there and the render function, which has a loop in it, renders it one by one in its loop). Sorry for the walls of questions, but I've just started with this, and it seems like programming 24/7, besides I recently started programming in C++ (well a year ago but I stopped for 10 months, to concentrate on other stuff). Really thanks for your help. Wrtent |
|||||||||||
|
|
||||||||||||
|
gameEater63
|
Dear Wrtent, Your problems seem mostly come from structuring the program. Most
of them are resolvable using OOP, what C++ fully supports. Also C++ offers Abstract Containers which solve the problem of pre-allocating an array of surfaces. You just need to declare a vector of surfaces, and add as many surfaces as you want to it. Considering game engines, I actually have been working on a home-made one for several weeks named Simple Game Engine (SGE), and it has or is supposed to have support for backgrounds, animated sprites, GUI, network, geometric elements, isometrics coordinate system, sounds, timing, game objects and a level runner which runs the main loop of the game itself. SGE is fully object oriented, and uses SDL 1.2, and yes it is a generic engine, and You need to derive objects of your game (player, enemies, platforms, arrows...) from a particular class, and rewrite some virtual functions. Edited : I've found an excellent free host to put the SGE onto |
|||||||||||
|
|
||||||||||||

