[gnome-games] Moved to ClutterAnimation to animate bonus, work on worm animation when dying



commit 2e7d6fa6d55f11765eaae5be7b5ce8f8af76c649
Author: Guillaume Beland <guillaume beland gmail com>
Date:   Fri Jul 24 16:34:20 2009 -0400

    Moved to ClutterAnimation to animate bonus, work on worm animation when dying

 gnibbles/board.c        |    4 ++--
 gnibbles/bonus.c        |   42 ++++++++++++++++++++----------------------
 gnibbles/gnibbles.c     |    2 +-
 gnibbles/worm-clutter.c |   47 ++++++++++++++++++++++++++++++++++++++++-------
 gnibbles/worm-clutter.h |    3 ++-
 5 files changed, 65 insertions(+), 33 deletions(-)
---
diff --git a/gnibbles/board.c b/gnibbles/board.c
index 7c53777..8d2c7d9 100644
--- a/gnibbles/board.c
+++ b/gnibbles/board.c
@@ -67,7 +67,8 @@ gnibbles_board_new (ClutterActor *stage)
   filename = g_build_filename (dirname, "wall-small-empty.svg", NULL);
 
   board->surface = clutter_texture_new_from_file (filename, NULL);
-  
+ 
+  clutter_actor_set_opacity (board->surface, 215);
   g_value_init (&val, G_TYPE_BOOLEAN);
   g_value_set_boolean ( &val, TRUE);
 
@@ -165,7 +166,6 @@ gnibbles_board_load_level (GnibblesBoard *board, GnibblesLevel *level)
   clutter_actor_animate (board->level, CLUTTER_EASE_IN_QUAD, 410,
                          "opacity", 255,
                          NULL);
-
 }
 
 void
diff --git a/gnibbles/bonus.c b/gnibbles/bonus.c
index c4a8b72..87fe283 100644
--- a/gnibbles/bonus.c
+++ b/gnibbles/bonus.c
@@ -54,41 +54,39 @@ gnibbles_bonus_new (gint t_x, gint t_y, gint t_type,
   return (tmp);
 }
 
+static void
+animate_bonus (ClutterAnimation *animation, ClutterActor *actor)
+{
+  ClutterVertex center;
+  ClutterAnimation *anim;
+
+  center = (ClutterVertex){(gfloat)properties->tilesize, 0, 0};
+  anim = clutter_actor_animate (actor, CLUTTER_LINEAR, 1300,
+                         "rotation-angle-y", 360.f,
+                         "fixed::rotation-center-y", &center,
+                         NULL);
+  clutter_animation_set_loop (anim, TRUE);
+  
+}
+
 void
 gnibbles_bonus_draw (GnibblesBonus *bonus)
 {
-  ClutterTimeline *timeline;
-  ClutterBehaviour *r_behave;
-
   clutter_actor_set_position (CLUTTER_ACTOR (bonus->actor),
                               bonus->x * properties->tilesize,
                               bonus->y * properties->tilesize);
 
-  clutter_actor_set_anchor_point (CLUTTER_ACTOR (bonus->actor), 
-                              properties->tilesize,
-                              0);
-
   gtk_clutter_texture_set_from_pixbuf (CLUTTER_TEXTURE (bonus->actor),
                                        boni_pixmaps[bonus->type]);
 
   clutter_container_add_actor (CLUTTER_CONTAINER (board->stage), bonus->actor);
-  
+
   clutter_actor_set_opacity (bonus->actor, 0);
-  clutter_actor_animate (bonus->actor, CLUTTER_EASE_IN_QUAD, 410,
+  g_signal_connect_after (
+    clutter_actor_animate (bonus->actor, CLUTTER_EASE_IN_QUAD, 500,
                          "opacity", 0xff,
-                         NULL);
-
-  timeline = clutter_timeline_new (4692);
-  clutter_timeline_set_loop (timeline, TRUE);
- 
-  r_behave =
-      clutter_behaviour_rotate_new (clutter_alpha_new_full (timeline, CLUTTER_LINEAR),
-                                    CLUTTER_Y_AXIS,
-                                    CLUTTER_ROTATE_CW,
-                                    0.0, 360.0);
-
-  clutter_behaviour_apply (r_behave, bonus->actor);
-  clutter_timeline_start (timeline);
+                          NULL),
+    "completed", G_CALLBACK (animate_bonus), bonus->actor);
 }
 
 void
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index d7ce34c..4b704d9 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -310,7 +310,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_reset (worms[i]);
+        gnibbles_worm_kill (worms[i]);
 	      games_sound_play ("crash");
 	    }
     }
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index c5488d3..dc98c21 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -39,7 +39,7 @@
 #include "bonus.h"
 #include "warpmanager.h"
 #include "properties.h"
-
+#include "board.h"
 #ifdef GGZ_CLIENT
 #include "ggz-network.h"
 #endif
@@ -52,6 +52,7 @@ extern GnibblesLevel *level;
 extern GnibblesBoni *boni;
 extern GnibblesWarpManager *warpmanager;
 extern GnibblesWorm *worms[NUMWORMS];
+extern GnibblesBoard *board;
 
 extern gint current_level;
 
@@ -470,20 +471,22 @@ gnibbles_worm_inverse (gpointer data)
   tmp = worm->yhead;
 }
 
-void
-gnibbles_worm_reset (GnibblesWorm * worm)
+static void
+gnibbles_worm_reset (ClutterAnimation *animation, gpointer data)
 {
+  GnibblesWorm *worm = (GnibblesWorm *)data;
+
   ClutterActor *tail_actor = NULL;
   gint tail_length;
   gint tail_dir;
   gint i,j;
-  gint nbr_actor = g_list_length (worm->list); 
+  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); 
-
+    
     switch (tail_dir) {
       case WORMUP:
         for (i = 0; i < tail_length; i++)
@@ -516,8 +519,8 @@ gnibbles_worm_reset (GnibblesWorm * worm)
   worm->length = SLENGTH;
 
   if (!(worm->lives <= 0)) {
-    gnibbles_worm_add_actor (worm);
-
+    //gnibbles_worm_add_actor (worm);
+    gnibbles_worm_show (worm);
     level->walls[worm->xhead][worm->yhead] = WORMCHAR;
     if (worm->direction == WORMRIGHT) {
       for (j = 0; j < worm->length; j++)
@@ -549,6 +552,36 @@ gnibbles_worm_reset (GnibblesWorm * worm)
  */   
 }
 
+static void *
+gnibbles_worm_animate (GnibblesWorm *worm)
+{
+  ClutterVertex center;
+  gint i, length;
+  ClutterActor *actor;
+  ClutterAnimation *animation = NULL;
+
+  gint count = clutter_group_get_n_children (CLUTTER_GROUP (worm->actors));
+  for (i = 0; i < count; i++) {
+    actor = clutter_group_get_nth_child (CLUTTER_GROUP (worm->actors), i);
+    length = gnibbles_worm_get_actor_length (actor);
+    center = (ClutterVertex) { length /2, 0, 0};
+    animation = clutter_actor_animate (actor, CLUTTER_LINEAR, 700,
+                           "opacity", 0,
+                           "rotation-angle-z", 360.f * 2,
+                           "fixed::rotation-center-z", &center,
+                           NULL);
+  }
+  return animation;
+}
+
+void
+gnibbles_worm_kill (GnibblesWorm *worm)
+{
+  g_signal_connect_after (
+    gnibbles_worm_animate (worm),
+    "completed", G_CALLBACK (gnibbles_worm_reset), (gpointer)worm);
+}
+
 void 
 gnibbles_worm_resize (GnibblesWorm *worm, gint newtile)
 {
diff --git a/gnibbles/worm-clutter.h b/gnibbles/worm-clutter.h
index a251621..94984af 100644
--- a/gnibbles/worm-clutter.h
+++ b/gnibbles/worm-clutter.h
@@ -70,7 +70,8 @@ void gnibbles_worm_destroy (GnibblesWorm * worm);
 
 void gnibbles_worm_inverse (gpointer data);
 void gnibbles_worm_resize (GnibblesWorm *worm, gint newtile);
-void gnibbles_worm_reset (GnibblesWorm *worm);
+
+void gnibbles_worm_kill (GnibblesWorm *worm);
 void gnibbles_worm_move_straight_worm (GnibblesWorm *worm);
 void gnibbles_worm_move_head (GnibblesWorm *worm);
 void gnibbles_worm_move_tail (GnibblesWorm *worm);



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