2D Game Data Structures
In the game I''m making, I''m not really sure how I should organize my data. I have tiles that you can set the graphic tile and blocked/unblocked flag on. I''m not sure if I should add in objects and player start points to the tile data or not. Should I have this data in the tile structure, or should I have separate tile, object, and player start structures?
Well im not really qualified to answer your question so dont just assume this is right. Lets say you have 4 player start points in each level to have variable for every tile that records wheather the player starts ther or not is going to be using up a lot of space when you could simply have an array with 4 x and y coords.
anyway i mabe talking bull because i have never done anything with tiles berfore (except the bathroom).
anyway i mabe talking bull because i have never done anything with tiles berfore (except the bathroom).
yeah boy
This is a simplest case for tile based program:
Struct {
POINT m_ptPosition
int m_nTileType
int m_nLayer //omit this one if you don''t have multiple layers
} CTile;
//Each Tile is considered one point in LP
class CMap
{
CMap();
~CMap();
CTile* m_pTileList; //use a pointer list for now,
//replace, if you have a container class
POINT m_ptCenterTile
}
class CTileConverter
{
//this function returns the Rect where a tile is in
static RECT LP2DP(POINT ptTile)
//this function returns the tile a screen point is at
static POINT DP2LP(POINT ptScreenPoint)
//other drawing helper class
static RECT GetPlayerInDP(POINT ptTile, int nLayer = 0);
static RECT GetMonsterInDP(POINT ptTile, UINT nMonsterID, int nLayer = 0);
}
class CPlayer : public someclass
{
......
POINT m_ptTile; // the tile where the player is at
int m_nLayer; //omit if ....
}
class CMonster : public someclass
{
......
POINT m_ptTile;
int m_nlayer; //omit if....
}
This should allow you to do all the calculations in Tile, and only convert to Device Point system during drawing.
Hope this helps. I used this system for my game, and it worked great so far. (except I have CPlayer and CMonster derived from a same base class that owns these two members)
Turtlenet
Struct {
POINT m_ptPosition
int m_nTileType
int m_nLayer //omit this one if you don''t have multiple layers
} CTile;
//Each Tile is considered one point in LP
class CMap
{
CMap();
~CMap();
CTile* m_pTileList; //use a pointer list for now,
//replace, if you have a container class
POINT m_ptCenterTile
}
class CTileConverter
{
//this function returns the Rect where a tile is in
static RECT LP2DP(POINT ptTile)
//this function returns the tile a screen point is at
static POINT DP2LP(POINT ptScreenPoint)
//other drawing helper class
static RECT GetPlayerInDP(POINT ptTile, int nLayer = 0);
static RECT GetMonsterInDP(POINT ptTile, UINT nMonsterID, int nLayer = 0);
}
class CPlayer : public someclass
{
......
POINT m_ptTile; // the tile where the player is at
int m_nLayer; //omit if ....
}
class CMonster : public someclass
{
......
POINT m_ptTile;
int m_nlayer; //omit if....
}
This should allow you to do all the calculations in Tile, and only convert to Device Point system during drawing.
Hope this helps. I used this system for my game, and it worked great so far. (except I have CPlayer and CMonster derived from a same base class that owns these two members)
Turtlenet
I''ve got the tile structure and stuff figured out now, it''s just a modified version of what you have. There''s another thing I was wondering that your code reminded me about. At first I was going to try to implement some sort of multiple floor design for my maps where the player could see the lower floor through holes in the floor the player''s on and on the sides of catwalks, etc. I decided to scrap that idea, don''t remember why. I may have scrapped it because I couldn''t think of a very good way to get that working. You can fall from floor to floor as well, and use elevators and stairs. The game I''m working on is just an overheard tile-based game. If anyone knows how to do this, I''d really like to know. I havn''t thought about it much lately because I''ve been busy, but the ideas of others never hurt (don''t start giving examples of ideas that hurt people, just letting all of those smart asses out there know that, I know I''d end up doing it if someone else said the same thing). Thanks for any help you can provide.
Just a thought:
you could make the floor that the player is on "hard" and alpha blend the roof...?
Regards,
Nekosion
you could make the floor that the player is on "hard" and alpha blend the roof...?
Regards,
Nekosion
Regards,Nekosion
It is posible to do with an upgrade version above method.
I think in the LP2DP and DP2LP method, I forgot to add the nLayer argument.
In the CMap object, you can use two drawing methods. The first drawing method draws all the tiles with Z-order lower than player, and the second draws all the tiles with higher z-order.
for example, when the player is on layer 1, position 3,3.
draw layer 0 first, then layer 1 from 0,0 throuugh 3,2, paint layer 1, draw player, then draw the rest.
In order to animate the "fall through scene. A player''s layer info should be a float instead of int, add add an API to determine the player''s integer layer info so that you can determine when you should stop drawing the top layer:
int GetPlayerLayer()
{
if (m_nLayer > 0.3)
return 1; //player can still be seen on the top layer so that
// we still need to draw top layer
else
return 0; // player cannot be seen on top, skip drawing top
// layer
}
The Animation timer can move 0.1 layer each tick so that you may see the entire "fall through" sequence.
if the calculation in RECT GetPlayerInDP is correct, this method should produce a good result.
You may also add an algorithm to skip drawing the covered tiles for better performance.
Turtlenet
I think in the LP2DP and DP2LP method, I forgot to add the nLayer argument.
In the CMap object, you can use two drawing methods. The first drawing method draws all the tiles with Z-order lower than player, and the second draws all the tiles with higher z-order.
for example, when the player is on layer 1, position 3,3.
draw layer 0 first, then layer 1 from 0,0 throuugh 3,2, paint layer 1, draw player, then draw the rest.
In order to animate the "fall through scene. A player''s layer info should be a float instead of int, add add an API to determine the player''s integer layer info so that you can determine when you should stop drawing the top layer:
int GetPlayerLayer()
{
if (m_nLayer > 0.3)
return 1; //player can still be seen on the top layer so that
// we still need to draw top layer
else
return 0; // player cannot be seen on top, skip drawing top
// layer
}
The Animation timer can move 0.1 layer each tick so that you may see the entire "fall through" sequence.
if the calculation in RECT GetPlayerInDP is correct, this method should produce a good result.
You may also add an algorithm to skip drawing the covered tiles for better performance.
Turtlenet
From what you were saying (I''m tired so I may not have understood completely) it seems like you''re saying draw the layer above the player as well. If I was going to implement the multi-layer design, I''d just draw the floor that the player is on, and the floor under them. I was thinking about drawing the lower floor first, but darkened, then drawing the layer that the player is on, skipping the tiles that are marked as completely transparent. At first I was going to try to scale the lower floor to make it a little smaller than the floor above it to try to give it a more realistic look, but I decided that since the floors would be so close it wouldn''t make much difference other than slowing down the game. Also, another thought I had was that when the player falls through one of these holes the floor the player was just on starts to fade w/ alpha blending and the lower floor starts getting brighter until the player lands. When the player lands the upper floor will have been completely alpha blended away and the lower floor will be set at the normal floor brightness. If anyone sees any problems with trying to do this, let me know. Suggestions are always welcome.
Your idea seems ok to me.
In the above post, I am not saying draw the layer above player. Just for the animated falling sequence, I divide the falling sequence to two sub-sequence.
in the first sub-sequence, we draw both layers. start drawing player on the "hole" tile, and slowly lower the player image until certain point (where you can do the alpha blending).
Now start the second sub-sequence, where you no longer draw the top layer, and the player starts somewhere above the target tile, then slower drop the image down to that tile.
The GetPlayerLayer() function is used to seperate these two sub-sequences.
you don''t have to explicitly code this two subsequences because the drawing method will automaticlly create this effect under this structure.
This is just how I did in my game, and worked pretty good so far, except I was using it for walking down/up stairs and ladders. However, I didn''t do alpha-blending when the top layer goes away. I should go ahead add it in my code for better effect
Turtlenet.
In the above post, I am not saying draw the layer above player. Just for the animated falling sequence, I divide the falling sequence to two sub-sequence.
in the first sub-sequence, we draw both layers. start drawing player on the "hole" tile, and slowly lower the player image until certain point (where you can do the alpha blending).
Now start the second sub-sequence, where you no longer draw the top layer, and the player starts somewhere above the target tile, then slower drop the image down to that tile.
The GetPlayerLayer() function is used to seperate these two sub-sequences.
you don''t have to explicitly code this two subsequences because the drawing method will automaticlly create this effect under this structure.
This is just how I did in my game, and worked pretty good so far, except I was using it for walking down/up stairs and ladders. However, I didn''t do alpha-blending when the top layer goes away. I should go ahead add it in my code for better effect
Turtlenet.
If you do draw the lower floor first completely, it will have significant influence on your speed. IMO if the layer above has only a few transparant tiles (most of the time with pitfalls) you get considerable overhead. If you don''t use any parallax or alpha blending it would be better to overlay the tile data (sort of like a mask)and draw the result.
And the price we paid was the price men have always paid for achieving paradise in this life -- we went soft, we lost our edge. - "Muad'Dib: Conversations" by the Princess Irulan
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement