[Tux4kids-commits] [SCM] tuxhistory - Educational history game branch, master, updated. f30d185c47d595c2f5118cf7b0e228d2a7d4ea20
julio (none)
julio at julio-desktop.
Thu Jul 15 02:53:39 UTC 2010
The following commit has been merged in the master branch:
commit f30d185c47d595c2f5118cf7b0e228d2a7d4ea20
Author: julio <julio at julio-desktop.(none)>
Date: Wed Jul 14 21:52:50 2010 -0500
Adding graphs.c/h and llist.c/h to compiling and fixed compiling errors.
diff --git a/src/Makefile.am b/src/Makefile.am
index 1ef7009..38d629a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -37,6 +37,7 @@ tuxhistory_SOURCES = tuxhistory.c \
hashtable.c \
highscore.c \
llist.c \
+ graphs.c \
linewrap.c \
loaders.c \
audio.c \
@@ -62,6 +63,7 @@ EXTRA_DIST = credits.h \
highscore.h \
linewrap.h \
llist.h \
+ graphs.h \
loaders.h \
titlescreen.h \
map.h \
diff --git a/src/globals.h b/src/globals.h
index 40011ec..5009929 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -165,6 +165,17 @@ enum {
NUM_HIGH_SCORE_LEVELS
};
+typedef struct th_point{
+ int x;
+ int y;
+} th_point;
+
+typedef struct th_vector{
+ int x;
+ int y;
+} th_vector;
+
+
#define NAME_BUF_SIZE 200
/* data for 'Training Academy' lessons: */
diff --git a/src/graphs.c b/src/graphs.c
index ad4518e..0a50fb9 100644
--- a/src/graphs.c
+++ b/src/graphs.c
@@ -17,13 +17,15 @@
#include "graphs.h"
#include "players.h"
+static int gmaps_alloc(int xsize, int ysize, int maps);
+
//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)
+ if(gmaps[i] == NULL)
{
printf("Error: Allocation of objects faild!\n");
return 1;
@@ -32,7 +34,7 @@ static int gmaps_alloc(int xsize, int ysize, int maps)
for(i = 0; i < maps; i++)
{
gmaps[i] = (gnode **)malloc(xsize * sizeof(gnode *));
- if(map[i] == NULL)
+ if(gmaps[i] == NULL)
{
printf("Error: Allocation of objects faild!\n");
return 1;
@@ -40,7 +42,7 @@ static int gmaps_alloc(int xsize, int ysize, int maps)
for(j = 0; j < ysize; j++)
{
gmaps[i][j] = (gnode *)malloc(ysize * sizeof(gnode));
- if(map[i][j] == NULL)
+ if(gmaps[i][j] == NULL)
{
printf("Error: Allocation of objects faild!\n");
return 1;
@@ -53,7 +55,10 @@ static int gmaps_alloc(int xsize, int ysize, int maps)
int create_gmaps(int players)
{
- int i,j,k;
+ int i,j,k,l;
+ int count;
+ th_point point;
+ th_vector vector;
players++;
if(gmaps_alloc(x_tildes, y_tildes, players))
@@ -62,11 +67,34 @@ int create_gmaps(int players)
return 1;
}
- for(i = 0; i < players; i++)
+ for(i = 1; i < players; i++)
{
+ count = 0;
for(j = 0; j < x_tildes; j++)
{
- for
+ for(k = 0; k < y_tildes; k++)
+ {
+ count++;
+ gmaps[i][j][k].visible = 1;
+ for(l = 0; l < NUM_DIRS; l++)
+ {
+ point.x = j;
+ point.y = k;
+ vector = get_vector(point, l);
+ if(vector.x != -2 && vector.y != -2)
+ gmaps[i][j][k].nodes[l] = &gmaps[0][j+vector.x][k+vector.y];
+ else
+ gmaps[i][j][k].nodes[l] = NULL;
+ if(i > 0)
+ gmaps[i][j][k].visible = 1;
+ else
+ gmaps[i][j][k].visible = 0;
+ }
+ gmaps[i][j][k].id = count;
+ }
+ }
+ }
+}
diff --git a/src/graphs.h b/src/graphs.h
index 8b4f06f..2c7b349 100644
--- a/src/graphs.h
+++ b/src/graphs.h
@@ -16,6 +16,7 @@
#include "map.h"
+enum
{
ISO_NW,
ISO_N,
@@ -24,19 +25,25 @@
ISO_E,
ISO_SW,
ISO_S,
- ISO_SE
-}
+ ISO_SE,
+ NUM_DIRS
+};
typedef struct gnode{
+ int id;
int anchor_x, anchor_y; //Anchors in main map surface.
int visible;
struct gnode *nodes[8];
th_obj *object;
int terrain;
-}gelement;
+}gnode;
+//gnode gmaps[player][x][y]
gnode ***gmaps;
-int gmaps_alloc(void);
+//Introduce the number of players for a game, abt create_gmaps()
+//will create a new graphs mesh in a 3 dimensional array:
+//This function uses **map as reference and x_size y_size
+int create_gmaps(int players);
-#define GRAPHS_H
+#endif GRAPHS_H
diff --git a/src/llist.c b/src/llist.c
index 22ac20d..a8539f1 100644
--- a/src/llist.c
+++ b/src/llist.c
@@ -13,6 +13,7 @@
#include<stdio.h>
#include<stdlib.h>
+#include "map.h"
#include "llist.h"
list_node *list_add(list_node **ptr, th_obj obj)
@@ -30,7 +31,7 @@ list_node *list_add(list_node **ptr, th_obj obj)
node->next = *ptr;
*ptr = node;
- node->object = obj;
+ node->obj = obj;
return node;
}
@@ -53,7 +54,7 @@ list_node **list_search(list_node **node, int data)
while(*node != NULL)
{
- if((*node)->object.id == data)
+ if((*node)->obj.id == data)
{
return node;
}
diff --git a/src/llist.h b/src/llist.h
index 38d387e..eadef45 100644
--- a/src/llist.h
+++ b/src/llist.h
@@ -13,11 +13,12 @@
#ifndef DSTRUCTS_H
#define DSTRUCTS_H
+#include "map.h"
#include "tuxhistory.h"
typedef struct list_node{
struct list_node *next;
- th_obj object;
+ th_obj obj;
}list_node;
list_node *list_add(list_node **, th_obj);
@@ -25,4 +26,8 @@ void list_remove(list_node **);
list_node **list_search(list_node **, int);
void list_clean(list_node **);
+// This list contains all objects that we load
+// from config files
+list_node *list_nodes;
+
#endif
diff --git a/src/map.c b/src/map.c
index 278352c..6bb2769 100644
--- a/src/map.c
+++ b/src/map.c
@@ -25,6 +25,7 @@
#include "map.h"
#include "hashtable.h"
#include "llist.h"
+#include "graphs.h"
SDL_Surface* map_image;
@@ -32,7 +33,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 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 *);
@@ -314,12 +315,6 @@ static int *get_context_tildes(int x, int y)
*(a + 8) = map[x+1][y+1].terrain;
}
}
- /*for (i=0; i<9; i++)
- {
- printf("%d ", *(a + i));
- }*/
- ////printf("\n");
-
return a;
}
@@ -381,7 +376,7 @@ static th_vector get_iso_vector(int dir)
//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)
+th_vector get_vector(th_point point, int iso_dir)
{
int i;
th_vector vector;
diff --git a/src/map.h b/src/map.h
index 8a2314a..beed808 100644
--- a/src/map.h
+++ b/src/map.h
@@ -21,7 +21,8 @@
#ifndef MAP_H
#define MAP_H
-//#include "hashtable.h"
+#include "hashtable.h"
+#include "globals.h"
// List of objects that can be used
// in create_object.
@@ -39,10 +40,8 @@ enum{
NUM_OF_TYPES
};
-
-
/*Global tuxhistory vars*/
-typedef struct {
+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
@@ -53,17 +52,17 @@ typedef struct {
int move;
int player;
}th_obj;
+
// th_map is the main data strucutre
// th_map_tilde specifies the terrain
// of the isometric map
-typedef struct {
+typedef struct th_map{
int height; //Height of this tilde
int terrain;
}th_map;
struct hashtable *map_table_hash; //Values of Terrains and objects
-list_node *list_nodes;
int flag_map; // Map flag: is a map surface allocated?
int x_tildes;
int y_tildes;
@@ -84,11 +83,7 @@ void free_map(void);
void th_draw_map(void);
-//Generates the th_map from a XML string.
-//th_map** th_make_map(char *);
-
-//char *th_serialize_map(th_map **);
-th_vector get_context_tildes(th_point point, int iso_dir);
+th_vector get_vector(th_point point, int iso_dir);
#endif
diff --git a/src/tuxhistory.h b/src/tuxhistory.h
index 52f5741..c763cbf 100644
--- a/src/tuxhistory.h
+++ b/src/tuxhistory.h
@@ -4,10 +4,7 @@
For tuxhistory
Contains global data for configuration
- Author: David Bruce <davidstuartbruce at gmail.com>, (C) 2006
-
- Modified by Jesús Mager <fongog at gmail.com> 2010
-
+ Author: Jesús Mager <fongog at gmail.com> 2010
Part of "Tux4Kids" Project
http://www.tux4kids.org/
@@ -43,16 +40,6 @@ typedef struct {
int cur;
} sprite;
-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: */
--
tuxhistory - Educational history game
More information about the Tux4kids-commits
mailing list