[gnome-games/gnibbles-clutter-rebased: 89/129] Some work on bonus/erasing tail, animation on warp and small fix to bonus anim
- From: Jason Clinton <jclinton src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-games/gnibbles-clutter-rebased: 89/129] Some work on bonus/erasing tail, animation on warp and small fix to bonus anim
- Date: Mon, 12 Oct 2009 21:33:42 +0000 (UTC)
commit 024449a57776cb8e6129e99f70f23e029911119a
Author: Guillaume Beland <guillaume beland gmail com>
Date: Fri Aug 7 20:54:33 2009 -0400
Some work on bonus/erasing tail, animation on warp and small fix to bonus anim
gnibbles/board.c | 5 +
gnibbles/bonus.c | 2 +
gnibbles/gnibbles.c | 27 ++-----
gnibbles/main.c | 7 +-
gnibbles/warp.c | 32 ++++++++-
gnibbles/worm-clutter.c | 190 ++++++++++++++++++++++-------------------------
gnibbles/worm-clutter.h | 3 +-
7 files changed, 138 insertions(+), 128 deletions(-)
---
diff --git a/gnibbles/board.c b/gnibbles/board.c
index ec7a45b..2bae893 100644
--- a/gnibbles/board.c
+++ b/gnibbles/board.c
@@ -235,6 +235,11 @@ gnibbles_board_level_new (GnibblesBoard *board, gint level)
g_free (message);
}
+ if (warpmanager)
+ gnibbles_warpmanager_destroy (warpmanager);
+
+ warpmanager = gnibbles_warpmanager_new ();
+
if (boni)
gnibbles_boni_destroy (boni);
diff --git a/gnibbles/bonus.c b/gnibbles/bonus.c
index 33f0f6b..2069007 100644
--- a/gnibbles/bonus.c
+++ b/gnibbles/bonus.c
@@ -62,6 +62,7 @@ animate_bonus1 (ClutterAnimation *animation, ClutterActor *actor)
clutter_actor_animate (actor, CLUTTER_LINEAR, 1100,
"scale-x", 1.22, "scale-y", 1.22,
"fixed::scale-gravity", CLUTTER_GRAVITY_CENTER,
+ "opacity", 0xDC,
NULL),
"completed", G_CALLBACK (animate_bonus2), actor);
@@ -74,6 +75,7 @@ animate_bonus2 (ClutterAnimation *animation, ClutterActor *actor)
clutter_actor_animate (actor, CLUTTER_LINEAR, 1100,
"scale-x", 0.9, "scale-y", 0.9,
"fixed::scale-gravity", CLUTTER_GRAVITY_CENTER,
+ "opacity", 0xFF,
NULL),
"completed", G_CALLBACK (animate_bonus1), actor);
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index 8e0467d..3331115 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -265,44 +265,29 @@ gnibbles_move_worms (void)
}
}
- //TODO: erase tail here
-
for (i = 0; i < properties->numworms; i++) {
dead[i] = !gnibbles_worm_test_move_head (worms[i]);
status &= !dead[i];
}
for (i = 0; i < properties->numworms; i++) {
- if (g_list_length (worms[i]->list) > 1 && !dead[i] && worms[i]->lives > 0)
+ if (!dead[i] && worms[i]->lives > 0)
gnibbles_worm_move_tail (worms[i]);
}
for (i = 0; i < properties->numworms; i++) {
- if (g_list_length (worms[i]->list) > 1 && !dead[i] && worms[i]->lives > 0)
+ if (!dead[i] && worms[i]->lives > 0)
gnibbles_worm_move_head (worms[i]);
}
- //printf ("XHEAD: %d, YHEAD %d \n", worms[0]->xhead, worms[0]->yhead);
- //printf ("XTAIL: %d, YTAIL %d \n", worms[0]->xtail, worms[0]->ytail);
- for (i = 0; i < properties->numworms; i++) {
- if (worms[i]->xhead >= BOARDWIDTH) {
- worms[i]->xhead = 0;
- } else if (worms[i]->xhead <= 0) {
- worms[i]->xhead = BOARDWIDTH;
- } else if (worms[i]->yhead >= BOARDHEIGHT) {
- worms[i]->yhead = 0;
- } else if (worms[i]->xhead <= 0) {
- worms[i]->yhead = BOARDHEIGHT;
- }
- }
-
for (i = 0; i < properties->numworms; i++) {
for (j = 0; j < properties->numworms; j++) {
- if (i != j && worms[i]->xhead == worms[j]->xhead
+ if (i != j
+ && worms[i]->xhead == worms[j]->xhead
&& worms[i]->yhead == worms[j]->yhead
&& worms[i]->lives > 0
&& worms[j]->lives > 0)
- dead[i] = TRUE;
+ dead[i] = TRUE;
}
}
@@ -377,7 +362,7 @@ gnibbles_undraw_worms (gint data)
gint i;
for (i = 0; i < properties->numworms; i++)
- gnibbles_worm_shrink (worms[i], data);
+ gnibbles_worm_reduce_tail (worms[i], data);
//gnibbles_worm_undraw_nth (worms[i], data);
}
diff --git a/gnibbles/main.c b/gnibbles/main.c
index 94c5605..d69a364 100644
--- a/gnibbles/main.c
+++ b/gnibbles/main.c
@@ -929,10 +929,11 @@ on_hide_logo_completed (ClutterAnimation *animation, ClutterActor *actor)
static void
hide_logo (void)
{
- clutter_actor_animate (logo, CLUTTER_EASE_IN_QUAD, 100,
+ g_signal_connect_after (
+ clutter_actor_animate (logo, CLUTTER_EASE_IN_QUAD, 150,
"opacity", 0,
- "signal::completed", on_hide_logo_completed, logo,
- NULL);
+ NULL),
+ "completed", G_CALLBACK (on_hide_logo_completed), logo);
}
int
diff --git a/gnibbles/warp.c b/gnibbles/warp.c
index d33d1c5..fd3ec24 100644
--- a/gnibbles/warp.c
+++ b/gnibbles/warp.c
@@ -34,6 +34,32 @@ extern GdkPixbuf *boni_pixmaps[];
extern GnibblesBoard *board;
extern ClutterActor *stage;
+static void animate_warp1 (ClutterAnimation *animation, ClutterActor *actor);
+static void animate_warp2 (ClutterAnimation *animation, ClutterActor *actor);
+
+static void
+animate_warp1 (ClutterAnimation *animation, ClutterActor *actor)
+{
+ g_signal_connect_after (
+ clutter_actor_animate (actor, CLUTTER_LINEAR, 1100,
+ "opacity", 0x96,
+ NULL),
+ "completed", G_CALLBACK (animate_warp2), actor);
+
+}
+
+static void
+animate_warp2 (ClutterAnimation *animation, ClutterActor *actor)
+{
+ g_signal_connect_after (
+ clutter_actor_animate (actor, CLUTTER_LINEAR, 1100,
+ "opacity", 0xff,
+ NULL),
+ "completed", G_CALLBACK (animate_warp1), actor);
+
+}
+
+
GnibblesWarp *
gnibbles_warp_new (gint t_x, gint t_y, gint t_wx, gint t_wy)
{
@@ -67,9 +93,11 @@ gnibbles_warp_draw (GnibblesWarp *warp)
clutter_container_add_actor (CLUTTER_CONTAINER (stage), warp->actor);
clutter_actor_set_opacity (warp->actor, 0);
clutter_actor_set_scale (warp->actor, 2.0, 2.0);
- clutter_actor_animate (warp->actor, CLUTTER_EASE_OUT_CIRC, 410,
+ g_signal_connect_after (
+ clutter_actor_animate (warp->actor, CLUTTER_EASE_OUT_CIRC, 410,
"scale-x", 1.0, "scale-y", 1.0,
"fixed::scale-gravity", CLUTTER_GRAVITY_CENTER,
"opacity", 0xff,
- NULL);
+ NULL),
+ "completed", G_CALLBACK (animate_warp1), warp->actor);
}
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index 751aea8..51ab876 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -149,13 +149,13 @@ gnibbles_worm_dequeue_keypress (GnibblesWorm * worm)
g_free (entry);
}
-/*
+
static ClutterActor*
gnibbles_worm_get_head_actor (GnibblesWorm *worm)
{
return CLUTTER_ACTOR (g_list_first (worm->list)->data);
}
-*/
+
static ClutterActor*
gnibbles_worm_get_tail_actor (GnibblesWorm *worm)
{
@@ -234,6 +234,63 @@ gnibbles_worm_handle_keypress (GnibblesWorm * worm, guint keyval)
return FALSE;
}
+static gint
+gnibbles_worm_get_tail_direction (GnibblesWorm *worm)
+{
+ gfloat x1,y1,x2,y2;
+ ClutterActor *next = NULL;
+ ClutterActor *tail = gnibbles_worm_get_tail_actor (worm);
+
+ if (g_list_length (worm->list) >= 2)
+ next = g_list_previous (g_list_last (worm->list))->data;
+ else
+ return worm->direction;
+
+ clutter_actor_get_position (CLUTTER_ACTOR (next), &x2, &y2);
+ clutter_actor_get_position (CLUTTER_ACTOR (tail), &x1, &y1);
+
+ if (x2 > x1 && y1 == y2)
+ return WORMRIGHT;
+ else if (x2 < x1 && y1 == y2)
+ return WORMLEFT;
+ else if (y2 > y1 && x1 == x2)
+ return WORMDOWN;
+ else if (y2 < y1 && x1 == x2)
+ return WORMUP;
+ else
+ return -1;
+}
+
+static void
+gnibbles_worm_inverse (gpointer data)
+{
+ GnibblesWorm *worm;
+ worm = (GnibblesWorm *) 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;
+ worm->xhead = worm->xtail;
+ worm->xtail = tmp;
+ tmp = worm->yhead;
+ worm->yhead = worm->ytail;
+ worm->ytail = tmp;
+ tmp = worm->yhead;
+}
+
static void
gnibbles_worm_grok_bonus (GnibblesWorm *worm)
{
@@ -278,33 +335,6 @@ gnibbles_worm_grok_bonus (GnibblesWorm *worm)
}
}
-static gint
-gnibbles_worm_get_tail_direction (GnibblesWorm *worm)
-{
- gfloat x1,y1,x2,y2;
- ClutterActor *next = NULL;
- ClutterActor *tail = gnibbles_worm_get_tail_actor (worm);
-
- if (g_list_length (worm->list) >= 2)
- next = g_list_previous (g_list_last (worm->list))->data;
- else
- return worm->direction;
-
- clutter_actor_get_position (CLUTTER_ACTOR (next), &x2, &y2);
- clutter_actor_get_position (CLUTTER_ACTOR (tail), &x1, &y1);
-
- if (x2 > x1 && y1 == y2)
- return WORMRIGHT;
- else if (x2 < x1 && y1 == y2)
- return WORMLEFT;
- else if (y2 > y1 && x1 == x2)
- return WORMDOWN;
- else if (y2 < y1 && x1 == x2)
- return WORMUP;
- else
- return -1;
-}
-
static void
gnibbles_worm_reset (ClutterAnimation *animation, gpointer data)
{
@@ -324,24 +354,12 @@ gnibbles_worm_reset (ClutterAnimation *animation, gpointer data)
worm->xtail = worm->xhead;
worm->ytail = worm->yhead;
worm->direction = worm->direction_start;
- worm->length = SLENGTH;
+ worm->length = 0;
if (!(worm->lives <= 0)) {
+ worm->change = SLENGTH - 1;
+ gnibbles_worm_move_head_pointer (worm);
gnibbles_worm_show (worm);
- if (worm->direction == WORMRIGHT) {
- for (j = 0; j < worm->length; j++)
- gnibbles_worm_move_head_pointer (worm);
- } else if ( worm->direction == WORMLEFT) {
- for (j = 0; j < worm->length; j++)
- gnibbles_worm_move_head_pointer (worm);
- } else if (worm->direction == WORMDOWN) {
- for (j = 0; j < worm->length; j++)
- gnibbles_worm_move_head_pointer (worm);
- } else if (worm->direction == WORMUP) {
- for (j = 0; j < worm->length; j++)
- gnibbles_worm_move_head_pointer (worm);
- }
- board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
}
/* DEBUG *//*
gint i;
@@ -398,14 +416,14 @@ gnibbles_worm_move_head_pointer (GnibblesWorm *worm)
break;
}
- if (worm->xhead == BOARDWIDTH)
+ if (worm->xhead <= 0)
+ worm->xhead = BOARDWIDTH;
+ if (worm->yhead <= 0)
+ worm->yhead = BOARDHEIGHT;
+ if (worm->xhead >= BOARDWIDTH)
worm->xhead = 0;
- if (worm->xhead <= 0)
- worm->xhead = BOARDWIDTH - 1;
- if (worm->yhead == BOARDHEIGHT)
+ if (worm->yhead >= BOARDHEIGHT)
worm->yhead = 0;
- if (worm->yhead <= 0)
- worm->yhead = BOARDHEIGHT - 1;
gnibbles_worm_add_actor (worm);
}
@@ -444,7 +462,11 @@ gnibbles_worm_handle_bonus (GnibblesWorm *worm)
if ((board->walls[worm->xhead][worm->yhead] == BONUSREGULAR + 'A') &&
!gnibbles_boni_fake (boni, worm->xhead, worm->yhead)) {
-
+ ClutterActor *actor = gnibbles_worm_get_head_actor (worm);
+ clutter_actor_animate (actor, CLUTTER_LINEAR, 300,
+ "scale-x", 1.3, "scale-y", 1.3,
+ "fixed::scale-gravity", CLUTTER_GRAVITY_CENTER,
+ NULL);
gnibbles_boni_remove_bonus_final (boni, worm->xhead, worm->yhead);
if (boni->numleft != 0)
@@ -515,37 +537,6 @@ gnibbles_worm_destroy (GnibblesWorm *worm)
}
void
-gnibbles_worm_inverse (gpointer data)
-{
- GnibblesWorm *worm;
- worm = (GnibblesWorm *) 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;
- worm->xhead = worm->xtail;
- worm->xtail = tmp;
- tmp = worm->yhead;
- worm->yhead = worm->ytail;
- worm->ytail = tmp;
- tmp = worm->yhead;
-
-}
-
-void
gnibbles_worm_kill (GnibblesWorm *worm)
{
g_signal_connect_after (
@@ -682,32 +673,31 @@ gnibbles_worm_move_tail (GnibblesWorm *worm)
}
void
-gnibbles_worm_shrink (GnibblesWorm *worm, gint shrinksize)
+gnibbles_worm_reduce_tail (GnibblesWorm *worm, gint erasesize)
{
ClutterActor *tmp = NULL;
ClutterActor *group = clutter_group_new ();
+ gint i;
- gint nbr_actor;
- int i;
-
- nbr_actor = g_list_length (worm->list);
+ if (erasesize) {
+ if (worm->length >= erasesize)
+ gnibbles_worm_kill (worm);
+ return;
- if (nbr_actor >= shrinksize)
- return; //TODO reset worm, dead
+ clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
- clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
+ for (i = 0; i < erasesize; i++) {
+ tmp = gnibbles_worm_get_tail_actor (worm);
+ clutter_container_remove_actor (CLUTTER_CONTAINER (worm->actors), tmp);
+ worm->list = g_list_delete_link (worm->list, g_list_last(worm->list));
+ clutter_container_add_actor (CLUTTER_CONTAINER (group), tmp);
+ gnibbles_worm_move_tail_pointer (worm);
+ }
- for (i = 0; i < shrinksize; i++) {
- tmp = gnibbles_worm_get_tail_actor (worm);
- clutter_container_remove_actor (CLUTTER_CONTAINER (worm->actors), tmp);
- worm->list = g_list_delete_link (worm->list, g_list_last(worm->list));
- clutter_container_add_actor (CLUTTER_CONTAINER (group), tmp);
- gnibbles_worm_move_tail_pointer (worm);
+ clutter_actor_animate (group, CLUTTER_EASE_IN_ELASTIC, 420,
+ "opacity", 0,
+ NULL);
}
-
- clutter_actor_animate (group, CLUTTER_EASE_IN_ELASTIC, 420,
- "opacity", 0,
- NULL);
}
gint
diff --git a/gnibbles/worm-clutter.h b/gnibbles/worm-clutter.h
index 9ede1f5..aad0a4d 100644
--- a/gnibbles/worm-clutter.h
+++ b/gnibbles/worm-clutter.h
@@ -66,13 +66,12 @@ void gnibbles_worm_move_head_pointer (GnibblesWorm *worm);
void gnibbles_worm_destroy (GnibblesWorm * worm);
-void gnibbles_worm_inverse (gpointer data);
void gnibbles_worm_resize (GnibblesWorm *worm, gint newtile);
void gnibbles_worm_kill (GnibblesWorm *worm);
void gnibbles_worm_move_head (GnibblesWorm *worm);
void gnibbles_worm_move_tail (GnibblesWorm *worm);
-void gnibbles_worm_shrink (GnibblesWorm *worm, gint shrinksize);
+void gnibbles_worm_reduce_tail (GnibblesWorm *worm, gint erasesize);
gint gnibbles_worm_lose_life (GnibblesWorm * worm);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]