Hey everyone-
I just started working on my first isometric game (ganja farmer II if anyone cares) and have run into a bit of a mental block. Basically my problem is converting screen coordinates to map coordinates, but it may be something deeper. I looked around and found a few pages on how to do it, but i think these people's engines are storing/drawing their maps differently than mine anyway.... So my tiles are stored in a 2D array: tile[x][y] and I draw them by plotting the first row of tiles, then offsetting the next row, then back for the next, and so on:
div_t testit = div(y,2);
if (testit.rem==1) add_x=40;
tile_graphics.x=levelmap.origin_x+(x*80)+add_x;
tile_graphics.y=levelmap.origin_y+(y*20)-100;
tile_graphics.curr_frame=levelmap.tile[x] [y].graphic_num+levelmap.tile[x][y].curr_frame;
the bases of my tiles are all 80 X 40 but for right now all my graphics are 80 X 120 hence the -100...anyway so this draws my tiles fine, is simple to index and yields me a world that's indexed like this:
0,0 1,0 2,0 3,0
0,1 1,1 2,1 3,1
0,2 1,2 2,2 3,2
0,3 1,3 2,3 3,3
ok...so I try to apply Jim Adam's cute little formula conversion the
xo=xscreen;
yo=yscreen;
xfine=yo +(xo/2);
yfine=yo -(xo/2);
mapx=xfine/40; //in my case
mapy=yfine/40;
However this indexes my map like so...
0,0 1,-1 2,-2 3,-3
1,0 2,-1 3,-2 4,-3
1,1 2,0 3,-1 4,-2
2,1 3,0 4,-1 5,-2
Anyway..this is a perfect representation of isometric map space, but has diddly squat to do with my 2D array. How the hell should I convert back to my 2d array space from this indexing system?
The other method I tried was tanstaafl's little rectangle idea, but I ran into a problem with that, his DX-DY table only works with even values of Y, when y is odd you get the wrong answer, at least for my map, you have to flip the corners diagonally for odd y's and then it works, but this just seems clumsy. Am I totally missing something? Should this be so damn hard? Should I be drawing/indexing my tile array differently, more in line with true iso space? HELP!!!!!!
-Jason
______________________________
http://www.evilx.com
______________________________
Edited by - EvilX_Systems on April 3, 2001 1:46:23 PM
______________________________http://www.evilx.com______________________________