Blade Brothers Engine: Creating my first 2D Game Engine
Moderator: PC Supremacists
- LeonBlade
- Chaos Rift Demigod
- Posts: 1314
- Joined: Thu Jan 22, 2009 12:22 am
- Current Project: Trying to make my first engine in C++ using OGL
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: Blossvale, NY
Blade Brothers Engine: Creating my first 2D Game Engine
Hello everyone,
I've been working on making a simple engine in C++ using SDL (possibly integrating OpenGL).
I'll be going through my steps in creating the engine, and you guys can correct me on things if I make a mistake or if you feel that something should be done a different way.
This is my first Game Engine, and I'm new to the whole thing.
Thanks everyone.
I've been working on making a simple engine in C++ using SDL (possibly integrating OpenGL).
I'll be going through my steps in creating the engine, and you guys can correct me on things if I make a mistake or if you feel that something should be done a different way.
This is my first Game Engine, and I'm new to the whole thing.
Thanks everyone.
Last edited by LeonBlade on Sat Apr 23, 2011 1:00 pm, edited 5 times in total.
There's no place like ~/
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: Questions on Creating a Game Engine
Sup, I'm working on an engine myself too so I'll tell you what I canLeonBlade wrote:Hello everyone,
I've been working on making a simple engine in C++ using SDL (possibly integrating OpenGL).
Now, the question I have, is how to structure a game engine...
I'm stumped on this really, I know that you need to make classes for textures and sprites or objects etc etc.
But I'm not entirely sure where to go or what to do...
If someone could point me in a direction where I can find how I should structure a game engine.
Right now I made a "GameObject" class and a "Game" class but I feel as if I'm not going about it right...
Thanks, hope you guys can be of assistance.
I'm not pro but I know that a good game engine needs a good structure, that is what you have to think about
You need to think what your engine is going to be able to do, and plan the main basic structure but still think big e.g. ->
______________Engine Core______________
General | Graphics | Game Elements | Logic
Here your engine core handles the main classes that you have coded.
_________________General_________________
Windowing | Input | Timer | CPU/GPU Anaylsis
_______________Graphics(SDL/OGL)_______
2D (e.g. Menus, Sprites) | 3D | GUI | Models
_________________Game Elements_________________
Texture | Audio | Camera | Lighting | Client-Server :P
____________Logic____________
Vector | Algebra | Physics | etc..
To make things clear, an example of your engine functionality would be, drawing/handling a game object ->
Code: Select all
// Here you can see the flow of the engine //
Engine->Graphics->2D->DrawObject(box);
Engine->Logic->HandleObject(Vec2, box);
Code: Select all
Engine::DrawBox2D(Vec2 pos, int tex)
{
Graphics2D->DrawRect(pos, tex);
Logic->HandleObject(pos);
}
// So now you can do this //
Engine->loadtexture("box.png", 1);
vec2 box_pos(10, 10);
drawing_loop
{
Engine->DrawBox2D(box_pos, 1);
}
- LeonBlade
- Chaos Rift Demigod
- Posts: 1314
- Joined: Thu Jan 22, 2009 12:22 am
- Current Project: Trying to make my first engine in C++ using OGL
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: Blossvale, NY
Re: Questions on Creating a Game Engine
Thanks for the reply, I saw your topic before.
Right now I'm trying to work with textures.
I was looking at using map to store my textures and use a texture manager basically.
I'm just gonna post basically a log of what I'm doing here, if anyone wants to tell me what I should do instead of what I'm doing please post here!
Right now I'm working on the graphics portion of the Engine, it's not going to be a large engine, just my first trying to get in the basics.
This is how I want my code to look like for loading a new texture:
I would create an instance of my BETextureManager class somewhere globally (I would assume) and then to add a texture I would pass in the file name that I want to load.
There would be a BETexture struct something like this I guess:
There would be a map for textures like this:
The AddTexture function would look something like this:
So now that the texture is stored with AddTexture you can apply the texture to a sprite or whatever and render it etc.
Does this sound like a good idea?
I'll be posting more on Sprites once I do this...
Right now I'm trying to work with textures.
I was looking at using map to store my textures and use a texture manager basically.
I'm just gonna post basically a log of what I'm doing here, if anyone wants to tell me what I should do instead of what I'm doing please post here!
Right now I'm working on the graphics portion of the Engine, it's not going to be a large engine, just my first trying to get in the basics.
This is how I want my code to look like for loading a new texture:
Code: Select all
BETextureManager tm;
tm->AddTexture("filename.png");
There would be a BETexture struct something like this I guess:
Code: Select all
struct BETexture {
SDL_Surface *t; // the SDL_Surface for the texture you load in
int width,height; // the width and height of the texture?
SDL_Color tpc; // the transparent color for the texture?
// anything else need to be added here?
};
Code: Select all
std::map<uint, BETexture> be_textures;
Code: Select all
BETextureManager::AddTexture(std::string filename) {
be_textures[INDEX] = IMG_Load(filename.c_str()); // the INDEX will be figured someway... not sure yet probably just "pushing" the new texture
//do the rest of the stuff with the texture like transparency etc...
}
Does this sound like a good idea?
I'll be posting more on Sprites once I do this...
There's no place like ~/
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: Questions on Creating a Game Engine
cool, ye that would do the job, but make sure the other classes can use the texturemanager properly rather than doing it on the flyLeonBlade wrote: There would be a map for textures like this:The AddTexture function would look something like this:Code: Select all
std::map<uint, BETexture> be_textures;
So now that the texture is stored with AddTexture you can apply the texture to a sprite or whatever and render it etc.Code: Select all
BETextureManager::AddTexture(std::string filename) { be_textures[INDEX] = IMG_Load(filename.c_str()); // the INDEX will be figured someway... not sure yet probably just "pushing" the new texture //do the rest of the stuff with the texture like transparency etc... }
I use a texturemanager aswell, it handle textures for everything in the engine, I don't use map though but I think it's a great idea!
also your BETexture struct doesn't really need anything else, once the texture, width/height and color/alpha is handled it's pretty much good to go
- LeonBlade
- Chaos Rift Demigod
- Posts: 1314
- Joined: Thu Jan 22, 2009 12:22 am
- Current Project: Trying to make my first engine in C++ using OGL
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: Blossvale, NY
Re: Questions on Creating a Game Engine
Alright I have a basic TextureManager system going.
Right now it has a render function only so I could test to see if the textures were loading etc.
The first parameter is the destination surface and the second is the ID of the texture you wish to render.
If you pass in -1 for the ID it renders all that you passed in, but like I said, this is just temporary
Here is a screenshot of that last code call:
Next I'll be working on a BESprite class that will handle the source rectangle from the texture, and the destination rectangle for the destination surface (the screen).
Here's what I wanted to do for that:
This would do as expected... it would load in the texture from the BETextureManager with an ID of 0.
Then it would position it 100 pixels on the X axis and 50 pixels on the Y axis.
Note the comment next to the loadTexture function.
An optional parameter for the source rectangle can be passed in (this is useful when loading from a tilesheet however this may be managed in it's own separate class).
And rendering would be as follows:
Passing in screen as the destination surface.
I'll post that once I get that done, any suggestions?
Right now it has a render function only so I could test to see if the textures were loading etc.
Code: Select all
btm->Render(screen, -1);
If you pass in -1 for the ID it renders all that you passed in, but like I said, this is just temporary
Here is a screenshot of that last code call:
Next I'll be working on a BESprite class that will handle the source rectangle from the texture, and the destination rectangle for the destination surface (the screen).
Here's what I wanted to do for that:
Code: Select all
BESprite mySprite;
mySprite.loadTexture(btm.GetTexture(0, NULL)); // GetTexture(id, source_rect)
mySprite.x = 100;
mySprite.y = 50;
Then it would position it 100 pixels on the X axis and 50 pixels on the Y axis.
Note the comment next to the loadTexture function.
An optional parameter for the source rectangle can be passed in (this is useful when loading from a tilesheet however this may be managed in it's own separate class).
And rendering would be as follows:
Code: Select all
mySprite->Render(screen);
I'll post that once I get that done, any suggestions?
There's no place like ~/
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: Questions on Creating a Game Engine
Nop, looks pretty much legit to me, cool engine name btwLeonBlade wrote:Here's what I wanted to do for that:And rendering would be as follows:Code: Select all
BESprite mySprite; mySprite.loadTexture(btm.GetTexture(0, NULL)); // GetTexture(id, source_rect) mySprite.x = 100; mySprite.y = 50;
Passing in screen as the destination surface.Code: Select all
mySprite->Render(screen);
I'll post that once I get that done, any suggestions?
I miss SDL
- LeonBlade
- Chaos Rift Demigod
- Posts: 1314
- Joined: Thu Jan 22, 2009 12:22 am
- Current Project: Trying to make my first engine in C++ using OGL
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: Blossvale, NY
Re: Questions on Creating a Game Engine
I'm pretty new to it... however I have done stuff with it before.GroundUpEngine wrote:Nop, looks pretty much legit to me, cool engine name btwLeonBlade wrote:Here's what I wanted to do for that:And rendering would be as follows:Code: Select all
BESprite mySprite; mySprite.loadTexture(btm.GetTexture(0, NULL)); // GetTexture(id, source_rect) mySprite.x = 100; mySprite.y = 50;
Passing in screen as the destination surface.Code: Select all
mySprite->Render(screen);
I'll post that once I get that done, any suggestions?
I miss SDL
And I just thought of the name Blade Engine from Leon Blade and Blade Brothers is the name of my "team" if you want to call it that
Basically me and my cousin have been coming up with a game story line for most of our life blah blah blah etc etc.
I'm going to change the topic name to "Blade Engine: Creating my first 2D Game Engine with SDL" because that seems to be a better name for it.
There's no place like ~/
- programmerinprogress
- Chaos Rift Devotee
- Posts: 632
- Joined: Wed Oct 29, 2008 7:31 am
- Current Project: some crazy stuff, i'll tell soon :-)
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++!
- Location: The UK
- Contact:
Re: Blade Engine: Creating my first 2D Game Engine with SDL
Keep up the good work, It's always a plus to know people are working on such interesting and intricate projects
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
---------------------------------------------------------------------------------------
And now a joke to lighten to mood :D
I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
I think I can program pretty well, it's my compiler that needs convincing!
---------------------------------------------------------------------------------------
And now a joke to lighten to mood :D
I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
- LeonBlade
- Chaos Rift Demigod
- Posts: 1314
- Joined: Thu Jan 22, 2009 12:22 am
- Current Project: Trying to make my first engine in C++ using OGL
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: Blossvale, NY
Re: Blade Engine: Creating my first 2D Game Engine with SDL
Alright, update!
I got BESprite done (for the most part).
This is what it looks like:
That is loading in a texture, moving it relative to it's current position, and then rendering it.
The render is in a different function (not the init function) but I put it in the same code block.
The relative bool is so I can move the sprite relative to it's current position, rather than moving it to a direct position.
I created a new struct called BEPoint that is just a regular point with a x and y value.
Here is an example of loading in a sprite and I'm using the source rectangle to crop out a part of the texture:
Next I want to do something with input... controlling the sprites like a BECharacter class perhaps?
How should I go about this?
Should it inherit the BESprite class?
Or should it be a class of it's own?
And I plan on having NPCs in the Engine and then Characters that would inherit from NPCs or BLAH something.
Anyone have some suggestions?
I got BESprite done (for the most part).
This is what it looks like:
Code: Select all
BESprite mySprite;
mySprite.LoadTexture(btm.GetTexture(0)); // you can also pass in a source rectangle
mySprite.Move(position, true);
...
mySprite.Render(screen);
The render is in a different function (not the init function) but I put it in the same code block.
The relative bool is so I can move the sprite relative to it's current position, rather than moving it to a direct position.
I created a new struct called BEPoint that is just a regular point with a x and y value.
Here is an example of loading in a sprite and I'm using the source rectangle to crop out a part of the texture:
Next I want to do something with input... controlling the sprites like a BECharacter class perhaps?
How should I go about this?
Should it inherit the BESprite class?
Or should it be a class of it's own?
And I plan on having NPCs in the Engine and then Characters that would inherit from NPCs or BLAH something.
Anyone have some suggestions?
There's no place like ~/
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: Blade Engine: Creating my first 2D Game Engine with SDL
Nice Work!LeonBlade wrote:I got BESprite done (for the most part).
This is what it looks like:Should it inherit the BESprite class?Code: Select all
BESprite mySprite; mySprite.LoadTexture(btm.GetTexture(0)); // you can also pass in a source rectangle mySprite.Move(position, true); ... mySprite.Render(screen);
Or should it be a class of it's own?
And I plan on having NPCs in the Engine and then Characters that would inherit from NPCs or BLAH something.
Anyone have some suggestions?
The idea of BEPoint sounds similar to Vector2 which is good, BECharacter class should inherit BESprite so you can assign a texture to a NPC ->
Code: Select all
class BECharacter: public BESprite {
private:
BEPoint pos; // NPC position var //
public:
BECharacter(int x, int y) { // Init Constuctor //
pos.x = x;
pos.y = y;
}
BEPoint BECharacter::GetPosition() { // Find NPC position //
return(pos);
}
};
Code: Select all
// So you can //
BECharacter bob(100, 100);
bob.LoadTexture(btm.GetTexture(0));
etc..
- LeonBlade
- Chaos Rift Demigod
- Posts: 1314
- Joined: Thu Jan 22, 2009 12:22 am
- Current Project: Trying to make my first engine in C++ using OGL
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: Blossvale, NY
Re: Blade Engine: Creating my first 2D Game Engine with SDL
Thanks GroundUpEngine I'll get to work on that next
But first, I figured it would be best for me now to make a BETilesheet class so that I can render tiles on the screen and then make a level editor.
So far this is how my BETilesheet class looks like, and how I plan on doing it:
If you saw the line where I called the tiles[x, y] = tileRect that is map that looks like this.
Now this is using it in practice:
Something like that... the line where I call GetTile I pass in the tile's X and Y position on the tilesheet and that will retrieve the SDL_Rect for the source of the tile on the tilesheet.
More on that in a few...
But first, I figured it would be best for me now to make a BETilesheet class so that I can render tiles on the screen and then make a level editor.
So far this is how my BETilesheet class looks like, and how I plan on doing it:
Code: Select all
BETilesheet::BETilesheet(BETexture sheet, int rows_w, int rows_h) {
for (uint x=0; x<rows_w; x++) {
for (uint y=0; y<rows_h; y++) {
SDL_Rect tileRect;
tileRect.w = tileRect.h = 32;
tileRect.x = x*32;
tileRect.y = y*32;
tiles[x, y] = tileRect;
}
}
}
Code: Select all
std::map<int[,], SDL_Rect> tiles;
Code: Select all
BETilesheet mySheet(btm.GetTexture(0), 10, 5); // 10 by 5 is the tiles 10 tiles wide and 5 tiles tall
BESprite mySprite;
mySprite.LoadTexture(btm.GetTexture(0), mySheet.GetTile(0,0));
...
mySprite.Render(screen);
More on that in a few...
There's no place like ~/
-
- Chaos Rift Junior
- Posts: 345
- Joined: Tue Jan 12, 2010 7:23 pm
- Favorite Gaming Platforms: PC - Windows 7
- Programming Language of Choice: c++;haxe
- Contact:
Re: Blade Engine: Creating my first 2D Game Engine with SDL
Sorry to be the bringer of bad news (don't shoot the messenger?) but
http://www.blade3d.com/
http://www.bladeengine.com/
I'd hate to see you get sued or whatever because of the name. It may or may not be legal, just thought I'd point it out
I've been keeping an eye on this. Good work so far!
http://www.blade3d.com/
http://www.bladeengine.com/
I'd hate to see you get sued or whatever because of the name. It may or may not be legal, just thought I'd point it out
I've been keeping an eye on this. Good work so far!
- LeonBlade
- Chaos Rift Demigod
- Posts: 1314
- Joined: Thu Jan 22, 2009 12:22 am
- Current Project: Trying to make my first engine in C++ using OGL
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: Blossvale, NY
Re: Blade Engine: Creating my first 2D Game Engine with SDL
Ah, well thank you!
I probably should of Google'd it first huh?
I'll just change it to BBE for Blade Brothers Engine.
I probably should of Google'd it first huh?
I'll just change it to BBE for Blade Brothers Engine.
There's no place like ~/
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: Blade Engine: Creating my first 2D Game Engine with SDL
Damn that sucksLive-Dimension wrote:Sorry to be the bringer of bad news (don't shoot the messenger?) but
http://www.blade3d.com/
http://www.bladeengine.com/
I like that, sounds more originalLeonBlade wrote: I'll just change it to BBE for Blade Brothers Engine.
- LeonBlade
- Chaos Rift Demigod
- Posts: 1314
- Joined: Thu Jan 22, 2009 12:22 am
- Current Project: Trying to make my first engine in C++ using OGL
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: Blossvale, NY
Re: Blade Brothers Engine: Creating my first 2D Game Engine
Hey everyone, sorry I haven't been posting much in here.
I've been sick lately and I just didn't have the energy to program
I have the spritesheet pretty much fleshed out in the posts above, so I'll just implement that and soon get start on a level editor of some kind.
Right now I'm stuck converting all the project files to BBE from BE.
Okay, I created a new project instead and finished changing all the files over.
Now I'll get to work on the BBESpriteSheet class.
I've been sick lately and I just didn't have the energy to program
I have the spritesheet pretty much fleshed out in the posts above, so I'll just implement that and soon get start on a level editor of some kind.
Okay, I created a new project instead and finished changing all the files over.
Now I'll get to work on the BBESpriteSheet class.
There's no place like ~/