Advertisement

Determining color of mousemap?

Started by August 19, 2000 04:15 PM
2 comments, last by epic709 24 years, 4 months ago
Hi, I''ve half-way implemented "Mouse Matters" according to TANSTAAFL''s Iso & Hex Maps Part 1. The problem right now is the line that says so ambiguously: Third Step: Determine the color in the MouseMap at (MouseMapX,MouseMapY). What I''ve done right now only checks certain parts of the mouse map since I can''t figure out how to check triangular areas. In ASCII art, this would look like this: ________ |R|/\|Y| |/|WW|\| |\|WW|/| |G|\/|B| -------- So, if u understand the obscure doodle above, I''m now only checking part of the red(R) area and leaving out two triangular areas (to the right & to the bottom). And so on.... It has also occured to me that certain coordinates would conflict. Assuming the mousemap is 64*32, coordinates (16,8) could either be red or white. This goes on for all the coordinates that are borders between 2 colors. The 4 vertices of the white diamond are worse - could be either red, yellow or white e.g. for the top vertex. My code goes like this:
    
if ((mouseMapX >= 0) && (mouseMapX <= 16)) {
   // red

   if ((mouseMapY >= 0) && (mouseMapY <= 8)) {
      regionDX = -1;
      regionDY = -1;
   }
   // green

   else if ((mouseMapY >= 24) && (mouseMapY == 32)) {
      regionDX = -1;
      regionDY = 1;
   }
}
	
if ((mouseMapX >= 48) && (mouseMapX <= 64)) {
   // yellow

   if ((mouseMapY >= 0) && (mouseMapY == 8)) {
      regionDX = 0;
      regionDY = -1;
   }
   else if ((mouseMapY >= 24) && (mouseMapY == 32)) {
      regionDX = 0;
      regionDY = 1;
   }
}
	   
// white

if ((mouseMapX >= 16) && (mouseMapX <= 48)) {
   if ((mouseMapY >= 8) && (mouseMapY == 24)) {
      regionDX = 0;
      regionDY = 0; 
   }
}
    
If anyone has an ingenius solution to my mousemapping woes, please enlighten me. Hope TANSFAAFL reads this...... Thanx in advance.
OK, you''ve got it half done (as you said yourself)

1. Using a Mousemap bitmap

Get the colour of the pixel at MouseMapx, MouseMapY and then run this colour though a switch statement. Since the bitmap will be created with the tile in it correctly there is no problems with the mouse position

2. Using code

I''m not sure, but using a hard coded array and doing the above would be fine.

Of the two options the second one uses less memory, while the first is easier to update for different tile sizes. There is a third option and that is to use a proper algorithm, but I''m not good enough with maths to work it out. Given time you should opt for the third option, but to get past the initial hurdle use option 1.

if you look at TANSTAAFL''s tutorial he shows you exactly what the bitmap would look like, so create one of these the same size as your tiles, or take a tile that is flat, i.e. nothing drawn over the iso tile edges, and re-colour it to match TANSAAFL''s article you can use it to be the maouse map bitmap for your code.
When I find my code in tons of trouble,Friends and colleages come to me,Speaking words of wisdom:"Write in C."My Web Site
Advertisement
ok, I think I''ll go with option 1.
so this involves processing a bitmap loaded in memory right? I never thought of it that way - I thought the mouse map was just this abstraction to understand the whole thing. I''ve never gotten around to bitmap surface manipulations but I think the rough idea is to Lock/Unlock the surface containing it? Please correct me if I''m wrong. Could somebody give me a rough idea or pseudocode on the whole process? I don''t have much time and I''m pretty desperate to make some progress.

I think I could continue with my present hard-coded - apparently very efficient according to Steven - method by creating a [64][32] array in memory that stores the color for each subscript by reading in a value (either R, Y, G, B or W) stored in a text file. Then I just continue with the all-important switch statement. Any comments?

Thanks again.
the way i do my mousemaps:

i have a bitmap, or some other type of graphic that i load in.

i scan the bitmap, and place constant values for each of the colors in the map.(usually, i make some sort of enum). i also store the width and height of the mousemap.

i then delete the bitmap, and work from the array.

Get off my lawn!

This topic is closed to new replies.

Advertisement