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

julio (none) julio at julio-desktop.
Tue Aug 3 19:07:42 UTC 2010


The following commit has been merged in the master branch:
commit d7cda4ea434cfb7443bec703d65cead94299281e
Author: julio <julio at julio-desktop.(none)>
Date:   Tue Aug 3 14:06:48 2010 -0500

    Player can now select objects

diff --git a/src/SDL_extras.c b/src/SDL_extras.c
index 7f04486..3e245b3 100644
--- a/src/SDL_extras.c
+++ b/src/SDL_extras.c
@@ -1252,3 +1252,34 @@ void draw_rect(SDL_Surface* surface, SDL_Rect rect)
     tmp_rect.h = rect.h;
     draw_line(surface, tmp_rect, 255, 255, 255);
 }
+
+void FillRect(SDL_Rect rect, int color) 
+{
+    SDL_FillRect(screen, &rect, color);
+}
+
+void th_ShowMessage(char* str, int size, int x, int y)
+{
+  SDL_Surface *s;
+  SDL_Rect loc;
+
+  s = NULL;
+
+  if (str)
+    s = BlackOutline(str, size, &white);
+
+  /* Draw lines of text (do after drawing Tux so text is in front): */
+  if (s)
+  {
+    loc.x = x; 
+    loc.y = y;
+    SDL_BlitSurface( s, NULL, screen, &loc);
+  }
+
+  /* and update: */
+  //SDL_UpdateRect(screen, 0, 0, 0, 0);
+
+  SDL_FreeSurface(s);
+}
+
+
diff --git a/src/SDL_extras.h b/src/SDL_extras.h
index c39eeee..fdf417b 100644
--- a/src/SDL_extras.h
+++ b/src/SDL_extras.h
@@ -59,5 +59,7 @@ Uint32          get_pcolori(SDL_Surface *surface, int x, int y);
 void            draw_line(SDL_Surface* surface, SDL_Rect rect, int red, int grn, int blu);
 void            putpixel(SDL_Surface* surface, int x, int y, Uint32 pixel);
 void            draw_rect(SDL_Surface* surface, SDL_Rect rect);
+void            FillRect(SDL_Rect rect, int color); 
 
+void th_ShowMessage(char* str, int size, int x, int y);
 #endif
diff --git a/src/game.c b/src/game.c
index e9e6d2c..b63f2d0 100644
--- a/src/game.c
+++ b/src/game.c
@@ -74,6 +74,7 @@ static SDL_Surface* scaled_bkgd = NULL; //native resolution (fullscreen)
 static SDL_Rect origin;
 static int screen_x;
 static int screen_y;
+static rts_vars selection;
 
 static th_point Pscreen;
 static int screen_margin_in;
@@ -90,6 +91,7 @@ typedef struct io_vars
     SDL_Rect select_xy;
     SDL_Rect select_rect;
     SDL_Rect select_rect_dest;
+    SDL_Rect select;
     th_point go_xy;
     SDL_Rect go_rect;
     SDL_Rect go_rect_dest;
@@ -214,6 +216,7 @@ static void game_draw(void)
 {
     SDL_Rect dest;
     list_node *obj_node;
+    char tmp_text[50];
 
     origin.x = Pscreen.x;
     origin.y = Pscreen.y;
@@ -245,6 +248,21 @@ static void game_draw(void)
                 dest.y = gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.y - 
                     origin.y - objects[obj_node->obj.name_enum]->h/2;
                 SDL_BlitSurface(objects[obj_node->obj.name_enum], NULL, screen, &dest);
+
+                // Is the any object selected?
+                if(selection.selected_num != -1)
+                {
+                    if(selection.selected_objs[0] != NULL)
+                    {
+                        if(obj_node->obj.id == selection.selected_objs[0]->id)
+                        {
+                            dest.w = dest.x + objects[obj_node->obj.name_enum]->w;
+                            dest.h = dest.y;
+
+                            draw_line(screen, dest, 0,255,0);
+                        }
+                    }
+                }
              }
             obj_node = obj_node->next;
         }while(obj_node != NULL);
@@ -271,12 +289,39 @@ static void game_draw(void)
    
     /*Third layer: User Interface*/
 
-    //TODO: Write a panel function to manipulate teh game...
+    //TODO: Write a panel function to manipulate the game...
     
     dest.x = 0;
     dest.y = (screen->h / 5) * 4;
     SDL_BlitSurface(images[IMG_GUIBG_BYZANTINE], NULL, screen, &dest);
     
+    if(selection.selected_num != -1)
+    {
+        if(selection.selected_objs[0] != NULL)
+        {
+            dest.x = dest.x + 10;
+            dest.y = dest.y + 10;
+            dest.h = 100;
+            dest.w = screen->w / 5;
+            //FillRect(dest, 0x000000);
+
+            dest.x = dest.x + 2;
+            dest.y = dest.y + 2;
+            th_ShowMessage(selection.selected_objs[0]->rname, 12, dest.x+2, dest.y+2);
+
+            sprintf(tmp_text,"%d / %d", selection.selected_objs[0]->actual_live,
+                                        selection.selected_objs[0]->live);
+            th_ShowMessage(tmp_text, 15, 
+                    objects[selection.selected_objs[0]->name_enum]->w + dest.x + 10, dest.y+20);
+
+
+
+            dest.y = dest.y + 20;
+
+            SDL_BlitSurface(objects[selection.selected_objs[0]->name_enum], NULL, screen, &dest);
+        }
+    }
+
     dest.x = (screen->w - mini_map_image->w - 5);
     dest.y = (screen->h - mini_map_image->h - 5);
     SDL_BlitSurface(mini_map_image, NULL, screen, &dest);
@@ -286,12 +331,12 @@ static void game_draw(void)
     dest.y = glyph_offset;
     SDL_BlitSurface(images[IMG_STOP], NULL, screen, &dest);
 
-    dest.x = 20;
+    /*dest.x = 20;
     dest.y = 20;
     dest.h = 100;
     dest.w = 100;
 
-    draw_rect(screen, dest);
+    draw_rect(screen, dest);*/
 
 }
 
@@ -362,9 +407,11 @@ static void game_handle_mouse(void)
     }
     if(io.mousedown_flag != 0)
     {
-        printf("Mouse down, ... ");
+        //printf("Mouse down, ... ");
         if(io.mouseclicked_flag != 0)
         {
+            //io.select.x = Plclick.x;
+            //io.select.y = Plclick.y; 
             Pmousemap = mouse_map(io.Plclick, Pscreen);
             if(Pmousemap.x != -1 && Pmousemap.y != -1)
             {
@@ -373,7 +420,21 @@ static void game_handle_mouse(void)
                 io.select_rect.y = gmaps[0][Pmousemap.x][Pmousemap.y].rect.y;
                 io.select_xy.x = Pmousemap.x;
                 io.select_xy.y = Pmousemap.y;
-                printf("Draw select: %d %d \n", io.select_rect.x, io.select_rect.y);
+
+                // Search for a object in current selected tile and
+                // select that object
+
+                selection.selected_objs[0]=rts_get_object(0,Pmousemap);
+                if(selection.selected_objs[0] != NULL)
+                {
+                    selection.selected_num = 0;
+                    printf("Selected: %s\n", selection.selected_objs[0]->name);
+                }
+                else
+                {
+                    selection.selected_num = -1;
+                }
+                
             }
         }
     }
@@ -384,7 +445,7 @@ static void game_handle_mouse(void)
         {
             io.go_rect.x = gmaps[0][Pmousemap.x][Pmousemap.y].rect.x; 
             io.go_rect.y = gmaps[0][Pmousemap.x][Pmousemap.y].rect.y;
-            printf("Go select: %d %d ", io.go_rect.x, io.go_rect.y);
+            //printf("Go select: %d %d ", io.go_rect.x, io.go_rect.y);
             io.mousedownr_flag = 0;
             if( io.go_rect.x > Pscreen.x &&
                 io.go_rect.x < Pscreen.x + screen->w &&
diff --git a/src/objects.c b/src/objects.c
index 1cdc1ca..9868968 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -134,6 +134,7 @@ int objects_xml(FILE *fp)
         if(atoi(node->child->value.opaque) >= 0)
         {
             object[i].live = atoi(node->child->value.opaque);
+            object[i].actual_live = object[i].live;
         }
         else
         {
diff --git a/src/objects.h b/src/objects.h
index 9b5d7b8..ca411a3 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -17,7 +17,8 @@ typedef struct th_obj{
     int id;
     int x, y; // (x,y) in the th_map array
     int type; // using the enum NUM_OF_TYPES of map.h
-    int live; // 100 to 0 
+    int live; 
+    int actual_live;
     char name[30];
     int name_enum;
     char rname[50];
diff --git a/src/tuxrts.c b/src/tuxrts.c
index e0e9ff5..28379c6 100644
--- a/src/tuxrts.c
+++ b/src/tuxrts.c
@@ -68,7 +68,7 @@ int tuxrts_init(char *object_name, char *map_name, int players)
       return 0;
     }
 
-    SDL_free(images[IMG_GUIBG_BYZANTINE]);
+    SDL_FreeSurface(images[IMG_GUIBG_BYZANTINE]);
     images[IMG_GUIBG_BYZANTINE] = tmp_surf;
 
 
@@ -126,7 +126,7 @@ th_obj *rts_get_object(int player, th_point coords)
 {
     list_node *obj_node;
 
-    if(gmaps[player][coords.x][coords.y].visible == 0)
+    if(gmaps[player][coords.x][coords.y].visible != 0)
         return NULL;
 
     obj_node = list_nodes;
diff --git a/src/tuxrts.h b/src/tuxrts.h
index dac3ed4..7c97450 100644
--- a/src/tuxrts.h
+++ b/src/tuxrts.h
@@ -8,6 +8,19 @@
 #include "llist.h"
 #include "objects.h"
 
+enum{
+    BUILD,
+    REPAIR,
+    ATTACK,
+    CREATE
+};
+
+typedef struct rts_vars{
+    th_obj *selected_objs[30];
+    int selected_num;
+}rts_vars;
+
+
 /* tuxrts_mapinit(): Inizialize all map vars. This is
  * the fisrt function to call when we begin the game.
  * char *: Object file name, without .xml

-- 
tuxhistory - Educational history game



More information about the Tux4kids-commits mailing list