[gnome-games] Some improvement to reset and animate worm properly when they die, still need work



commit 96f5ca2de2960527f847cb4327b56c5aa8f2c5cd
Author: Guillaume Beland <guillaume beland gmail com>
Date:   Fri Aug 14 14:52:22 2009 -0400

    Some improvement to reset and animate worm properly when they die, still need work

 gnibbles/gnibbles.c |   18 ++++----
 gnibbles/worm.c     |  114 +++++++++++++++++++++++++++++++-------------------
 gnibbles/worm.h     |    3 +-
 3 files changed, 82 insertions(+), 53 deletions(-)
---
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index 18334c2..0cddc57 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -196,7 +196,7 @@ gnibbles_load_logo (void)
 void
 gnibbles_init ()
 {
-  if (board == NULL)
+  if (!board)
     return;
 
   gint i;
@@ -291,7 +291,7 @@ gnibbles_move_worms (void)
 	      worms[i]->score *= .7;
       if (!gnibbles_worm_lose_life (worms[i])) {
         /* One of the worms lost one life, but the round continues. */
-        gnibbles_worm_kill (worms[i]);
+        gnibbles_worm_reset (worms[i]);
 	      games_sound_play ("crash");
 	    }
     }
@@ -310,15 +310,15 @@ gnibbles_move_worms (void)
 
   if (nlives == 1 && (properties->ai + properties->human > 1)) {
     /* There is one player left, the other AI players are dead, and that player has won! */
-    return (VICTORY);
+    return VICTORY;
   } else if (nlives == 0) {
     /* There was only one worm, and it died. */
-    return (GAMEOVER);
+    return GAMEOVER;
   }
    /* Noone died, so the round can continue. */
 
   g_free (dead);
-  return (CONTINUE);
+  return CONTINUE;
 }
 
 gint
@@ -370,15 +370,15 @@ gnibbles_show_scores (GtkWidget * window, gint pos)
                                             highscores, 
                                             _("Nibbles Scores"));
     games_scores_dialog_set_category_description (GAMES_SCORES_DIALOG
-						  (scoresdialog),
-						  _("Speed:"));
+	                                                (scoresdialog),
+                                                  _("Speed:"));
   }
   if (pos > 0) {
     games_scores_dialog_set_hilight (GAMES_SCORES_DIALOG (scoresdialog), pos);
     message = g_strdup_printf ("<b>%s</b>\n\n%s",
-			                         _("Congratulations!"),
+                               _("Congratulations!"),
                                pos == 1 ? _("Your score is the best!") :
-			                         _("Your score has made the top ten."));
+                               _("Your score has made the top ten."));
     games_scores_dialog_set_message (GAMES_SCORES_DIALOG (scoresdialog),
 				     message);
     g_free (message);
diff --git a/gnibbles/worm.c b/gnibbles/worm.c
index 655b6c7..9ed3ed6 100644
--- a/gnibbles/worm.c
+++ b/gnibbles/worm.c
@@ -453,43 +453,35 @@ gnibbles_worm_move_tail_pointer (GnibblesWorm *worm)
     worm->ytail = 0;
 }
 
-static void *
+static void 
 gnibbles_worm_animate_death (GnibblesWorm *worm)
 {
-  ClutterAnimation *animation = NULL;
-
-  animation = clutter_actor_animate (worm->actors, CLUTTER_EASE_OUT_QUAD, 210,
-                                     "opacity", 0,
-                                     "scale-x", 2.0,
-                                     "scale-y", 2.0,
-                                     "fixed::scale-center-x", 
-                                     (gfloat) worm->xhead * properties->tilesize,
-                                     "fixed::scale-center-y",
-                                     (gfloat) worm->yhead * properties->tilesize,
-                                     NULL);
-
-  return animation;
-}
-
-static void
-gnibbles_worm_reset (ClutterAnimation *anim, GnibblesWorm *worm)
-{
-  gint j;
-
-  for (j = 0; j < g_list_length(worm->list); j++)
-    gnibbles_worm_move_tail_pointer (worm);
-
-  worm->xhead = worm->xstart;
-  worm->yhead = worm->ystart;
-  worm->xtail = worm->xhead;
-  worm->ytail = worm->yhead;
-  worm->direction = worm->direction_start;
-  worm->length = 1;
-
-  if (!(worm->lives <= 0)) {
-    worm->change = SLENGTH - 1;
-    gnibbles_worm_show (worm);
+  ClutterActor *group = clutter_group_new ();
+  ClutterActor *tmp = NULL;
+  int i;
+  gfloat x,y;
+
+  for (i = 0; i < g_list_length (worm->list); i++) {
+    tmp = gtk_clutter_texture_new_from_pixbuf (worm_pixmaps [worm->number]);
+    clutter_actor_get_position (CLUTTER_ACTOR (g_list_nth_data (worm->list, i)),
+                                &x, &y);
+    clutter_actor_set_position (CLUTTER_ACTOR (tmp), x, y);
+    clutter_actor_set_size (CLUTTER_ACTOR (tmp), 
+                            properties->tilesize,
+                            properties->tilesize);
+    clutter_container_add_actor (CLUTTER_CONTAINER (group), tmp);
   }
+  clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
+
+  clutter_actor_animate (group, CLUTTER_EASE_OUT_QUAD, 210,
+                         "opacity", 0,
+                         "scale-x", 2.0,
+                         "scale-y", 2.0,
+                         "fixed::scale-center-x", 
+                         (gfloat) worm->xhead * properties->tilesize,
+                         "fixed::scale-center-y",
+                         (gfloat) worm->yhead * properties->tilesize,
+                         NULL);
 }
 
 GnibblesWorm*
@@ -503,6 +495,7 @@ gnibbles_worm_new (guint number, guint t_xhead,
   worm->number = number;
   worm->lives = SLIVES;
   worm->human = FALSE;
+  worm->stop = FALSE;
 
   worm->xhead = t_xhead;
   worm->xstart = t_xhead;
@@ -532,6 +525,45 @@ gnibbles_worm_show (GnibblesWorm *worm)
                          "fixed::scale-gravity", CLUTTER_GRAVITY_CENTER,
                          "opacity", 0xff,
                          NULL);
+  worm->stop = FALSE;
+}
+
+void
+gnibbles_worm_reset (GnibblesWorm *worm)
+{
+  worm->stop = TRUE;
+  gnibbles_worm_animate_death (worm);
+
+  gint j;
+
+  for (j = 0; j < g_list_length(worm->list); j++)
+    gnibbles_worm_move_tail_pointer (worm);
+
+  worm->xhead = worm->xstart;
+  worm->yhead = worm->ystart;
+  worm->xtail = worm->xhead;
+  worm->ytail = worm->yhead;
+  worm->direction = worm->direction_start;
+  worm->length = 1;
+
+  if (worm->lives > 0) {
+    worm->change = SLENGTH - 1;
+    gnibbles_worm_show (worm);
+  }
+  
+  gint i;
+  FILE *fo;
+  fo = fopen ("level_output", "w");
+  for (i = 0; i < BOARDHEIGHT; i++) {
+    for (j = 0; j < BOARDHEIGHT; j++) {
+      if (board->walls[j][i] == 'a')
+        fprintf (fo, "%c", ' ');
+      else
+        fprintf (fo, "%c", board->walls[j][i]);
+    }
+    fprintf (fo, "\n");
+  }
+  fclose (fo);
 }
 
 void
@@ -545,14 +577,6 @@ gnibbles_worm_destroy (GnibblesWorm *worm)
   g_free (worm);
 }
 
-void
-gnibbles_worm_kill (GnibblesWorm *worm)
-{
-  g_signal_connect_after (
-    gnibbles_worm_animate_death (worm),
-    "completed", G_CALLBACK (gnibbles_worm_reset), (gpointer)worm);
-}
-
 void 
 gnibbles_worm_resize (GnibblesWorm *worm, gint newtile)
 {
@@ -646,6 +670,8 @@ gnibbles_cworm_move (ClutterTimeline *timeline, gint frame_num, gpointer data)
 void
 gnibbles_worm_move_head (GnibblesWorm *worm)
 {
+  if (worm->stop)
+    return;
   if (g_list_length (worm->list) <= 1)
     return;
 
@@ -662,6 +688,8 @@ gnibbles_worm_move_head (GnibblesWorm *worm)
 void
 gnibbles_worm_move_tail (GnibblesWorm *worm)
 {
+  if (worm->stop)
+    return;
   if (g_list_length (worm->list) <= 1)
     return;
 
@@ -685,7 +713,7 @@ gnibbles_worm_reduce_tail (GnibblesWorm *worm, gint erasesize)
 
   if (erasesize) {
     if (g_list_length (worm->list) <= erasesize) {
-      gnibbles_worm_kill (worm);
+      gnibbles_worm_reset (worm);
       return;
     }
 
diff --git a/gnibbles/worm.h b/gnibbles/worm.h
index e3d86b6..1e15b2f 100644
--- a/gnibbles/worm.h
+++ b/gnibbles/worm.h
@@ -52,6 +52,7 @@ typedef struct {
   gint change;
   gint keypress;
   gboolean human;
+  gboolean stop;
 } GnibblesWorm;
 
 void worm_set_direction (int worm, int dir);
@@ -68,7 +69,7 @@ void gnibbles_worm_destroy (GnibblesWorm * worm);
 
 void gnibbles_worm_resize (GnibblesWorm *worm, gint newtile);
 
-void gnibbles_worm_kill (GnibblesWorm *worm);
+void gnibbles_worm_reset (GnibblesWorm *worm);
 void gnibbles_worm_move_head (GnibblesWorm *worm);
 void gnibbles_worm_move_tail (GnibblesWorm *worm);
 void gnibbles_worm_reduce_tail (GnibblesWorm *worm, gint erasesize);



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