Blade Brothers Engine: Creating my first 2D Game Engine

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Blade Brothers Engine: Creating my first 2D Game Engine

Post by avansc »

who's the cute gurl is all i really wanna know. ;)
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: Blade Brothers Engine: Creating my first 2D Game Engine

Post by Bakkon »

Looking like a good start. Keep up the good work.
avansc wrote:who's the cute gurl is all i really wanna know. ;)
Hopefully its his girlfriend or its a little creepy that he's using her as a test sprite. :P
User avatar
LeonBlade
Chaos Rift Demigod
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

Post by LeonBlade »

Bakkon wrote:Looking like a good start. Keep up the good work.
avansc wrote:who's the cute gurl is all i really wanna know. ;)
Hopefully its his girlfriend or its a little creepy that he's using her as a test sprite. :P
Hahaha, me and her are together :lol:

I hope to either work on it within the next few hours, or tomorrow perhaps.
There's no place like ~/
User avatar
LeonBlade
Chaos Rift Demigod
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

Post by LeonBlade »

Hey everyone, I'm experiencing some issues on my tilesheet...
For whatever reason it returns the tile on the right and whatever Y gets passed in.
Here is an example:
Image
This is me passing in (0,2) yet it doesn't do the X position correctly.

I'll try outputting some information to the console, in the mean time, here is my for loop:

Code: Select all

void BBETileSheet::LoadTiles(BBETexture *texture, int rows_w, int rows_h)
{
	t_Texture = texture;
	t_TilesW = rows_w;
	t_TilesH = 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);
			
			t_Tiles[x, y] = tileRect;
		}
	}
}
There's no place like ~/
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: Blade Brothers Engine: Creating my first 2D Game Engine

Post by Bakkon »

LeonBlade wrote:

Code: Select all

			t_Tiles[x, y] = tileRect;
This is C++, correct? This doesn't look right. You probably want t_Tiles[x][y] if this is a 2D array.
User avatar
GroundUpEngine
Chaos Rift Devotee
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 Brothers Engine: Creating my first 2D Game Engine

Post by GroundUpEngine »

Bakkon wrote:
LeonBlade wrote:

Code: Select all

			t_Tiles[x, y] = tileRect;
This is C++, correct? This doesn't look right. You probably want t_Tiles[x][y] if this is a 2D array.
That was I was thinking, How did that compile with no errors?
User avatar
LeonBlade
Chaos Rift Demigod
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

Post by LeonBlade »

GroundUpEngine wrote:
Bakkon wrote:
LeonBlade wrote:

Code: Select all

			t_Tiles[x, y] = tileRect;
This is C++, correct? This doesn't look right. You probably want t_Tiles[x][y] if this is a 2D array.
That was I was thinking, How did that compile with no errors?
Yeah I'm not sure what I was thinking :roll:

This is what it looks like now:

Code: Select all

void BBETileSheet::LoadTiles(BBETexture *texture, int rows_w, int rows_h)
{
	t_Texture = texture;
	t_TilesW = rows_w;
	t_TilesH = rows_h;
	
	int cTile = 0;
	
	for (uint y=0; y<rows_h; y++) {
		for (uint x=0; x<rows_w; x++) {
			SDL_Rect tileRect;
			tileRect.w = tileRect.h = 32;
			tileRect.x = (x * 32);
			tileRect.y = (y * 32);
			
			t_Tiles[cTile] = tileRect;
			cTile++;
		}
	}
}
I was having problems because the X and Y were reversed so I just swapped the two for loops and now it works fine like this.
Basically it makes it a long string of tiles, but in reality, the image isn't spliced up or anything.

I was also having problems with optimizing my image for transparency with a transparent color with color keys, so I just instead made it a PNG and transparent :)

So now everything is working just as I want it to with BBETileSheet!

Next I plan on making some sort of level editor... should I do this using SDL to render the graphics?
Or should I just load in the graphics a different way? I want to have an actual UI that you can click around and stuff, and have the SDL screen in a portion of the window if at all possible.

And then there is the issue of in what format should my maps be saved in.
Would an XML based map system be worth it? Or should I just make a large file full of numbers and commas to delimit them and load it in and parse out the tiles from there?

Thanks for everyone's words so far.
There's no place like ~/
User avatar
RyanPridgeon
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 447
Joined: Sun Sep 21, 2008 1:34 pm
Current Project: "Triangle"
Favorite Gaming Platforms: PC
Programming Language of Choice: C/C++
Location: UK
Contact:

Re: Blade Brothers Engine: Creating my first 2D Game Engine

Post by RyanPridgeon »

LeonBlade wrote: Next I plan on making some sort of level editor... should I do this using SDL to render the graphics?
Unless you plan on doing alot of pixel manipulation you may want to look into using OpenGL :)
Ryan Pridgeon
C, C++, C#, Java, ActionScript 3, HaXe, PHP, VB.Net, Pascal
Music | Blog
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Blade Brothers Engine: Creating my first 2D Game Engine

Post by Ginto8 »

RyanPridgeon wrote:
LeonBlade wrote: Next I plan on making some sort of level editor... should I do this using SDL to render the graphics?
Unless you plan on doing alot of pixel manipulation you may want to look into using OpenGL :)
and even if you want to do a lot of pixel manipulations, you can probably implement it more efficiently than SDL does by using OpenGL and some stuff like glUpdateTexture() (or w/e the function is, I remember seeing it used in a nehe tutorial)
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
LeonBlade
Chaos Rift Demigod
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

Post by LeonBlade »

RyanPridgeon wrote:
LeonBlade wrote: Next I plan on making some sort of level editor... should I do this using SDL to render the graphics?
Unless you plan on doing alot of pixel manipulation you may want to look into using OpenGL :)
Hmm, well that doesn't sound too good :(
I think I'll just make the level editor entirely in the game engine instead of making a graphical UI.
It wont be a challenge, and with the right graphics I can make it look nice :)

Here are some of the features/goals I want for the editor:

Ease of use:
This one should come as no surprise. Obviously you want a level editor to be easy to use.
I plan on making a simple HUD that will hold tiles and other properties on the right side, and tools on the left side.
Features like a rectangle tool to easily draw large areas, being able to right-click to set the current tile to the one under your mouse, things like that.

Multiple Layers:
There will be the base ground layer which will contain all the basic tiles that wont have transparency on them.
This includes things like grass, pathways, walls, etc.
The base layer or ground layer will be below every thing else

A second layer will hold elements that will be above the ground layer, but not over your character.
This is where you would place tiles like flowers, windows, trees, chairs, things with transparency in their tile.

The third layer will be all tiles you want to be placed above everything else.
These would be things like bridges for example that are over your character.

I may decide to make a priority layer that will sort the Z of the tile instead and just have 2 extra layers for transparency.

Collision Layer:
This is pretty straight forward, all tiles with an X or some other form of way to signify a collision will be a solid[/b] tile and you cannot pass through it.

Event Layer:
When you go into the event layer, the right panel will change.
Instead of showing all the map tiles, it will instead show character tiles and other event tiles that can be used, as well as an invisible tile.
The right panel will contain properties for your event as well.

Every event has:
  • Tile or character tilesheet for NPCs.
  • Trigger type whether it be auto-start, key press, player touch/collision, etc.
  • Solidity either true or false to determine if you can walk through the event or not.
  • Script file will be the name of the script you wish to call when the trigger is fired.


I'm going to look into Lua and see if I want to use that, but I may decide to use Ruby instead.
If you have any suggestions, please let me know.

That's pretty much it for my mock-up of the level editor.
Let me know what you guys think and what I should change or improve on.

Right now I'll be working on statically loading in a hard-coded map file.
Here is an example of how I want to have my map saved:

Code: Select all

<Map name="My Map" width="300" height="250" tilesheet="mytileset.png">
     <GroundLayer>
          TILE_NUMBER,X_POSITION,Y_POSITION,COLLISION_STATE
     </GroundLayer>

     <SecondLayer>
          TILE_NUMBER,X_POSITION,Y_POSITION,COLLISION_STATE
     </SecondLayer>

     <ThirdLayer>
          TILE_NUMBER,X_POSITION,Y_POSITION,COLLISION_STATE
     </ThirdLayer>

     <EventLayer>
          SPRITE_SHEET,X_POSITION,Y_POSITION,COLLISION_STATE,TRIGGER_STATE,SCRIPT_FILE
     </EventLayer>
</Map>
I figured I could use XML to easily structure the file, but when it came down to parsing it, I would be left with this for example:

Code: Select all

0,0,0,0
0,0,1,0
2,0,2,1
And I would just remove all spaces and I could delimit each line with the line-break character.
Then I would have the tile which I could delimit each property with the comma and then create a sprite for that tile etc.
For events it's the same way, only I do other stuff for the events of course because they aren't just tiles.

Let me know what you think of my approach to this!!!
If you think that I'm just going crazy with it and should tone it down, or if you have some suggestions PLEASE PLEASE PLEASE let me know.
This is my first engine and my first level editor, so right now I'm not entirely sure what to do.

Next I'll be working on loading in a level just with tiles that just appear in rows like this:

Code: Select all

0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
Which would load a 12x3 tiled map full of all tile 0.

Thanks, and hope to hear your input.
There's no place like ~/
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Blade Brothers Engine: Creating my first 2D Game Engine

Post by K-Bal »

Some suggestions to your map implementation:

- Use YAML instead of XML, easier to read and maintain.
- Don't limit one map to one tileset. You will end up merging images with something like GIMP, unneccessary extra work.
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: Blade Brothers Engine: Creating my first 2D Game Engine

Post by Bakkon »

RyanPridgeon wrote: Unless you plan on doing alot of pixel manipulation you may want to look into using OpenGL :)
It's also pretty easy to create an OpenGL texture from an SDL_Surface*. I find it easier to keep track of GLuints instead of SDL_Surface pointers.
K-Bal wrote: - Don't limit one map to one tileset. You will end up merging images with something like GIMP, unneccessary extra work.
This is a big one IMO. Just have a tile know which spritesheet to use and then the (x,y) block on that sheet.
User avatar
LeonBlade
Chaos Rift Demigod
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

Post by LeonBlade »

Thank you for the suggestions and improvements.
Once I get to work again, I will implement them.
There's no place like ~/
User avatar
RyanPridgeon
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 447
Joined: Sun Sep 21, 2008 1:34 pm
Current Project: "Triangle"
Favorite Gaming Platforms: PC
Programming Language of Choice: C/C++
Location: UK
Contact:

Re: Blade Brothers Engine: Creating my first 2D Game Engine

Post by RyanPridgeon »

Sorry, I didn't realise you were talking about an external level editor.

For that I'd recommend Qt, it's cross-platform, powerful and intuitive :)
Ryan Pridgeon
C, C++, C#, Java, ActionScript 3, HaXe, PHP, VB.Net, Pascal
Music | Blog
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: Blade Brothers Engine: Creating my first 2D Game Engine

Post by eatcomics »

I hope to get an ingame level editor in my platformer soon. School has pulled me in, and I have other things to do for an alliance I'm in... One of my friends runs the alliance, so he forces me to work XD but anyways looks great and keep it up. Do you have youtube vids, if so I'll go sub :D
Image
Post Reply