[Tux4kids-commits] [SCM] tuxhistory - Educational history game branch, master, updated. 6e4bb304bf02a54815f7225558225f77147228a8
julio (none)
julio at julio-desktop.
Sat Jul 10 17:58:03 UTC 2010
The following commit has been merged in the master branch:
commit 6e4bb304bf02a54815f7225558225f77147228a8
Author: julio <julio at julio-desktop.(none)>
Date: Sat Jul 10 12:57:06 2010 -0500
Adding linked list for objects
diff --git a/src/Makefile.am b/src/Makefile.am
index 7fa4dc1..c579d16 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -35,6 +35,7 @@ tuxhistory_SOURCES = tuxhistory.c \
options.c \
credits.c \
highscore.c \
+ llist.c \
linewrap.c \
loaders.c \
audio.c \
@@ -58,6 +59,7 @@ EXTRA_DIST = credits.h \
globals.h \
highscore.h \
linewrap.h \
+ llist.h \
loaders.h \
titlescreen.h \
map.h \
diff --git a/src/game.c b/src/game.c
index fcc488b..ba194be 100644
--- a/src/game.c
+++ b/src/game.c
@@ -37,7 +37,7 @@
#include "map.h"
-#define FPS 15 /* 15 frames per second */
+#define FPS 15 /* 15 frames per second */
#define MS_PER_FRAME (1000 / FPS)
#define IN_SCROLL 3 // Scroll speed
diff --git a/src/llist.c b/src/llist.c
new file mode 100644
index 0000000..72046cf
--- /dev/null
+++ b/src/llist.c
@@ -0,0 +1,60 @@
+#include<stdio.h>
+#include<stdlib.h>
+
+#include "tuxhistory.h"
+#include "llist.h"
+
+list_node *list_add(list_node **ptr, th_obj obj)
+{
+ if (ptr == NULL)
+ {
+ return NULL;
+ }
+
+ list_node *node = (list_node *)malloc(sizeof(list_node));
+ if (node == NULL)
+ {
+ return NULL;
+ }
+
+ node->next = *ptr;
+ *ptr = node;
+ node->object = obj;
+ return node;
+}
+
+void list_remove(list_node** ptr)
+{
+ if(ptr != NULL && *ptr != NULL)
+ {
+ list_node *node = *ptr;
+ *ptr = (*ptr)->next;
+ free(node);
+ }
+}
+
+list_node **list_search(list_node **node, int data)
+{
+ if(node == NULL)
+ {
+ return NULL;
+ }
+
+ while(*node != NULL)
+ {
+ if((*node)->object.id == data)
+ {
+ return node;
+ }
+ node = &(*node)->next;
+ }
+ return NULL;
+}
+
+void list_clean(list_node **node)
+{
+ while(*node != NULL)
+ list_remove(node);
+}
+
+
diff --git a/src/llist.h b/src/llist.h
new file mode 100644
index 0000000..8e6f3da
--- /dev/null
+++ b/src/llist.h
@@ -0,0 +1,16 @@
+#ifndef DSTRUCTS_H
+
+#include "tuxhistory.h"
+
+typedef struct list_node{
+ struct list_node *next;
+ th_obj object;
+}list_node;
+
+list_node *list_add(list_node **, th_obj);
+void list_remove(list_node **);
+list_node **list_search(list_node **, int);
+void list_clean(list_node **);
+
+#define DSTRUCT_H
+#endif
diff --git a/src/map.c b/src/map.c
index 8f87a70..040714c 100644
--- a/src/map.c
+++ b/src/map.c
@@ -424,8 +424,10 @@ int generate_map(void)
map_image = NULL;
int w, h;
- w = terrain[TUNDRA_CENTER_1]->w * x_tildes + x_tildes;
- h = terrain[TUNDRA_CENTER_1]->h * y_tildes + y_tildes;
+
+ //Create a SDL_Surface that contains the terrain._
+ w = terrain[TUNDRA_CENTER_1]->w * (x_tildes + 1);
+ h = terrain[TUNDRA_CENTER_1]->h * (y_tildes + 1);
map_image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h,
32, rmask, gmask, bmask, amask);
@@ -435,16 +437,19 @@ int generate_map(void)
return 1;
}
+ // Prepare the variables...
SDL_FillRect(map_image, NULL, SDL_MapRGB(map_image->format, 0, 0 ,0));
dest.x = (map_image->w/2)-(terrain[TUNDRA_CENTER_1]->w/2);
- dest.y = (map_image->h/2);
+ dest.y = map_image->h-terrain[TUNDRA_CENTER_1]->h;
printf("[%d,%d]\n", x_tildes, y_tildes);
x = dest.x;
y = dest.y;
k = 0;
+
+ //This loop blits all tildes to map_image.
for (i = x_tildes; i >= 0; i--)
{
oe = k + 1;
diff --git a/src/map.h b/src/map.h
index 969ac88..cb99f91 100644
--- a/src/map.h
+++ b/src/map.h
@@ -35,6 +35,7 @@ enum{
/*Global tuxhistory vars*/
typedef struct {
+ int id;
int x, y; // (x,y) in the th_map array
int type;
int live; // 100 to 0
--
tuxhistory - Educational history game
More information about the Tux4kids-commits
mailing list