2D Height Map Storage

So, after that big discussion in this thread about the ‘best’ storage method for various things, it got me thinking about a problem that I’m planning on tackling for my platformer.

Basically, when an entity is standing on the floor, he should be clamped to it, unless certain special criteria are met (The entity runs off the edge, the entity jumps, the entity runs up a slope and gathers enough vertical momentum that going over the crest allows it to overcome gravity for more than a timestep or two). To accomplish this, I’m making basically turning floors into a faux-list of tiles that the entity gets attached to and ‘slides’ across. The primary benefit of this is that if an entity is standing on static, solid ground then you shouldn’t need to do physics calculations on them to figure out whether they fall through the scenery or need to change their state, ja? Instead, you’d just need to calculate where on this list of tiles the player is, then figure out their Y position by checking the tiles in question and assigning the entity’s height based on the tiles beneath them.

Tiles have some information like height by pixel (Used to perform ‘slope’ positions), a general slope for the whole tile (Used for calculating inclination based speed) and… Other stuff that I can’t remember the importance of at this point. Hah!

I’m torn between several different alternatives for how to do this.

  1. Store all of the tiles that make up a floor area in an array (Or ArrayList), then convert the entity position into a tile position, then figure out the correct offsets from tile-edges so that I can figure out where in that tile the entity is standing.
  2. Drag all of the height information out of the tiles and into an Array (Or ArrayList) so that I can do an easy range check across the list from the left and right position of the entity (This would still require a check to the Tile list to get the slope information though).
  3. Compute height-range sets for the floor (IE- From i to j, the height is ‘y’) and iterate through them to find where the player is. (Just like 2, it’d require the check to the Tile list).

1 and 2 are my favorite options, with 1 coming out ahead, except that it requires quite a few more math ops and method calls than 2 would. Might be premature optimization there, but…

Then the question of whether an array or an ArrayList would be more suitable for these would be appreciated. The number of elements in a floor is going to be a static number that won’t be changing (In option 1 it’d be around a max of 100 with an average of 20-30, while option 2 would require the height list to be much larger).

If anyone has any other suggestions for how to accomplish this I’m all ears.

I’m having trouble figuring out what you’re trying to do (as opposed to HOW you’re trying to do it). I assume isometric maps?

Don’t know what’s the best way but in a previous project I had a Row that has an ArrayList of Columns that has an ArrayList of Pillars (height) that has an ArrayList of entities to represent each “tile/object”.

http://pastebin.java-gaming.org/642704b5318

What I value about it is its incredible flexibility and Collection methods ( binarySearch ). It’s fast as well, i.e, I haven’t been able to get it to lag. And I can “easily” only paint the tiles/objects that are visible on the screen. Actually, I’ll try and upload the full source of it to play around with next week.

Let me try to explain it again (I’ll look at your link after I finish doing this, hah.)

Basically, in the platformer that I’m writing when an entity is standing on top of something their bottom edge is ‘clamped’ to the highest point on that something between their extreme left and extreme right bounding edge (Max from Left to Right). Currently, I was figuring this out by finding the tile position (Enity.X / TileSize) and the offset (Entity.X % TileSize) for the left and right edges of the entity then finding the highest point by checking the left-most tile from offset to its right edge, and then the right-most tile from offset to its left edge (If the entity can span a tile, there’s a convenience method for just getting the max/min of the entire thing).