Tile selecting with mouse cursor in isometric engine?
Displaying 1-8 of 8 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Buckermann

Greetings,
first I have to admit that my problem is not 100% Verge related, more a general programing question. For this I appologize, but maybe one of you can help me.

Like you can see in this screenshot (reduced to 1/2 size) I'm building a simple isometric engine for a turn-based strategy game.


The map itself is a Array[10000], for a maxium size of 100x100 tiles, and is displayed on the screen like this (the actual map size on the screen is 13x13, not 9x9). Drawing order is 8,0 - 7,0 - 6,0 -... 8,1 - 7,1 - 6,1 e.t.c.

Now I'm trying for a few days to find a way to select a tile with the mouse. But I just can't figure out how to translate the mouse coordinates into map coordinates. Anybody has some experience with iso engines?

Thanks in advance.

Posted on 2004-04-29 21:27:51

mcgrue

(this is assuming you're doing this in v3)

My advise to you: cheat.

Make an image object mirroring the full iso map in relation to it's absolute screen position. Let's call this image mouse_map. When you place the tiles, place a tile-shaped solid color area on your mouse_map with it's color set to the flat-indexing value of your coordinates.

That's be ((y*MAX_X)+x), IIRC. This'd make the [0,0] tile color 0, [1,0] color 1, [3,2] would be color 29, and [8,8] would be color 80.

So, after you've made your mirrored mouse_map, all you need to do to find the index that the mouse is on the screen, then figure out it's absolute position from there, and then

GetPixel( abs_x, abs_y, mouse_map);

Which will return the flat index of the tile, which you can then reverse engineer the iso coordinates from.

There could be better ways, but this is how I'd do it off the top of my head.

Implementing this method would require you to (these functions unchecked for accuracy):


int flatIdx(int x, int y, int yMax) {
return ((x*yMax)+y);
}

int x_from_flat( int flatval, int yMax ) {
return flatval%yMax;
}

int y_from_flat( int flatval, int yMax ) {
flatval = flatval - x_from_flat( flatval,yMax );
return flatval/yMax;
}


and then

void drawIsoShape( int x, int y, int color, int dest_im )
/*
this draws your iso shape at the apporopriate coordinates onto your destination image, the mouse_map. You would use it like:

drawIsoShape( abs_x, abs_y, flatIdx(iso_x, iso_y, iso_yMax) , mouse_map );
*/

Posted on 2004-04-29 21:44:07 (last edited on 2004-04-29 21:51:58)

mcgrue

Erm, and what do you mean 13x13, not 9x9?

Did I miss the boat entirely here?

Posted on 2004-04-30 11:11:27

Buckermann

Quote:Originally posted by mcgrue

Erm, and what do you mean 13x13, not 9x9?

Did I miss the boat entirely here?

I don't think so. I was just to lazy to draw the second image in my first post large enough to show the real size of the part of the map which is drawn on screen.


(this is assuming you're doing this in v3)

My advise to you: cheat.
[lots of good advice snipped]


Cheating? I think I like that idea
And yes, of course it is V3. I guess I should have mentioned that in my first post.

Thanks again for your help Mcgrue. As soon as I have added the tile selector function, finished the entity system and cleaned up my code, I'll upload the isoengine to the file section.

Posted on 2004-04-30 11:46:27

mcgrue

Ah, so it was useful?

Posted on 2004-04-30 12:16:45

Buckermann

Quote:Originally posted by mcgrue

Ah, so it was useful?

Of course! My tile selection function is up and running thanks to your idea. Took me a little bit of thinking to find a way how to translate the mousemap coordinates when the map is rotated, but I'm not THAT clueless .
Thanks again.

Posted on 2004-04-30 22:11:11

aen

On the topic of isometric/hex programming in general, there is a lot of good information on gamedev.net. This article in particular covers the method Grue mentioned, or at least something similar:

http://www.gamedev.net/reference/articles/article747.asp

Which is only one of many:

http://www.gamedev.net/reference/list.asp?categoryid=44

There is also a good book you could get your hands on:

http://www.amazon.com/exec/obidos/tg/detail/-/0761530894/102-4605582-2698559?v=glance

Posted on 2004-04-30 22:46:47

Buckermann

Thanks for the links Aen. Some really interresting info there.

Posted on 2004-05-02 14:09:41


Displaying 1-8 of 8 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.