[Tux4kids-commits] [SCM] tuxhistory - Educational history game branch, master, updated. 173bc249ccf495e76e0651127d1a96fdb31b7f47

julio (none) julio at julio-desktop.
Thu Jul 22 08:27:41 UTC 2010


The following commit has been merged in the master branch:
commit 173bc249ccf495e76e0651127d1a96fdb31b7f47
Author: julio <julio at julio-desktop.(none)>
Date:   Thu Jul 22 03:27:16 2010 -0500

    Mouse Mapper completed

diff --git a/src/game.c b/src/game.c
index 524c066..97e7043 100644
--- a/src/game.c
+++ b/src/game.c
@@ -290,93 +290,126 @@ static void game_handle_mouse(void)
     th_point Pmousemap;
     int i, j;
 
-    if( Pscreen.x < (map_image->w - screen->h) &&
-        Pscreen.x > 0 &&
-        Pscreen.y < (map_image->h - screen->h) &&
-        Pscreen.y > 0)
+    Pmousemap = mouse_map(Pmouse, Pscreen);
+    if(Pmousemap.x != -1 && Pmousemap.y != -1)
     {
-        // Is the mouse close to the border? Move the
-        // map...
-        if(Pmouse.x < screen_margin_in && Pscreen.x > IN_SCROLL){
-            Pscreen.x = Pscreen.x - IN_SCROLL;
-        }
-        if(Pmouse.x > screen->w - screen_margin_in &&
-           (Pscreen.x + screen->w) < (map_image->w - IN_SCROLL)){
-            Pscreen.x = Pscreen.x + IN_SCROLL;
-        }
-        if(Pmouse.y < screen_margin_in && Pscreen.y > IN_SCROLL){
-            Pscreen.y = Pscreen.y - IN_SCROLL;
-        }
-        if(Pmouse.y > screen->h - screen_margin_in &&
-                (Pscreen.y + screen->h) < (map_image->h - IN_SCROLL)){
-            Pscreen.y = Pscreen.y + IN_SCROLL;
-        }
+        select_rect.x = gmaps[0][Pmousemap.x][Pmousemap.y].rect.x - Pscreen.x; 
+        select_rect.y = gmaps[0][Pmousemap.x][Pmousemap.y].rect.y - Pscreen.y;
+        printf("Draw select: %d %d ", select_rect.x, select_rect.y);
+    
 
-        // Is the mouse VERY close to the border?
-        // Move the map faster!
-        if(Pmouse.x < screen_margin_out && Pscreen.x > OUT_SCROLL){
-            Pscreen.x = Pscreen.x - OUT_SCROLL;
-        }
-        if(Pmouse.x > screen->w - screen_margin_out &&
-           (Pscreen.x + screen->w) < (map_image->w - OUT_SCROLL)){
-            Pscreen.x = Pscreen.x + OUT_SCROLL;
-        }
-        if(Pmouse.y < screen_margin_out && Pscreen.y > OUT_SCROLL){
-            Pscreen.y = Pscreen.y - OUT_SCROLL;
-        }
-        if(Pmouse.y > screen->h - screen_margin_out &&
-                (Pscreen.y + screen->h) < (map_image->h - OUT_SCROLL)){
-            Pscreen.y = Pscreen.y + OUT_SCROLL;
+        if( Pscreen.x < (map_image->w - screen->h) &&
+            Pscreen.x > 0 &&
+            Pscreen.y < (map_image->h - screen->h) &&
+            Pscreen.y > 0)
+        {
+            // Is the mouse close to the border? Move the
+            // map...
+            if(Pmouse.x < screen_margin_in && Pscreen.x > IN_SCROLL){
+                Pscreen.x = Pscreen.x - IN_SCROLL;
+            }
+            if(Pmouse.x > screen->w - screen_margin_in &&
+                (Pscreen.x + screen->w) < (map_image->w - IN_SCROLL)){
+                Pscreen.x = Pscreen.x + IN_SCROLL;
+            }
+            if(Pmouse.y < screen_margin_in && Pscreen.y > IN_SCROLL){
+                Pscreen.y = Pscreen.y - IN_SCROLL;
+            }
+            if(Pmouse.y > screen->h - screen_margin_in &&
+                    (Pscreen.y + screen->h) < (map_image->h - IN_SCROLL)){
+                Pscreen.y = Pscreen.y + IN_SCROLL;
+            }
+
+            // Is the mouse VERY close to the border?
+            // Move the map faster!
+            if(Pmouse.x < screen_margin_out && Pscreen.x > OUT_SCROLL){
+                Pscreen.x = Pscreen.x - OUT_SCROLL;
+            }
+            if(Pmouse.x > screen->w - screen_margin_out &&
+            (Pscreen.x + screen->w) < (map_image->w - OUT_SCROLL)){
+                Pscreen.x = Pscreen.x + OUT_SCROLL;
+            }
+            if(Pmouse.y < screen_margin_out && Pscreen.y > OUT_SCROLL){
+                Pscreen.y = Pscreen.y - OUT_SCROLL;
+            }
+            if(Pmouse.y > screen->h - screen_margin_out &&
+                    (Pscreen.y + screen->h) < (map_image->h - OUT_SCROLL)){
+                Pscreen.y = Pscreen.y + OUT_SCROLL;
+            }
         }
     }
 
-    Pmousemap = mouse_map(Pmouse, Pscreen);
-    select_rect.x = ((Pmousemap.x * terrain[0]->w) - terrain[0]->w/2)-Pscreen.x;
-    select_rect.y = (Pmousemap.y * terrain[0]->h)-Pscreen.y;
 }
-/*
-static th_point generate_mousemap(th_point mouse_p, th_point screen_p)
+
+Uint32 get_pcolor(SDL_Surface *surface, int x, int y)
 {
-    int i, j;
-    int **anchor_map;
-    th_point point;
-
-    for(point.x = terrain[TUNDRA_CENTER_1]->w/2; 
-        point.x <= map_image->w;
-        point.x = point.x + terrain[0]->w){
-        for(j = 0; j <= y_tildes; i++){
-            if((mouse_p.x + screen_p.x) < gmap[0][i][j].anchor &&
-               (mouse_p.x + screen_p.x + terrain[TUNDRA_CENTER_1]->w) > gmap[0][i][j].anchor &&
-               (mouse_p.x + screen_p.x) < gmap[0][i][j].anchor &&
-               (mouse_p.x + screen_p.x + terrain[TUNDRA_CENTER_1]->w) > gmap[0][i][j].anchor)
-            {
-            }
-        }
-    }
-    point.x = (int)(mouse_p.x + screen_p.x + terrain[TUNDRA_CENTER_1]->w/2)/terrain[TUNDRA_CENTER_1]->w;
-    point.y = (int)(mouse_p.y + screen_p.y)/terrain[TUNDRA_CENTER_1]->h;
-    //printf("Mouse Maping: %d, %d\n", Pmousemap.x, Pmousemap.y);
-    return point;
-    }*/
+    Uint32 *pixels = (Uint32 *)surface->pixels;
+    return pixels[ ( y * surface->w ) + x ];
+}
 
 
+// TODO: This function should be in map.c
+//       give the mouse point and the creen point as arguments 
+//       and returns the actual tile in ***gmaps
 static th_point mouse_map(th_point mouse_p, th_point screen_p)
 {
     int i, j;
     int terr_e;
+    Uint32 color;
+    Uint32 iso_colors[4];
     th_point *anchor_p;
     th_point Pmousemap;
+    th_point Ptilemap;
 
     Pmousemap.x = (int)(mouse_p.x + screen_p.x + terrain[TUNDRA_CENTER_1]->w/2)/terrain[TUNDRA_CENTER_1]->w;
     Pmousemap.y = (int)(mouse_p.y + screen_p.y)/terrain[TUNDRA_CENTER_1]->h;
     
+    Ptilemap.x = (int)(mouse_p.x + screen_p.x + terrain[TUNDRA_CENTER_1]->w/2)%terrain[TUNDRA_CENTER_1]->w;
+    Ptilemap.y = (int)(mouse_p.y + screen_p.y)%terrain[TUNDRA_CENTER_1]->h;
+    
+
     anchor_p = &anchor_map[Pmousemap.x][Pmousemap.y];
     if(anchor_p->x != -1 && anchor_p->y != -1)
         terr_e = gmaps[0][anchor_p->x][anchor_p->y].terrain;
     else
         terr_e = -1;
 
-    printf("Mouse Maping: %d, %d Terrain %d\n", Pmousemap.x, Pmousemap.y, terr_e);
+
+    Pmousemap.x = anchor_p->x;
+    Pmousemap.y = anchor_p->y; 
+
+    iso_colors[1] = get_pcolor(images[IMG_ISOMAPPER], 2, 2);
+    iso_colors[2] = get_pcolor(images[IMG_ISOMAPPER], images[IMG_ISOMAPPER]->w-2, 2);
+    iso_colors[3] = get_pcolor(images[IMG_ISOMAPPER], 2 , images[IMG_ISOMAPPER]->h-2);
+    iso_colors[4] = get_pcolor(images[IMG_ISOMAPPER], images[IMG_ISOMAPPER]->w-2, images[IMG_ISOMAPPER]->h-2);
+
+    color = get_pcolor(images[IMG_ISOMAPPER], Ptilemap.x, Ptilemap.y);
+
+
+    // NW
+    if(color == iso_colors[1])
+    {
+        Pmousemap.x--;
+    }
+    //NE
+    if(color == iso_colors[2])
+    {
+        Pmousemap.y--;
+    }
+    //SW
+    if(color == iso_colors[3])
+    {
+        Pmousemap.y++;
+    }
+    //SE
+    if(color == iso_colors[4])
+    {
+        //Pmousemap.y++;
+        Pmousemap.x++;
+    }
+
+    printf("Mouse Maping: %d, %d Terrain: %d Color: %d\n", Pmousemap.x, Pmousemap.y, terr_e, color);
+
     return Pmousemap;
 }
 
diff --git a/src/graphs.h b/src/graphs.h
index 79b4ef5..e47acc6 100644
--- a/src/graphs.h
+++ b/src/graphs.h
@@ -14,6 +14,7 @@
 #ifndef GRAPHS_H
 #define GRAPHS_H
 
+#include "SDL.h"
 #include "globals.h"
 #include "objects.h"
 #include "map.h"
@@ -33,6 +34,7 @@ enum
 
 typedef struct gnode{
     int id;
+    th_point rect;
     th_point anchor; //Anchors in main map surface.
     int visible;
     int explored;
diff --git a/src/map.c b/src/map.c
index 7022784..38100ca 100644
--- a/src/map.c
+++ b/src/map.c
@@ -552,7 +552,7 @@ int generate_anchormap(void)
     int x, y;
     int i,j;
     int ii, jj;
-    x = (int)((map_image->w - terrain[0]->h/2) / terrain[0]->w);
+    x = (int)((map_image->w - terrain[0]->w/2) / terrain[0]->w) + 2;
     y = (int)(map_image->h / terrain[0]->h);
 
     printf("Grid size: %d %d\n", x, y);
@@ -581,12 +581,12 @@ int generate_anchormap(void)
             anchor_map[i][j].y = -1;
             //printf("X Point: %d ", terrain[0]->w*i);
             //printf("Y Point: %d\n", terrain[0]->h*j);
-            for(ii = 0; ii < x_tildes; ii++)
+            for(ii = 0; ii <= x_tildes; ii++)
             {
-                for(jj = 0; jj < y_tildes; jj++)
+                for(jj = 0; jj <= y_tildes; jj++)
                 {
-                    if( gmaps[0][ii][jj].anchor.x > (terrain[0]->w*i) - terrain[0]->h/2&&
-                        gmaps[0][ii][jj].anchor.x < (terrain[0]->w*i + terrain[0]->w) - terrain[0]->h/2&&
+                    if( gmaps[0][ii][jj].anchor.x > (terrain[0]->w*i) - terrain[0]->w/2&&
+                        gmaps[0][ii][jj].anchor.x < (terrain[0]->w*i + terrain[0]->w) - terrain[0]->w/2&&
                         gmaps[0][ii][jj].anchor.y > (terrain[0]->h*j) &&
                         gmaps[0][ii][jj].anchor.y < (terrain[0]->h*j + terrain[0]->h))
                     {
@@ -606,6 +606,7 @@ endineriter:
     }
     return 0;
 }
+
 void free_anchormap(void)
 {
     int i;
@@ -688,10 +689,13 @@ int generate_map(void)
             anchor.x = dest.x + terrain[*img_enums]->w/2;
             anchor.y = dest.y + terrain[*img_enums]->h/2;
 
+
             printf(" Tile dest in px: (%d,%d) from: (%d,%d) with anchori (%d,%d)\n", 
                     dest.x, dest.y, i, j, anchor.x, anchor.y);
 
             gmaps[0][i][j].anchor = anchor;
+            gmaps[0][i][j].rect.x = dest.x;
+            gmaps[0][i][j].rect.y = dest.y;
             
             // TODO: This is better in graph.h
             if(map[i][j].terrain == HIGHSEA ||

-- 
tuxhistory - Educational history game



More information about the Tux4kids-commits mailing list