Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 3013 times)
0 Members and 1 Guest are viewing this topic.
Offline 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.

Offline 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".

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

EgonOlsen (78 views)
2018-06-10 19:43:48

EgonOlsen (58 views)
2018-06-10 19:43:44

EgonOlsen (78 views)
2018-06-10 19:43:20

DesertCoockie (260 views)
2018-05-13 18:23:11

nelsongames (158 views)
2018-04-24 18:15:36

nelsongames (157 views)
2018-04-24 18:14:32

ivj94 (898 views)
2018-03-24 14:47:39

ivj94 (162 views)
2018-03-24 14:46:31

ivj94 (811 views)
2018-03-24 14:43:53

Solater (175 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!