[gnome-games/gnibbles-clutter-rebased: 49/129] Fixed warp, mostly, also fixed gnibbles_worm_reset (), mostly



commit fc5dff1158c50d844d41a8d94f1cdfd2823f2c9a
Author: Guillaume Beland <guillaume beland gmail com>
Date:   Wed Jul 15 15:47:41 2009 -0400

    Fixed warp, mostly, also fixed gnibbles_worm_reset (), mostly

 gnibbles/gnibbles.c     |    6 +----
 gnibbles/worm-clutter.c |   51 ++++++++++++++++++++++++++++++----------------
 2 files changed, 34 insertions(+), 23 deletions(-)
---
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index c83713e..7c325c6 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -309,11 +309,7 @@ gnibbles_move_worms (void)
       if (!gnibbles_worm_lose_life (worms[i])) {
         /* One of the worms lost one life, but the round continues. */
         // TODO: reset worm state
-        //gnibbles_worm_reset (worms[i]);
-        //gnibbles_worm_set_start (worms[i],
-				//                         worms[i]->xstart,
-        //                				 worms[i]->ystart,
-				//                         worms[i]->direction_start);
+        gnibbles_worm_reset (worms[i]);
 	      games_sound_play ("crash");
 	    }
     }
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index dad9740..c8c3b2f 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -272,13 +272,23 @@ gnibbles_worm_get_tail_direction (GnibblesWorm *worm)
   gboolean is_horizontal;
   GValue val = {0,};
   g_value_init (&val, G_TYPE_BOOLEAN);
+  ClutterActor *next = NULL;
 
   ClutterActor *tail = gnibbles_worm_get_tail_actor (worm);
-  ClutterActor *next = g_list_previous (g_list_last (worm->list))->data;
+
+  if (g_list_length (worm->list) >= 2)
+    next = g_list_previous (g_list_last (worm->list))->data;
+  else
+    return worm->direction;
   
   g_object_get_property (G_OBJECT (tail), "repeat-x", &val);
   is_horizontal = g_value_get_boolean (&val);
 
+  g_object_get_property (G_OBJECT (next), "repeat-x", &val);
+
+  if (is_horizontal == g_value_get_boolean (&val))
+    return worm->direction;
+
   clutter_actor_get_position (CLUTTER_ACTOR (next), &x2, &y2);
   clutter_actor_get_size (CLUTTER_ACTOR (next), &w, &h);
   clutter_actor_get_position (CLUTTER_ACTOR (tail), &x1, &y1);
@@ -424,7 +434,7 @@ gnibbles_worm_destroy (GnibblesWorm *worm)
     gnibbles_worm_remove_actor (worm);
 
   g_list_free (worm->list);
-  g_free (worm->actors);
+  //g_free (worm->actors);
 }
 
 void
@@ -451,41 +461,46 @@ void
 gnibbles_worm_reset (GnibblesWorm * worm)
 {
   ClutterActor *tail_actor = NULL;
-  gint length = gnibbles_worm_get_length (worm);
-  gint actor_length;
+  gint tail_length;
   gint tail_dir;
-  gint i;
+  gint i,j;
 
-  while (length != 0) {
-    //while (actor_length != 0)
+  gint nbr_actor = clutter_group_get_n_children (CLUTTER_GROUP (worm->actors));
+
+  for (j = 0; j < nbr_actor; j++) {
     tail_dir = gnibbles_worm_get_tail_direction (worm);
     tail_actor = gnibbles_worm_get_tail_actor (worm);
-    actor_length = gnibbles_worm_get_actor_length (tail_actor);
+    tail_length = gnibbles_worm_get_actor_length (tail_actor);
+    
     switch (tail_dir) {
       case WORMUP:
-        for (i = 0; i < actor_length; i++)
+        for (i = 0; i < tail_length; i++)
           level->walls[worm->xtail][worm->ytail--] = EMPTYCHAR;
         break;
       case WORMDOWN:
-        for (i = 0; i < actor_length; i++)
+        for (i = 0; i < tail_length; i++)
           level->walls[worm->xtail][worm->ytail++] = EMPTYCHAR;
         break;
       case WORMLEFT:
-        for (i = 0; i < actor_length; i++)
+        for (i = 0; i < tail_length; i++)
           level->walls[worm->xtail--][worm->ytail] = EMPTYCHAR;
         break;
       case WORMRIGHT:
-        for (i = 0; i < actor_length; i++)
+        for (i = 0; i < tail_length; i++)
           level->walls[worm->xtail++][worm->ytail] = EMPTYCHAR;
         break;
       default:
         break;
     }
-    length--;
+
+    gnibbles_worm_remove_actor (worm);
   }
-  gnibbles_worm_new (worm->number, worm->xstart, worm->ystart, worm->direction_start);
-  gnibbles_worm_destroy (worm);
 
+  worms[worm->number] = gnibbles_worm_new (worm->number, 
+                                           worm->xstart, 
+                                           worm->ystart, 
+                                           worm->direction_start);
+  gnibbles_worm_destroy (worm);
 }
 
 void 
@@ -742,7 +757,7 @@ gnibbles_worm_move_tail (GnibblesWorm *worm)
   gfloat w,h;
   gfloat x,y;
   gfloat size;
-  gint tmp_dir;
+  gint tail_dir;
 
   ClutterActor *tail = gnibbles_worm_get_tail_actor (worm);
 
@@ -754,8 +769,8 @@ gnibbles_worm_move_tail (GnibblesWorm *worm)
   if (size <= 0) {
      gnibbles_worm_remove_actor (worm);
   } else {
-    tmp_dir = gnibbles_worm_get_tail_direction (worm);
-    switch (tmp_dir) {
+    tail_dir = gnibbles_worm_get_tail_direction (worm);
+    switch (tail_dir) {
       case WORMRIGHT:
         clutter_actor_set_size (CLUTTER_ACTOR (tail), 
                                 size, 



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