Java-Gaming.org
 Featured games (81) games approved by the League of Dukes Games in Showcase (497) Games in Android Showcase (114) games submitted by our members Games in WIP (563) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 2D Height Map Storage  (Read 1532 times) 0 Members and 1 Guest are viewing this topic.
UprightPath
 « Posted 2012-07-20 23:57:22 »

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.

jonjava
 « Reply #1 - Posted 2012-07-21 21:37:52 »

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.

UprightPath
 « Reply #2 - Posted 2012-07-21 21:50:52 »

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).

Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 Add your game by posting it in the WIP section, or publish it in Showcase. The first screenshot will be displayed as a thumbnail.
 UprightPath (5 views) 2014-09-20 20:14:06 BurntPizza (26 views) 2014-09-19 03:14:18 Dwinin (40 views) 2014-09-12 09:08:26 Norakomi (70 views) 2014-09-10 13:57:51 TehJavaDev (95 views) 2014-09-10 06:39:09 Tekkerue (49 views) 2014-09-09 02:24:56 mitcheeb (70 views) 2014-09-08 06:06:29 BurntPizza (52 views) 2014-09-07 01:13:42 Longarmx (39 views) 2014-09-07 01:12:14 Longarmx (45 views) 2014-09-07 01:11:22
 BurntPizza 36x Riven 18x Rayvolution 18x basil_ 16x ags1 16x princec 16x KevinWorkman 15x LiquidNitrogen 12x kevglass 11x deathpat 11x nsigma 11x theagentd 11x HeroesGraveDev 8x The Lion King 7x Gibbo3771 6x cylab 6x
 List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27Resources for WIP games2014-08-01 16:20:17Resources for WIP games2014-08-01 16:19:50List of Learning Resources2014-07-31 16:29:50List of Learning Resources2014-07-31 16:26:06List of Learning Resources2014-07-31 11:54:12HotSpot Optionsby dleskov2014-07-08 01:59:08
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org