Jump to content

  • Log In with Google      Sign In   
  • Create Account

Chris Burrows

Member Since 17 Sep 2012
Offline Last Active Jul 06 2016 03:09 AM

#4981971 Representing an iso map in a 2d array?

Posted by on 20 September 2012 - 03:36 AM

no need for negative array indices; not sure where you got that idea

As I said originally, I require the entire visible map to be covered with tiles. Using a traditional square grid on a tilted on a 30 degree angle means that there are going to be tiles with negative array indices, shown in black.

Posted Image

Unless however, the (0,0) index is far off to the left somewhere, seemingly the preferred method. In the image below, the green rectangle depicts the desired visible map, it also shows the array co-ordinates within the map using the staggered approach. The giant blue rhombus, demonstrates the size of a tilted array required to cover the same size map with tiles.

Posted Image

As you can see, using the staggered approach cuts the size of the array in half, but as FLeBlanc mentioned, this is unlikely to have any impact on performance. Personally, I prefer the staggered approach for it's elegance. Positioning the tiles on screen is simple:

X co-ordinate: (X index * Tile width) + ((Y index mod 2) * ( Tile width / 2))
Y co-ordinate: Y index * (Tile height / 2)

I've already coded the pathfinding and movement with a staggered grid (here is a demo if anybody is interested), but I haven't come much further than that. I think I'll head the advice and re-write with the (0,0) offset method. Thanks for the help.

But your world representation does not have to be an array.

What other choices do I have? Hash table? My pathfinding code is pretty dependant on arrays, but I'm always open to suggestions...