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

julio (none) julio at julio-desktop.
Mon Aug 2 21:47:53 UTC 2010


The following commit has been merged in the master branch:
commit 97ae73ffabe193066b9bdcf5bb1799eb5bf4e7c7
Author: julio <julio at julio-desktop.(none)>
Date:   Mon Aug 2 16:46:49 2010 -0500

    Mini map added and GUI advances

diff --git a/configure.ac b/configure.ac
index f90d11e..4ee9db8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -461,6 +461,7 @@ data/fonts/Makefile
 data/images/Makefile
 data/images/backgrounds/Makefile
 data/images/icons/Makefile
+data/images/gui/Makefile
 data/images/others/Makefile
 data/images/penguins/Makefile
 data/images/status/Makefile
diff --git a/data/images/Makefile.am b/data/images/Makefile.am
index a4ac4ac..9908a56 100644
--- a/data/images/Makefile.am
+++ b/data/images/Makefile.am
@@ -5,6 +5,7 @@ SUBDIRS = backgrounds \
   terrain \
   forest \
   icons \
+  gui \
   others \
   penguins \
   status \
diff --git a/data/images/gui/Makefile.am b/data/images/gui/Makefile.am
new file mode 100644
index 0000000..169cc37
--- /dev/null
+++ b/data/images/gui/Makefile.am
@@ -0,0 +1,7 @@
+## Makefile.am for tuxhistory data/images/gui:
+
+## Process with AutoMake:
+
+guidir = $(pkgdatadir)/images/gui
+
+dist_gui_DATA = byzantine.png
diff --git a/data/images/gui/byzantine.png b/data/images/gui/byzantine.png
new file mode 100644
index 0000000..cfef9a5
Binary files /dev/null and b/data/images/gui/byzantine.png differ
diff --git a/src/SDL_extras.c b/src/SDL_extras.c
index 2766e35..7f04486 100644
--- a/src/SDL_extras.c
+++ b/src/SDL_extras.c
@@ -1108,3 +1108,147 @@ Uint32 get_pcolori(SDL_Surface *surface, int x, int y)
 
 #endif
 
+/* Draw a line: */
+void draw_line(SDL_Surface* surface, SDL_Rect rect, int red, int grn, int blu)
+{
+  int dx, dy, tmp;
+  float m, b;
+  Uint32 pixel;
+  SDL_Rect dest;
+
+  pixel = SDL_MapRGB(screen->format, red, grn, blu);
+
+  dx = rect.w - rect.x;
+  dy = rect.h - rect.y;
+
+  putpixel(screen, rect.x, rect.y, pixel);
+
+  if (dx != 0)
+  {
+    m = ((float) dy) / ((float) dx);
+    b = rect.y - m * rect.x;
+
+    if (rect.w > rect.x)
+      dx = 1;
+    else
+      dx = -1;
+
+    while (rect.x != rect.w)
+    {
+      rect.x = rect.x + dx;
+      rect.y = m * rect.x + b;
+
+      putpixel(surface, rect.x, rect.y, pixel);
+    }
+  }
+  else
+  {
+    if (rect.y > rect.h)
+    {
+      tmp = rect.y;
+      rect.y = rect.h;
+      rect.h = tmp;
+    }
+
+    dest.x = rect.x;
+    dest.y = rect.y;
+    dest.w = 3;
+    dest.h = rect.h - rect.y;
+
+    SDL_FillRect(surface, &dest, pixel);
+  }
+}
+
+
+/* Draw a single pixel into the surface: */
+
+void putpixel(SDL_Surface* surface, int x, int y, Uint32 pixel)
+{
+#ifdef PUTPIXEL_RAW
+  int bpp;
+  Uint8* p;
+
+  /* Determine bytes-per-pixel for the surface in question: */
+
+  bpp = surface->format->BytesPerPixel;
+
+
+  /* Set a pointer to the exact location in memory of the pixel
+     in question: */
+
+  p = (Uint8 *) (surface->pixels +       /* Start at beginning of RAM */
+                 (y * surface->pitch) +  /* Go down Y lines */
+                 (x * bpp));             /* Go in X pixels */
+
+
+  /* Assuming the X/Y values are within the bounds of this surface... */
+
+  if (x >= 0 && y >= 0 && x < surface->w && y < surface->h)
+  {
+      /* Set the (correctly-sized) piece of data in the surface's RAM
+         to the pixel value sent in: */
+
+    if (bpp == 1)
+      *p = pixel;
+    else if (bpp == 2)
+      *(Uint16 *)p = pixel;
+    else if (bpp == 3)
+    {
+      if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+      {
+        p[0] = (pixel >> 16) & 0xff;
+        p[1] = (pixel >> 8) & 0xff;
+        p[2] = pixel & 0xff;
+      }
+      else
+      {
+        p[0] = pixel & 0xff;
+        p[1] = (pixel >> 8) & 0xff;
+        p[2] = (pixel >> 16) & 0xff;
+      }
+    }
+    else if (bpp == 4)
+    {
+      *(Uint32 *)p = pixel;
+    }
+  }
+#else
+  SDL_Rect dest;
+
+  dest.x = x;
+  dest.y = y;
+  dest.w = 3;
+  dest.h = 4;
+
+  SDL_FillRect(surface, &dest, pixel);
+#endif
+}
+
+void draw_rect(SDL_Surface* surface, SDL_Rect rect)
+{
+    SDL_Rect tmp_rect;
+
+    tmp_rect.x = rect.x;
+    tmp_rect.y = rect.y;
+    tmp_rect.w = rect.w;
+    tmp_rect.h = rect.y;
+    draw_line(surface, tmp_rect, 255, 255, 255);
+
+    tmp_rect.x = rect.x;
+    tmp_rect.y = rect.y;
+    tmp_rect.w = rect.x;
+    tmp_rect.h = rect.h;
+    draw_line(surface, tmp_rect, 255, 255, 255);
+
+    tmp_rect.x = rect.x;
+    tmp_rect.y = rect.h;
+    tmp_rect.w = rect.w;
+    tmp_rect.h = rect.h;
+    draw_line(surface, tmp_rect, 255, 255, 255);
+
+    tmp_rect.x = rect.w;
+    tmp_rect.y = rect.y;
+    tmp_rect.w = rect.w;
+    tmp_rect.h = rect.h;
+    draw_line(surface, tmp_rect, 255, 255, 255);
+}
diff --git a/src/SDL_extras.h b/src/SDL_extras.h
index 1975f24..c39eeee 100644
--- a/src/SDL_extras.h
+++ b/src/SDL_extras.h
@@ -56,4 +56,8 @@ SDL_Surface*    SimpleText(const char *t, int size, SDL_Color* col);
 SDL_Surface*    SimpleTextWithOffset(const char *t, int size, SDL_Color* col, int *glyph_offset);
 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);
+
 #endif
diff --git a/src/fileops.h b/src/fileops.h
index 709c5a1..0adfe5e 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -73,6 +73,7 @@ enum {
   IMG_ISOSELECT,
   IMG_ISOGO,
   IMG_ISOWRONG,
+  IMG_GUIBG_BYZANTINE,
   NUM_IMAGES
 };
 
diff --git a/src/fileops_media.c b/src/fileops_media.c
index 3fde5d4..32b0829 100644
--- a/src/fileops_media.c
+++ b/src/fileops_media.c
@@ -64,7 +64,8 @@ int load_image_data()
   "others/isomapper.png",
   "others/select.png",
   "others/go.png",
-  "others/wrong.png"
+  "others/wrong.png",
+  "gui/byzantine.png"
   };
 
 
diff --git a/src/game.c b/src/game.c
index 9772d93..e9e6d2c 100644
--- a/src/game.c
+++ b/src/game.c
@@ -182,7 +182,8 @@ int game(void)
     while(game_status == GAME_IN_PROGRESS)
     {
         last_time = SDL_GetTicks();
-        
+
+        update_gmaps();
         game_handle_user_events();
         game_handle_mouse();
 
@@ -269,9 +270,29 @@ static void game_draw(void)
     }
    
     /*Third layer: User Interface*/
+
+    //TODO: Write a panel function to manipulate teh game...
+    
+    dest.x = 0;
+    dest.y = (screen->h / 5) * 4;
+    SDL_BlitSurface(images[IMG_GUIBG_BYZANTINE], 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);
+    
+
     dest.x = (screen->w - images[IMG_STOP]->w - 5);
     dest.y = glyph_offset;
     SDL_BlitSurface(images[IMG_STOP], NULL, screen, &dest);
+
+    dest.x = 20;
+    dest.y = 20;
+    dest.h = 100;
+    dest.w = 100;
+
+    draw_rect(screen, dest);
+
 }
 
 static void game_handle_mouse(void)
diff --git a/src/game.h b/src/game.h
index 69433d9..dce03aa 100644
--- a/src/game.h
+++ b/src/game.h
@@ -39,7 +39,6 @@ int game(void);
 void game_set_start_message(const char*, const char*, const char*, const char*);
 
 void draw_nums(const char* str, int x, int y);
-void draw_line(int x1, int y1, int x2, int y2, int r, int g, int b);
 void draw_numbers(const char* str, int x, int y);
 
 #endif
diff --git a/src/graphs.c b/src/graphs.c
index 599b321..b88c563 100644
--- a/src/graphs.c
+++ b/src/graphs.c
@@ -16,6 +16,7 @@
 #include "globals.h"
 #include "graphs.h"
 #include "players.h"
+#include "llist.h"
 
 
 static int gmaps_alloc(int xsize, int ysize, int maps);
@@ -81,6 +82,7 @@ int create_gmaps(int players)
                 count++;
                 gmaps[i][j][k].visible = 1;
                 gmaps[i][j][k].terrain = map[j][k].terrain;
+                gmaps[i][j][k].object = NULL;
                 for(l = 0; l < NUM_DIRS; l++)
                 {
                     point.x = j;
@@ -114,6 +116,18 @@ int create_gmaps(int players)
 
 int update_gmaps(void)
 {
+    list_node *obj_node;
+
+    obj_node = list_nodes;
+    if(obj_node != NULL)
+    {
+        do{
+            gmaps[0][obj_node->obj.x][obj_node->obj.y].object = obj_node;
+            gmaps[0][obj_node->obj.x][obj_node->obj.y].object = obj_node;
+            obj_node = obj_node->next;
+        }while(obj_node != NULL);
+    }
+
     return 0;
 }
 
diff --git a/src/map.c b/src/map.c
index f668445..09fd050 100644
--- a/src/map.c
+++ b/src/map.c
@@ -18,6 +18,7 @@
 #include "SDL.h"
 #include "SDL_image.h"
 #include "SDL_extras.h"
+#include "SDL_rotozoom.h"
 
 #include "tuxhistory.h"
 #include "globals.h"
@@ -29,6 +30,7 @@
 #include "graphs.h"
 
 SDL_Surface* map_image;
+SDL_Surface* mini_map_image;
 
 static int  init_map_hash(void);
 static void end_map_hash(void);
@@ -647,6 +649,8 @@ int generate_map(void)
         return 1;
     }
 
+
+
     // Prepare the variables...
     SDL_FillRect(map_image, NULL, SDL_MapRGB(map_image->format, 0, 0 ,0));
 
@@ -746,6 +750,14 @@ int generate_map(void)
     // Create a anchors map and allocates int **anchor_map
     generate_anchormap(); 
 
+
+    // Generate mini map
+    mini_map_image = rotozoomSurface(map_image, 0, 0.1, 1);
+    if(mini_map_image == NULL)
+    {
+        printf("Error: No mini map!");
+        return 1;
+    }
     return 0;
 }
 
diff --git a/src/setup.c b/src/setup.c
index 13638f8..4073785 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -211,7 +211,7 @@ void handle_command_args(int argc, char* argv[])
     {
       /* Display help message: */
 
-      printf("\nTux, of Math Command\n\n"
+      printf("\nTux History\n\n"
         "Use the number keys on the keyboard to answer math equations.\n"
         "If you don't answer a comet's math equation before it hits\n"
         "one of your cities, the city's shields will be destroyed.\n"
@@ -258,8 +258,8 @@ void handle_command_args(int argc, char* argv[])
              strcmp(argv[i], "-c") == 0)
     {
       printf(
-        "\n\"Tux, of Math Command\" version " VERSION ", Copyright (C) 2001-2009,\n"
-        "Bill Kendrick, David Bruce, Tim Holy, and the Tux4Kids Project.\n"
+        "\n\"Tux History\" version " VERSION ", Copyright (C) 2010,\n"
+        "Jesus Mager, Bill Kendrick, David Bruce, Tim Holy, and the Tux4Kids Project.\n"
         "This program is free software; you can redistribute it and/or\n"
         "modify it under the terms of the GNU General Public License\n"
         "as published by the Free Software Foundation.  See COPYING.txt\n"
@@ -565,7 +565,7 @@ void initialize_SDL(void)
 
     seticon();
 
-    SDL_WM_SetCaption("Tu History", "TuxHistory");
+    SDL_WM_SetCaption("Tux History", "TuxHistory");
   }
 
   /* --- Define the colors we use --- */
diff --git a/src/tuxhistory.h b/src/tuxhistory.h
index f6ac8c3..9ea5ee0 100644
--- a/src/tuxhistory.h
+++ b/src/tuxhistory.h
@@ -60,6 +60,7 @@ extern SDL_Color yellow;
 
 extern SDL_Surface* screen; /* declared in setup.c; also used in game.c, options.c, fileops.c, credits.c, titlescreen.c */
 extern SDL_Surface* map_image;
+extern SDL_Surface* mini_map_image;
 extern SDL_Surface* images[];    /* declared in setup.c, used in same files as screen */
 extern sprite* sprites[];
 extern SDL_Surface* flipped_images[];
diff --git a/src/tuxrts.c b/src/tuxrts.c
index add0d9e..e0e9ff5 100644
--- a/src/tuxrts.c
+++ b/src/tuxrts.c
@@ -1,3 +1,5 @@
+#include "SDL.h"
+#include "SDL_rotozoom.h"
 #include "tuxrts.h"
 #include "globals.h"
 #include "tuxhistory.h"
@@ -10,7 +12,9 @@
 
 int tuxrts_init(char *object_name, char *map_name, int players)
 {
+    float zoom;
     FILE *fp;
+    SDL_Surface *tmp_surf;
 
     object_counter = 0;
 
@@ -52,6 +56,22 @@ int tuxrts_init(char *object_name, char *map_name, int players)
     }
     generate_map();
 
+    zoom = (float)screen->w/(float)images[IMG_GUIBG_BYZANTINE]->w;
+
+    //rotozoomSurface (SDL_Surface *src, double angle, double zoom, int smooth);
+    tmp_surf = rotozoomSurface(images[IMG_GUIBG_BYZANTINE], 0, zoom, 1);
+
+    if (tmp_surf == NULL)
+    {
+      fprintf(stderr,
+              "\nError: Zoom of GUI Backgrund not possible\n");
+      return 0;
+    }
+
+    SDL_free(images[IMG_GUIBG_BYZANTINE]);
+    images[IMG_GUIBG_BYZANTINE] = tmp_surf;
+
+
     return 0;
 }
 
@@ -60,6 +80,7 @@ int tuxrts_init(char *object_name, char *map_name, int players)
 int rts_valid_tile(int player, int unit, th_point coords)
 {
     list_node *unit_p;
+    th_obj *obj_p;
     if(coords.x < 0 || coords.x > x_tildes)
         return 0;
     if(coords.y < 0 || coords.y > y_tildes)
@@ -77,24 +98,50 @@ int rts_valid_tile(int player, int unit, th_point coords)
     {
         return 0;
     }
-    /*else if(gmaps[player][coords.x][coords.y].object != NULL)
+    else if(gmaps[player][coords.x][coords.y].object != NULL)
     {
-        if( gmaps[player][coords.x][coords.y].object->type == FOREST   ||
-            gmaps[player][coords.x][coords.y].object->type == GOLD     ||
-            gmaps[player][coords.x][coords.y].object->type == STONE ) 
+
+        obj_p = rts_get_object(player, coords);
+        if(obj_p != NULL)
         {
-            return 0;
-            // From to condition... Ships may use wather, 
-            // pawns may une FOREST, GOLD, AND STONE
+            if( obj_p->type == FOREST   ||
+                obj_p->type == GOLD     ||
+                obj_p->type == STONE)
+                return 0;
+            else
+                return 1;
         }
         else
         {
             return 1;
         }
-    }*/
+    }
     else
     {
         return 1;
     }
 }
 
+th_obj *rts_get_object(int player, th_point coords)
+{
+    list_node *obj_node;
+
+    if(gmaps[player][coords.x][coords.y].visible == 0)
+        return NULL;
+
+    obj_node = list_nodes;
+    if(obj_node != NULL)
+    {
+        do{
+            if( obj_node->obj.x == coords.x &&
+                obj_node->obj.y == coords.y   )
+                return &obj_node->obj;
+            else
+                obj_node = obj_node->next;
+        }while(obj_node != NULL);
+        return NULL;
+    }
+
+    return 0;
+}
+
diff --git a/src/tuxrts.h b/src/tuxrts.h
index cc09d59..dac3ed4 100644
--- a/src/tuxrts.h
+++ b/src/tuxrts.h
@@ -6,16 +6,35 @@
 #include "map.h"
 #include "players.h"
 #include "llist.h"
+#include "objects.h"
 
 /* tuxrts_mapinit(): Inizialize all map vars. This is
  * the fisrt function to call when we begin the game.
  * char *: Object file name, without .xml
  * char *: Map file name, without .xml
- * int   : Number of players*/
+ * int   : Number of players
+ * */
 
 int tuxrts_init(char *, char *, int);
+
+/* rts_valid_tile(): Evaluates a tile coordiate
+ * to determine if it is valid for a player.
+ * return 1 if it is valid and 0 if not.
+ * int      : Player number 
+ * th_point : Coords to evaluate 
+ */
+
 int rts_valid_tile(int, int, th_point);
 
+/* rts_get_object(): gets a objetc that is 
+ * on a spesific coordinate. Returns a pointer to 
+ * that object if it exists on the coords and NULL
+ * if no object is on the coords.
+ * int      : Player
+ * th_point : The coords
+ */
+th_obj *rts_get_object(int, th_point); 
+
 void tuxrts_cleanup(void);
 
 list_node *selected_node;

-- 
tuxhistory - Educational history game



More information about the Tux4kids-commits mailing list