Sign in to follow this  
GroZZleR

Multiple Heights

Recommended Posts

Hey all, I imagine I'm just overthinking here, but what's the trick to multiple heights? I'm working on a 2D tile engine, not iso, but I imagine the concepts are more or less the same. Imagine something like this (1 = floor, 2 = second floor, B = bridge, S = stairs)
22SSS11
2211111
22BBB22
2211122
2211122
What's the trick to being able to walk under the bridge if you're on the first floor, or walk up the stairs to be on the second floor and walk over the bridge? Do you just have tiles at "level 1" and "level 2", and mark certain tiles as "moving to" level 2 or am I way off base? Ideas and articles are always welcome. EDIT: Just found an image to show what I mean: If you're one the first floor you'll walk under the bridge, but if you're on the second, you'll walk over. Now I imagine in A Link to the Past it was just a simple "climb the ladder" and you're on level 2 check, but I'm looking for something more robust with 1 or 2 or 10 stair tiles to get to the next level.

Share this post


Link to post
Share on other sites
are you asking how the collision is done or how its rendered like that or what? i'm not sure how the collision is done, possibly with some sort of per tile heightmap. but for rendering, you could have a Tile class with a std::vector<Tile_Layer> for a member. this would be all the layers that tile had. the Tile_Layer class would probably look just like your Tile class does now except maybe with some sort of flags member that would effect the whole tile (e.g SOLID or NONSOLID...). anyway, when you render, just render the map in 2 loops. render all the lower level tiles first, then the player and sprites, then all the higher level tiles. i could go into better detail but im not even sure if this was the question you were asking [smile].

EDIT: if you use this method for rendering, you could also use it for the collision. simply give your Player class an int height_level member. it would be used as an index into the Tile_Layers member of a Tile when you do collision. this way you only test collision with tiles on the same layer as you so you can walk under the bridge but when your on it, you collide with the edge of the bridge.. you could have some sort of STAIRS flag on a Tile which when a player stepped on, would increase / decrease his height_level member.

EDIT2:

you would probably have to do a little trickery to make sure you treated the other layers besides your height_level properly. for example, when your on a low level you want all tiles with layers above you to be NONSOLID. when your on the top level, you want tiles below you to be SOLID. therefore, all tiles above your height_level will be treated as NONSOLID, and all the tiles below your height_level would be treated as SOLID. all tiles equal to your height level would be either or depending on their flag obviously like any normal tile would.

if you need any of this explained better just ask.

Share this post


Link to post
Share on other sites
Lots of ways to do this...one way is to have two seperate maps...one is a regular tile map indicateing what tiles to draw where...the other is a collision map.

Additionaly create a invisable sprite class to control switches and such...also keep in mind your sprite should have a "handle location" or an screen cord offset from which the engine deturmines where to draw the sprite.

If the offset location...erm..actual screen location of the sprite is right around the bottom of the feet...changeing the Y offest value will make the sprite appear higher/lower onscreen...you can use this to your advantage

sort the sprite basied on thier actual onscreen Y value inorder to get them in the right draw order...the bridge itself can be a sprite with the correct offset to appear above the characters...then when players connect with the proper invisable trigger sprite thier actual location can be teleported to one of the other areas of the collision map, additionaly thier "handle location" is offset to reflect this move...to the player nothing would appear to happen other then the intended action...then as the new sprite "handle location" is even further offset from the feet...when sorting the sprite is drawn after the bridge, thus it appears the sprite is walking across it...another invisable sprite located in the altrnative collision section would teleport the character back restoreing the sprite handle location to it's defult location.

Course thats just one way...there are many more...

Share this post


Link to post
Share on other sites
Make your level codes powers of 2:

Level 1 = 0x01
Level 2 = 0x02
Level 3 = 0x04
Bridge = 0x08
Roof = 0x10

in your tile map, OR these together to form a tile. When your player is on one level and wants to move check the tile he wants to go to for the level flag of the level he is now on or for an accesible level.

When rendering, do passes over the map, rendering each level separately with its objects and the players.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this