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

julio (none) julio at julio-desktop.
Wed Jul 14 04:39:50 UTC 2010


The following commit has been merged in the master branch:
commit e9a3863aed632d1ac97d8a539b21d96b817dab00
Author: julio <julio at julio-desktop.(none)>
Date:   Tue Jul 13 23:33:10 2010 -0500

    Advances in the graph representation of game world

diff --git a/src/graphs.c b/src/graphs.c
index 745785f..ad4518e 100644
--- a/src/graphs.c
+++ b/src/graphs.c
@@ -10,5 +10,84 @@
  * http://www.tux4kids.com
  * 
  */
+#include<stdio.h>
+#include<stdlib.h>
 
+#include "globals.h"
 #include "graphs.h"
+#include "players.h"
+
+//gmaps is a tree dimensional array og gnode's, each 
+//gnode must be linked with their niehboors.
+static int gmaps_alloc(int xsize, int ysize, int maps)
+{
+    int i,j;
+    gmaps = (gnode ***)malloc(maps * sizeof(gnode **));
+    if(map[i] == NULL)
+    {
+        printf("Error: Allocation of objects faild!\n");
+        return 1; 
+    }
+
+    for(i = 0; i < maps; i++)
+    {
+        gmaps[i] = (gnode **)malloc(xsize * sizeof(gnode *));
+        if(map[i] == NULL)
+        {
+            printf("Error: Allocation of objects faild!\n");
+            return 1; 
+        }
+        for(j = 0; j < ysize; j++)
+        {
+            gmaps[i][j] = (gnode *)malloc(ysize * sizeof(gnode));
+            if(map[i][j] == NULL)
+            {
+                printf("Error: Allocation of objects faild!\n");
+                return 1; 
+            }
+
+        }
+    }
+    return 0;
+}
+
+int create_gmaps(int players)
+{
+    int i,j,k;
+    
+    players++;
+    if(gmaps_alloc(x_tildes, y_tildes, players))
+    {
+        printf("Error: out of memory!\n");
+        return 1;
+    }
+
+    for(i = 0; i < players; i++)
+    {
+        for(j = 0; j < x_tildes; j++)
+        {
+            for
+
+    
+
+
+
+
+
+
+void cleanup_gmaps(int maps, int xsize)
+{
+    int i,j;
+    for(i = 0; i < maps; i++)
+    {
+        for(j = 0; j < xsize; j++)
+        {
+            FREE(gmaps[i][j]);
+        }
+    }
+}
+
+
+
+
+
diff --git a/src/graphs.h b/src/graphs.h
index 3f46c34..8b4f06f 100644
--- a/src/graphs.h
+++ b/src/graphs.h
@@ -27,18 +27,16 @@
     ISO_SE
 }
 
-typedef struct gelement{
+typedef struct gnode{
     int anchor_x, anchor_y; //Anchors in main map surface.
+    int visible;
+    struct gnode *nodes[8];
     th_obj *object;
-    th_map *terrain;
+    int terrain;
 }gelement;
 
+gnode ***gmaps;
 
-typedef struct gnode{
-    struct gnode *nodes[8];
-    gelement *data;
-}gnode;
-
-
+int gmaps_alloc(void);
 
 #define GRAPHS_H
diff --git a/src/map.c b/src/map.c
index 84592da..278352c 100644
--- a/src/map.c
+++ b/src/map.c
@@ -32,6 +32,7 @@ static int init_map_hash(void);
 static void end_map_hash(void);
 static int get_terrain_enum(char *);
 static int *get_context_tildes(int, int);
+static th_vector get_iso_vector(int dir)
 static int *get_draw_tilde(int *, int);
 static int get_tile_num(int, int);
 static void str_upper(char *);
@@ -322,6 +323,89 @@ static int *get_context_tildes(int x, int y)
     return a; 
 }        
 
+// Returns a th_vector that contains a vector
+// representing the tile walking of a isometric
+// direction
+static th_vector get_iso_vector(int dir)
+{
+    th_vector vector;
+    if(dir == ISO_NW)
+    {
+        vector.x = -1;
+        vector.y = -1;
+    }
+    else if(dir == ISO_N)
+    {
+        vector.x = 0;
+        vector.y = -1;
+    }
+    else if(dir == ISO_NE)
+    {
+        vector.x = 1;
+        vector.y = -1;
+    }
+    else if(dir == ISO_W)
+    {
+        vector.x = -1;
+        vector.y = 0;
+    }
+    else if(dir == ISO_E)
+    {
+        vector.x = 1;
+        vector.y = 0;
+    }
+    else if(dir == ISO_SW)
+    {
+        vector.x = -1;
+        vector.y = 1;
+    }
+    else if(dir == ISO_S)
+    {
+        vector.x = 0;
+        vector.y = 1;
+    }
+    else if(dir == ISO_SE)
+    {
+        vector.x = 1;
+        vector.y = 1;
+    }
+    else
+    {
+        vector.x = -2;
+        vector.y = -2;
+    }
+    return vector;
+}
+
+//Uses th_map and returns a vector datatype that gives
+//the move if posible. -2 if the move is not possible
+//in this direction, 1,0, and -1 are valid moves.
+
+th_vector get_context_tildes(th_point point, int iso_dir)
+{
+    int i;
+    th_vector vector;
+
+    vector = get_iso_vector(iso_dir);
+    point.x = point.x + vector.x;
+    point.y = point.y + vector.y;
+
+    if (point.x < 0 || 
+        point.x > x_tildes)
+    {
+        vector.x = -2;
+        vector.y = -2;
+    }
+    if (point.y < 0 ||
+        point.y > y_tildes)
+    {
+        vector.x = -2;
+        vector.y = -2;
+    }
+    return vector;
+}
+        
+
 // return a array with the terrain enum values to draw the map.
 static int *get_draw_tilde(int *array, int oe)
 {
diff --git a/src/map.h b/src/map.h
index 97affdb..8a2314a 100644
--- a/src/map.h
+++ b/src/map.h
@@ -89,4 +89,6 @@ void th_draw_map(void);
 
 //char *th_serialize_map(th_map **);
 
+th_vector get_context_tildes(th_point point, int iso_dir);
+
 #endif
diff --git a/src/players.c b/src/players.c
index 2c25569..e9e923b 100644
--- a/src/players.c
+++ b/src/players.c
@@ -1 +1,11 @@
 #include "players.h"
+
+static int players_alloc();
+int init_players(num_players)
+{
+    num_of_players = num_players;
+    if(players_alloc(num_of_players))
+        return 1;
+    return 0;
+}
+
diff --git a/src/tuxhistory.h b/src/tuxhistory.h
index 12b1c0a..52f5741 100644
--- a/src/tuxhistory.h
+++ b/src/tuxhistory.h
@@ -43,11 +43,17 @@ typedef struct {
   int cur;
 } sprite;
 
-typedef struct {
+typedef struct th_point{
     int x;
     int y;
 } th_point;
 
+typedef struct th_vector{
+    int x;
+    int y;
+} th_vector;
+
+
 /* Global data gets 'externed' here: */
 
 /* declared in setup.c */

-- 
tuxhistory - Educational history game



More information about the Tux4kids-commits mailing list