[gnome-games] Work on debugging collision detection, added debug info, gnibbles_worm_inverse()



commit 9ec55d5701f15c437833b6022ff933d57bded576
Author: Guillaume Beland <guillaume beland gmail com>
Date:   Wed Jul 22 17:13:15 2009 -0400

    Work on debugging collision detection, added debug info, gnibbles_worm_inverse()

 gnibbles/gnibbles.c     |   35 +++++++++++++--------------
 gnibbles/level.c        |   10 ++++---
 gnibbles/worm-clutter.c |   59 ++++++++++++++++++++++++++++++++++++++--------
 3 files changed, 71 insertions(+), 33 deletions(-)
---
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index 815c271..d7ce34c 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -160,8 +160,8 @@ gnibbles_load_pixmap (gint tilesize)
       g_object_unref (wall_pixmaps[i]);
       
     wall_pixmaps[i] = gnibbles_load_pixmap_file (small_files[i],
-  	 	  		                                             2 * tilesize,
-                           						                   2 * tilesize);
+  	 	  		                                             tilesize,
+                           						                   tilesize);
   }
 
   for (i = 0; i < 7; i++) {
@@ -262,22 +262,6 @@ gnibbles_move_worms (void)
     status &= !dead[i];
   }
 
-  for (i = 0; i < properties->numworms; i++) { 
-    if (worms[i]->xhead >= BOARDWIDTH) {
-      worms[i]->xhead = 0;
-      gnibbles_worm_add_actor(worms[i]);
-    } else if (worms[i]->xhead <= 0) {
-      worms[i]->xhead = BOARDWIDTH;
-      gnibbles_worm_add_actor (worms[i]);
-    } else if (worms[i]->yhead >= BOARDHEIGHT) {
-      worms[i]->yhead = 0;
-      gnibbles_worm_add_actor (worms[i]);
-    } else if (worms[i]->xhead <= 0) {
-      worms[i]->yhead = BOARDHEIGHT;
-      gnibbles_worm_add_actor (worms[i]);
-    }
-
-  }
   
   for (i = 0; i < properties->numworms; i++) {
     if (g_list_length (worms[i]->list) > 1 && !dead[i] && worms[i]->lives > 0)
@@ -294,6 +278,21 @@ gnibbles_move_worms (void)
       gnibbles_worm_move_straight_worm (worms[i]);
   }
 
+  for (i = 0; i < properties->numworms; i++) { 
+    if (worms[i]->xhead >= BOARDWIDTH) {
+      worms[i]->xhead = 0;
+      gnibbles_worm_add_actor(worms[i]);
+    } else if (worms[i]->xhead <= 0) {
+      worms[i]->xhead = BOARDWIDTH;
+      gnibbles_worm_add_actor (worms[i]);
+    } else if (worms[i]->yhead >= BOARDHEIGHT) {
+      worms[i]->yhead = 0;
+      gnibbles_worm_add_actor (worms[i]);
+    } else if (worms[i]->xhead <= 0) {
+      worms[i]->yhead = BOARDHEIGHT;
+      gnibbles_worm_add_actor (worms[i]);
+    }
+  }
 
   for (i = 0; i < properties->numworms; i++) {
     for (j = 0; j < properties->numworms; j++) {
diff --git a/gnibbles/level.c b/gnibbles/level.c
index 703de3a..56e31bd 100644
--- a/gnibbles/level.c
+++ b/gnibbles/level.c
@@ -154,18 +154,20 @@ gnibbles_level_new (gint level)
   fclose (in);
 
   for (i = 0; i < count; i++) {
+    lvl->walls[worms[i]->xhead][worms[i]->yhead] = WORMCHAR;
+
     if (worms[i]->direction == WORMRIGHT) {
       for (j = 0; j < worms[i]->length; j++)
-        lvl->walls[worms[i]->xhead++][worms[i]->yhead] = WORMCHAR;
+        lvl->walls[++worms[i]->xhead][worms[i]->yhead] = WORMCHAR;
     } else if ( worms[i]->direction == WORMLEFT) {
       for (j = 0; j < worms[i]->length; j++)
-        lvl->walls[worms[i]->xhead--][worms[i]->yhead] = WORMCHAR;
+        lvl->walls[--worms[i]->xhead][worms[i]->yhead] = WORMCHAR;
     } else if (worms[i]->direction == WORMDOWN) {
       for (j = 0; j < worms[i]->length; j++)
-        lvl->walls[worms[i]->xhead][worms[i]->yhead++] = WORMCHAR;
+        lvl->walls[worms[i]->xhead][++worms[i]->yhead] = WORMCHAR;
     } else if (worms[i]->direction == WORMUP) {
       for (j = 0; j < worms[i]->length; j++)
-        lvl->walls[worms[i]->xhead][worms[i]->yhead--] = WORMCHAR;
+        lvl->walls[worms[i]->xhead][--worms[i]->yhead] = WORMCHAR;
     }
   }
 
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index 40b923a..c5488d3 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -369,14 +369,11 @@ gnibbles_worm_add_actor (GnibblesWorm *worm)
   if (worm->list) 
     head = gnibbles_worm_get_head_actor (worm);
 
-  gfloat x,y;
-  clutter_actor_get_position (CLUTTER_ACTOR (actor), &x, &y);
-
   if (worm->direction == WORMRIGHT || worm->direction == WORMLEFT) {
     // if it's the first actor, set its size
     if (!head) {
       clutter_actor_set_size (CLUTTER_ACTOR (actor),
-                              properties->tilesize * SLENGTH,
+                              properties->tilesize * worm->length,
                               properties->tilesize);
 
     } else {
@@ -389,7 +386,7 @@ gnibbles_worm_add_actor (GnibblesWorm *worm)
     if (!head) {
       clutter_actor_set_size (CLUTTER_ACTOR (actor),
                               properties->tilesize,
-                              properties->tilesize * SLENGTH);
+                              properties->tilesize * worm->length);
     } else {
       clutter_actor_set_size (CLUTTER_ACTOR (actor), properties->tilesize, 0);
     }
@@ -451,6 +448,17 @@ gnibbles_worm_inverse (gpointer data)
 
   worm->list = g_list_reverse (worm->list);
   
+  gint old_dir = gnibbles_worm_get_tail_direction (worm);
+
+  if (old_dir == WORMRIGHT)
+    worm->direction = WORMLEFT;
+  else if (old_dir == WORMLEFT)
+    worm->direction = WORMRIGHT;
+  else if (old_dir == WORMUP)
+    worm->direction = WORMDOWN;
+  else if (old_dir == WORMDOWN)
+    worm->direction = WORMUP;
+
   gint tmp;
 
   tmp = worm->xhead;
@@ -469,13 +477,12 @@ gnibbles_worm_reset (GnibblesWorm * worm)
   gint tail_length;
   gint tail_dir;
   gint i,j;
-  gint nbr_actor = clutter_group_get_n_children (CLUTTER_GROUP (worm->actors));
+  gint nbr_actor = g_list_length (worm->list); 
 
   for (j = 0; j < nbr_actor; j++) {
     tail_dir = gnibbles_worm_get_tail_direction (worm);
     tail_actor = gnibbles_worm_get_tail_actor (worm);
-    tail_length = gnibbles_worm_get_actor_length (tail_actor);
-   
+    tail_length = gnibbles_worm_get_actor_length (tail_actor); 
 
     switch (tail_dir) {
       case WORMUP:
@@ -497,7 +504,7 @@ gnibbles_worm_reset (GnibblesWorm * worm)
       default:
         break;
     }
-
+    level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
     gnibbles_worm_remove_actor (worm);
   }
 
@@ -506,10 +513,40 @@ gnibbles_worm_reset (GnibblesWorm * worm)
   worm->xtail = worm->xhead;
   worm->ytail = worm->yhead;
   worm->direction = worm->direction_start;
-  worm->length = 0;
+  worm->length = SLENGTH;
 
-  if (!(worm->lives <= 0))
+  if (!(worm->lives <= 0)) {
     gnibbles_worm_add_actor (worm);
+
+    level->walls[worm->xhead][worm->yhead] = WORMCHAR;
+    if (worm->direction == WORMRIGHT) {
+      for (j = 0; j < worm->length; j++)
+        level->walls[++worm->xhead][worm->yhead] = WORMCHAR;
+    } else if ( worm->direction == WORMLEFT) {
+      for (j = 0; j < worm->length; j++)
+        level->walls[--worm->xhead][worm->yhead] = WORMCHAR;
+    } else if (worm->direction == WORMDOWN) {
+      for (j = 0; j < worm->length; j++)
+        level->walls[worm->xhead][++worm->yhead] = WORMCHAR;
+    } else if (worm->direction == WORMUP) {
+      for (j = 0; j < worm->length; j++)
+        level->walls[worm->xhead][--worm->yhead] = WORMCHAR;
+    }
+  }
+/*
+  FILE *fo;
+  fo = fopen ("output.txt", "w" );
+  for (i = 0; i < BOARDWIDTH; i++) {
+    for (j = 0; j < BOARDHEIGHT; j++) {
+      if (level->walls[i][j] == 'a')
+        fprintf(fo, "%c", ' ');
+      else
+        fprintf (fo , "%c", level->walls[i][j]);
+    }
+    fprintf (fo, "\n");
+  }
+  fclose (fo);
+ */   
 }
 
 void 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]