[Tux4kids-commits] [SCM] tuxhistory - Educational history game branch, master, updated. 6d8a452f0beb262c41505c59dc9cdded505c2b2f

julio (none) julio at julio-desktop.
Thu Jul 22 06:43:25 UTC 2010


The following commit has been merged in the master branch:
commit 6d8a452f0beb262c41505c59dc9cdded505c2b2f
Author: julio <julio at julio-desktop.(none)>
Date:   Thu Jul 22 01:42:56 2010 -0500

    Advances in mouse mapping...

diff --git a/data/images/others/Makefile.am b/data/images/others/Makefile.am
index 76d2c1e..be541ac 100644
--- a/data/images/others/Makefile.am
+++ b/data/images/others/Makefile.am
@@ -4,4 +4,5 @@
 
 othersdir = $(pkgdatadir)/images/others
 
-dist_others_DATA = isomapper.png
+dist_others_DATA = isomapper.png \
+select.png
diff --git a/src/fileops.h b/src/fileops.h
index 1aff488..be25dcc 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -69,6 +69,8 @@ enum {
   IMG_NUMBERS,
   IMG_GAMEOVER,
   IMG_GAMEOVER_WON,
+  IMG_ISOMAPPER,
+  IMG_ISOSELECT,
   NUM_IMAGES
 };
 
diff --git a/src/fileops_media.c b/src/fileops_media.c
index cca6ca4..9ce0053 100644
--- a/src/fileops_media.c
+++ b/src/fileops_media.c
@@ -61,6 +61,8 @@ int load_image_data()
   "status/numbers.png",
   "status/gameover.png",
   "status/gameover_won.png",
+  "others/isomapper.png",
+  "others/select.png"
   };
 
 
diff --git a/src/game.c b/src/game.c
index 5bec4e3..524c066 100644
--- a/src/game.c
+++ b/src/game.c
@@ -71,6 +71,7 @@ static SDL_Surface* scaled_bkgd = NULL; //native resolution (fullscreen)
 
 // Game vars
 static SDL_Rect origin;
+static SDL_Rect select_rect;
 static int screen_x;
 static int screen_y;
 
@@ -274,6 +275,8 @@ static void game_draw(void)
             obj_node = obj_node->next;
         }while(obj_node != NULL);
     }
+
+    SDL_BlitSurface(images[IMG_ISOSELECT], NULL, screen, &select_rect);
    
     /*Third layer: User Interface*/
     dest.x = (screen->w - images[IMG_STOP]->w - 5);
@@ -285,6 +288,7 @@ static void game_draw(void)
 static void game_handle_mouse(void)
 {
     th_point Pmousemap;
+    int i, j;
 
     if( Pscreen.x < (map_image->w - screen->h) &&
         Pscreen.x > 0 &&
@@ -325,15 +329,54 @@ static void game_handle_mouse(void)
             Pscreen.y = Pscreen.y + OUT_SCROLL;
         }
     }
-    mouse_map(Pmouse, Pscreen);
+
+    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)
+{
+    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;
+    }*/
+
 
 static th_point mouse_map(th_point mouse_p, th_point screen_p)
 {
+    int i, j;
+    int terr_e;
+    th_point *anchor_p;
     th_point Pmousemap;
+
     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;
-    printf("Mouse Maping: %d, %d\n", Pmousemap.x, Pmousemap.y);
+    
+    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);
     return Pmousemap;
 }
 
diff --git a/src/map.c b/src/map.c
index 6ff9e6b..7022784 100644
--- a/src/map.c
+++ b/src/map.c
@@ -547,6 +547,73 @@ static int get_tile_num(int i, int k)
     else return -1;
 }
 
+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);
+    y = (int)(map_image->h / terrain[0]->h);
+
+    printf("Grid size: %d %d\n", x, y);
+    anchor_map = (th_point **)malloc(x * sizeof(th_point *));
+    
+    if(anchor_map == NULL)
+    {
+        printf("Error: out of memory!\n");
+        return 1;
+    }
+
+    for(i=0;i<x;i++)
+    {
+        anchor_map[i] = (th_point *)malloc(y * sizeof(th_point));
+        if(anchor_map[i] == NULL)
+        {
+            printf("Error: out of memoy!\n");
+            return 1;
+        }
+    }
+    for(i = 0; i < x; i++)
+    {
+        for(j = 0; j < y; j++)
+        {
+            anchor_map[i][j].x = -1;
+            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(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&&
+                        gmaps[0][ii][jj].anchor.y > (terrain[0]->h*j) &&
+                        gmaps[0][ii][jj].anchor.y < (terrain[0]->h*j + terrain[0]->h))
+                    {
+                        anchor_map[i][j].x = ii;
+                        anchor_map[i][j].y = jj;
+                        goto endineriter;
+                    }
+                }
+            }
+endineriter:
+            if(anchor_map[i][j].x != -1 && anchor_map[i][j].y != -1)
+                printf("%d", gmaps[0][i][j].terrain);
+            else
+                printf("-");
+        }
+        printf("\n");
+    }
+    return 0;
+}
+void free_anchormap(void)
+{
+    int i;
+    for(i = 0; i < (int)(map_image->w / terrain[0]->w); i++)
+        FREE(anchor_map[i]);
+    FREE(anchor_map);
+}
+
 int generate_map(void)
 {
     SDL_Surface* orig = NULL;
@@ -639,6 +706,7 @@ int generate_map(void)
 
             gmaps[0][i][j].terrain = map[i][j].terrain;
 
+
             //Prepare te new coords for the next tile
             dest.x = dest.x - (terrain[*img_enums]->w/2);
             dest.y = dest.y + (terrain[*img_enums]->h/2);
@@ -659,11 +727,15 @@ int generate_map(void)
             k++;
     }
 
+    // Optimizing img_map
     orig = map_image;
 
     SDL_SetAlpha(orig, SDL_RLEACCEL, SDL_ALPHA_OPAQUE);
     map_image = SDL_DisplayFormat(orig); /* optimize the format */
     SDL_FreeSurface(orig);
+    
+    // Create a anchors map and allocates int **anchor_map
+    generate_anchormap(); 
 
     return 0;
 }
diff --git a/src/map.h b/src/map.h
index df29deb..636512f 100644
--- a/src/map.h
+++ b/src/map.h
@@ -38,6 +38,7 @@ typedef struct th_map{
     //int obj_id;
 }th_map;
 
+th_point **anchor_map;
 struct hashtable *map_table_hash; //Values of Terrains and objects
 int flag_map; // Map flag: is a map surface allocated? 
 int x_tildes;
@@ -62,4 +63,7 @@ void th_draw_map(void);
 
 th_vector get_vector(th_point point, int iso_dir);
 
+int generate_anchormap(void);
+void free_anchormap(void);
+
 #endif

-- 
tuxhistory - Educational history game



More information about the Tux4kids-commits mailing list