Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  2D Height Map Storage  (Read 1479 times)
0 Members and 1 Guest are viewing this topic.
Offline UprightPath
« Posted 2012-07-21 01: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.

Offline jonjava
« Reply #1 - Posted 2012-07-21 23: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.

Offline UprightPath
« Reply #2 - Posted 2012-07-21 23: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.

pw (25 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (19 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (56 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!