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

julio (none) julio at julio-desktop.
Fri Jul 16 22:53:46 UTC 2010


The following commit has been merged in the master branch:
commit 76e12e690e5013e48b279db1da3ccf6e1269ec78
Author: julio <julio at julio-desktop.(none)>
Date:   Fri Jul 16 17:53:03 2010 -0500

    Objects are now from objects linked list to screen. Only windowed mode is OK at now, fullscreen mode is bugy.

diff --git a/src/Makefile.am b/src/Makefile.am
index 40d13b7..fb29a8e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -36,7 +36,7 @@ tuxhistory_SOURCES = tuxhistory.c \
 	options.c	\
 	credits.c	\
 	hashtable.c \
-	highscore.c	*/\
+	highscore.c	\
 	llist.c		\
 	graphs.c	\
 	linewrap.c	\
diff --git a/src/game.c b/src/game.c
index 71acec3..fc4df58 100644
--- a/src/game.c
+++ b/src/game.c
@@ -34,8 +34,10 @@
 #include "options.h"
 #include "SDL_extras.h"
 #include "pixels.h"
+#include "graphs.h"
 #include "map.h"
 #include "objects.h"
+#include "llist.h"
 
 
 #define FPS 15 /* 15 frames per second */
@@ -224,6 +226,7 @@ int game(void)
 static void game_draw(void)
 {
     SDL_Rect dest;
+    list_node *obj_node;
 
     origin.x = Pscreen.x;
     origin.y = Pscreen.y;
@@ -240,7 +243,46 @@ static void game_draw(void)
 
     dest.x = 0;
     dest.y = 0;
+
+    /*TODO: Separate each Layer drawing in different functions.*/
+
+
+    /*First layer: terrain*/
     SDL_BlitSurface(map_image, &origin, screen, &dest);
+
+    /*Second layer: objects*/
+
+    obj_node = list_nodes;
+    if(obj_node != NULL)
+    {
+        do{
+            //Debug...
+            //printf("Nodes: (%d, %d)\n", obj_node->obj.x, obj_node->obj.y);
+            if( gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.x > origin.x -
+                    objects[obj_node->obj.name_enum]->w/2&&
+                gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.y > origin.y - 
+                    objects[obj_node->obj.name_enum]->w/2&&
+                gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.x < origin.x + origin.w &&
+                gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.y < origin.y + origin.w)
+            {
+                dest.x = gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.x - 
+                    origin.x - objects[obj_node->obj.name_enum]->w/2;
+                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);
+                /*printf("x: %d y: %d anchors, x: %d y: %d",
+                        obj_node->obj.x,
+                        obj_node->obj.y,
+                        gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.x,
+                        gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.y);*/
+            }
+            obj_node = obj_node->next;
+        }while(obj_node != NULL);
+    }
+   
+
+
+    /*Third layer: User Interface*/
     dest.x = (screen->w - images[IMG_STOP]->w - 5);
     dest.y = glyph_offset;
     SDL_BlitSurface(images[IMG_STOP], NULL, screen, &dest);
diff --git a/src/hashtable.c b/src/hashtable.c
index 8a97dc5..353947d 100644
--- a/src/hashtable.c
+++ b/src/hashtable.c
@@ -197,14 +197,14 @@ struct hashtable *make_hashtable(unsigned int (*hash) (const char*),
     if(table) {
         table->bucket = NEWARRAY(struct hashtable_entry*,
                                 nbuckets);
-        if(!table->bucket) {
-        free(table);
-        return NULL;
-    }
-    table->hash = hash;
-    table->nbuckets = nbuckets;
+        if(!table->bucket) 
+        {
+            free(table);
+            return NULL;
+        }
+        table->hash = hash;
+        table->nbuckets = nbuckets;
     }
-    
     return table;
-    }
+}
 
diff --git a/src/map.c b/src/map.c
index e19c735..3a8083b 100644
--- a/src/map.c
+++ b/src/map.c
@@ -84,7 +84,7 @@ int map_xml(FILE *fp)
 
     object_ptr = NULL;
     list_nodes = NULL;
-   
+
     tree = mxmlLoadFile(NULL, fp, MXML_TEXT_CALLBACK);
     if(init_map_hash())
     {
@@ -157,7 +157,14 @@ int map_xml(FILE *fp)
                     
                     printf(" *%s ", object_ptr->description);
                     tmp_obj = *object_ptr;
+                    tmp_obj.id = object_counter;
+                    tmp_obj.x = x;
+                    tmp_obj.y = y;
                     list_add(&list_nodes, tmp_obj);
+
+                    //map[i][j].obj_id = object_counter;
+
+                    object_counter++;
                 }
                 else
                 {
@@ -585,7 +592,6 @@ int generate_map(void)
         {
             k++;
 
-            printf(" (%d,%d) (%d,%d)\n", dest.x, dest.y, i, j);
 
             context_array = get_context_tildes(i,j);
             if (context_array == NULL)
@@ -613,6 +619,9 @@ 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;
             
             // TODO: This is better in graph.h
diff --git a/src/map.h b/src/map.h
index 74569e8..df29deb 100644
--- a/src/map.h
+++ b/src/map.h
@@ -23,6 +23,7 @@
 
 #include "hashtable.h"
 #include "globals.h"
+#include "objects.h"
 
 
 /*Global tuxhistory vars*/
@@ -34,6 +35,7 @@
 typedef struct th_map{
     int height; //Height of this tilde
     int terrain;
+    //int obj_id;
 }th_map;
 
 struct hashtable *map_table_hash; //Values of Terrains and objects
diff --git a/src/objects.c b/src/objects.c
index 918c741..14dbcd6 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -175,6 +175,8 @@ int objects_xml(FILE *fp)
 
     fclose(fp);
 
+    object_counter = 0;
+
     return 0;
 }
 

-- 
tuxhistory - Educational history game



More information about the Tux4kids-commits mailing list