Tile Engine question

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

mattheweston
Chaos Rift Junior
Chaos Rift Junior
Posts: 200
Joined: Mon Feb 22, 2010 12:32 am
Current Project: Breakout clone, Unnamed 2D RPG
Favorite Gaming Platforms: PC, XBOX360
Programming Language of Choice: C#
Location: San Antonio,Texas
Contact:

Tile Engine question

Post by mattheweston »

I'm building a tile Engine for a game I'm working on and had a question.

I'm looking at having a Tile class and a map class.

The map class would be a 2D array of Tiles and the tile class would have information about a "Tile" including an array that would hold the information for each layer for that tile.

In a game I would have an array of "map"s to build a level.

Currently, I'm looking for feedback on this design. What do you guys think?
Image
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: Tile Engine question

Post by GroundUpEngine »

Great design imo, I have used the exact same thing for 2 of my first games :)
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: Tile Engine question

Post by XianForce »

so like:

Code: Select all

class Map
{
Tile** tiles;
};

class Tile
{
//Other tile stuff...
Layer* layer
};
?

If that's along the lines of what you were thinking, I think that's a tad bit flawed.

Typically when you have different layers, you'll probably have like a ground layer, a couple object layers, maybe an item layer, etc.

So if any of these share the same (x, y) position, yet different layers, they will probably all need to hold different information to define itself.

So if a tile has an array that defines all the spaces in that (x, y) space through a number of layers, things will become a bit more complicated when two of those spaces in the layer aren't the same (and if they are the same, layers become useless...).

In my level editor / tile engine. I have maps defined as a dynamically allocated 3D array. So, I have width, height, and layers, and each one is a different tile. This way I can store information about each individual piece.


Sorry if my post seems a little confusing, but I hope it helps.


EDIT: After thinking about what I posted, perhaps I interpreted what you said a little wrong, did you perhaps mean something more like this:

Code: Select all

class Map
{
Tile** tiles;
Tile* tileLayers;
};

class Tile
{
//Tile info
};
? Because that seems like a great way to do it =D
mattheweston
Chaos Rift Junior
Chaos Rift Junior
Posts: 200
Joined: Mon Feb 22, 2010 12:32 am
Current Project: Breakout clone, Unnamed 2D RPG
Favorite Gaming Platforms: PC, XBOX360
Programming Language of Choice: C#
Location: San Antonio,Texas
Contact:

Re: Tile Engine question

Post by mattheweston »

I see what you are saying. I started with the 3D array concept but didn't want to get things too complex. =)

The gist would be to use a Tile to have a ground layer(grass, road, caves, etc) then have a layer for objects(treasure chests, etc)

I would have say an overworld "level" that would be similar to a "screen" in a game like zelda this would be a 2D array.

then the coordinate x,y in that array would be a "map" which in and of itself would be a 2D array of TIles.

That was the initial thought; however, I think once difference would be that in this design you would almost have to do it like The Legend of Zelda in order to only have one "Map" on the screen at once. If you used a 3D array you would be able to do more of a smooth scrolling around the world.

My inital problem was trying to think of a way to work on a "level" that goes beyond the bounds of a screen in a level editor.
Then again I really haven't put TOO much tought into this. =)
Image
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: Tile Engine question

Post by XianForce »

mattheweston wrote: My inital problem was trying to think of a way to work on a "level" that goes beyond the bounds of a screen in a level editor.
Well if you still haven't found a solution to this, here's my two cents:

Create a camera class, and only load the tiles that would be on screen. So with a few calculations, you can find where the top left corner of the game window should be, and from there, it's easy to find the rest of the rectangle. So you'd start with the tiles that would be at that (x, y) coordinate in the map, and tile until you reach the screen width and height.
mattheweston
Chaos Rift Junior
Chaos Rift Junior
Posts: 200
Joined: Mon Feb 22, 2010 12:32 am
Current Project: Breakout clone, Unnamed 2D RPG
Favorite Gaming Platforms: PC, XBOX360
Programming Language of Choice: C#
Location: San Antonio,Texas
Contact:

Re: Tile Engine question

Post by mattheweston »

yeah I was going to have a variable for storing the top left corner of the tiles on screen. This is probably really easy stuff. I just have to think it through and not make it out to be harder than it is. =)
Image
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: Tile Engine question

Post by XianForce »

mattheweston wrote:yeah I was going to have a variable for storing the top left corner of the tiles on screen. This is probably really easy stuff. I just have to think it through and not make it out to be harder than it is. =)
Well, I'd say you should at least have a rectangle to hold the top left corner, width, and height, instead of only the top left corner
mattheweston
Chaos Rift Junior
Chaos Rift Junior
Posts: 200
Joined: Mon Feb 22, 2010 12:32 am
Current Project: Breakout clone, Unnamed 2D RPG
Favorite Gaming Platforms: PC, XBOX360
Programming Language of Choice: C#
Location: San Antonio,Texas
Contact:

Re: Tile Engine question

Post by mattheweston »

Yes, I'll have a height and width as well. Not sure if I'll have two vector2D vars or one Rectangle yet.

Rectangle would make more sense.
Image
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: Tile Engine question

Post by RyanPridgeon »

XianForce wrote:so like:

Code: Select all

class Map
{
Tile** tiles;
};

class Tile
{
//Other tile stuff...
Layer* layer
};
This looks absolutely fine.
This is the way I would do it, although maybe not have a seperate Layer object for every layer, as some layers (like collision) might only need something as simple as a char value, and others might need much more complex information. Unless Layer is an abstract base type which would work fine, as long as you're not going too overboard on OOP.
XianForce wrote:

Code: Select all

class Map
{
Tile** tiles;
Tile* tileLayers;
};

class Tile
{
//Tile info
};
? Because that seems like a great way to do it =D
This makes little sense.
Last edited by RyanPridgeon on Tue Mar 23, 2010 11:26 am, edited 1 time in total.
Ryan Pridgeon
C, C++, C#, Java, ActionScript 3, HaXe, PHP, VB.Net, Pascal
Music | Blog
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: Tile Engine question

Post by XianForce »

RyanPridgeon wrote:
XianForce wrote:so like:

Code: Select all

class Map
{
Tile** tiles;
};

class Tile
{
//Other tile stuff...
Layer* layer
};
This looks absolutely fine.
This is the way I would do it, although maybe not have a seperate Layer object for every layer, as some layers (like collision) might only need something as simple as a char value, and others might need much more complex information. Unless Layer is an abstract base type which would work fine, as long as you're not going too overboard on OOP.
XianForce wrote:

Code: Select all

class Map
{
Tile** tiles;
Tile* tileLayers;
};

class Tile
{
//Tile info
};
? Because that seems like a great way to do it =D
This makes little sense.
Yeah I realized I effed that up haha...

The second thing I posted is most definitely NOT the way to do it. I had a little brain malfunction there haha.

But the first way... What happens when you need information for a specific tile? If you have a 2D array of tiles, that accounts for the (x, y), but if the tiles hold something to represent each tile in that layer, that becomes a problem because they likely need to have different properties, and have all the properties any tile would. So the only way I could think that it would have the same properties, is if you made it another array of tiles within the tile class... which wouldn't really work, as it would be unending, right?

And just to fix the second one, what I probably meant to put was something like:

Code: Select all

class Map
{
Tile** tiles1;
Tile** tiles2;
//continue for amount of layers
};
But that's probably not great style.

But here's another suggestion:

Code: Select all

class Layer
{
Tile** tiles
};

class Map
{
std::vector<Layer> layers;
};
That would probably work well, but I imagine there would be some nasty overhead with the vector.

But then again, what do I know? I'm a nub :lol:
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Tile Engine question

Post by avansc »

since you are so pointer happy,
why not just go, Tile ***tiles; ?
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
mattheweston
Chaos Rift Junior
Chaos Rift Junior
Posts: 200
Joined: Mon Feb 22, 2010 12:32 am
Current Project: Breakout clone, Unnamed 2D RPG
Favorite Gaming Platforms: PC, XBOX360
Programming Language of Choice: C#
Location: San Antonio,Texas
Contact:

Re: Tile Engine question

Post by mattheweston »

All the C++ examples are great but, pointers won't be a problem as I'll be using C# and XNA. =)
Image
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: Tile Engine question

Post by XianForce »

mattheweston wrote:All the C++ examples are great but, pointers won't be a problem as I'll be using C# and XNA. =)
Oh, oops >.>
mattheweston
Chaos Rift Junior
Chaos Rift Junior
Posts: 200
Joined: Mon Feb 22, 2010 12:32 am
Current Project: Breakout clone, Unnamed 2D RPG
Favorite Gaming Platforms: PC, XBOX360
Programming Language of Choice: C#
Location: San Antonio,Texas
Contact:

Re: Tile Engine question

Post by mattheweston »

It's all good. I think I got things figured out now.
Image
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: Tile Engine question

Post by LeonBlade »

avansc wrote:since you are so pointer happy,
why not just go, Tile ***tiles; ?
Better yet...

Code: Select all

Tile *******tiles;
...seems to be the best route to take ;)
There's no place like ~/
Post Reply