[gnome-games/gnibbles-clutter] Rotation on bonus, still need polish, also trying to fix bugs in collision
- From: Guillaume Béland <guillaubel src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games/gnibbles-clutter] Rotation on bonus, still need polish, also trying to fix bugs in collision
- Date: Wed, 22 Jul 2009 17:36:44 +0000 (UTC)
commit 3c5da0529aea997d952ad646964d98e86c8a32d1
Author: Guillaume Beland <guillaume beland gmail com>
Date: Wed Jul 22 13:35:01 2009 -0400
Rotation on bonus, still need polish, also trying to fix bugs in collision
detection
gnibbles/bonus.c | 29 ++++++++++++++++++++++--
gnibbles/bonus.h | 1 +
gnibbles/gnibbles.c | 2 +-
gnibbles/worm-clutter.c | 54 ++++++++++++++++++++---------------------------
4 files changed, 51 insertions(+), 35 deletions(-)
---
diff --git a/gnibbles/bonus.c b/gnibbles/bonus.c
index 210ec35..c4a8b72 100644
--- a/gnibbles/bonus.c
+++ b/gnibbles/bonus.c
@@ -26,6 +26,8 @@
#include <clutter/clutter.h>
#include <clutter-gtk/clutter-gtk.h>
+#include <libgames-support/games-runtime.h>
+
#include "gnibbles.h"
#include "bonus.h"
#include "properties.h"
@@ -49,23 +51,44 @@ gnibbles_bonus_new (gint t_x, gint t_y, gint t_type,
tmp->fake = t_fake;
tmp->countdown = t_countdown;
tmp->actor = clutter_texture_new ();
-
return (tmp);
}
void
gnibbles_bonus_draw (GnibblesBonus *bonus)
{
- gtk_clutter_texture_set_from_pixbuf (CLUTTER_TEXTURE (bonus->actor),
- boni_pixmaps[bonus->type]);
+ 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,
"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);
}
void
diff --git a/gnibbles/bonus.h b/gnibbles/bonus.h
index 6571a08..091bac8 100644
--- a/gnibbles/bonus.h
+++ b/gnibbles/bonus.h
@@ -25,6 +25,7 @@
#include <gtk/gtk.h>
#include <clutter/clutter.h>
+#include <cogl/cogl.h>
#define BONUSNONE 0
#define BONUSREGULAR 1
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index 282a411..64b99c5 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -219,7 +219,7 @@ gnibbles_init ()
gint
gnibbles_move_worms (void)
{
- gint i, j, olddir, length, nbr_actor;
+ gint i, j, olddir;
gint status = 1, nlives = 1;
gboolean *dead;
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index 456608a..7ff8d35 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -74,7 +74,6 @@ gnibbles_worm_queue_keypress (GnibblesWorm * worm, guint dir)
/* Ignore duplicates in normal movement mode. This resolves the
* key repeat issue. We ignore this in relative mode because then
* you do want two keys that are the same in quick succession. */
- printf ("\nfail here 1");
if ((!properties->wormprops[worm->number]->relmove) &&
(!g_queue_is_empty (key_queue[n])) &&
(dir == ((key_queue_entry *) g_queue_peek_tail (key_queue[n]))->dir))
@@ -131,7 +130,6 @@ gnibbles_worm_queue_empty (GnibblesWorm * worm)
if (!key_queue[n])
return;
- printf ("\nfail here 2");
while (!g_queue_is_empty (key_queue[n])) {
entry = g_queue_pop_head (key_queue[n]);
g_free (entry);
@@ -253,7 +251,7 @@ gnibbles_worm_grok_bonus (GnibblesWorm *worm)
for (i = 0; i < properties->numworms; i++)
if (worm != worms[i])
g_timeout_add (1, (GSourceFunc)
- gnibbles_worm_inverse, worms[i]);
+ gnibbles_worm_inverse, worms[i]);
games_sound_play ("reverse");
break;
}
@@ -357,6 +355,8 @@ void
gnibbles_worm_add_actor (GnibblesWorm *worm)
{
ClutterActor *actor = NULL;
+ ClutterActor *head = NULL;
+
GValue val = {0,};
actor = gtk_clutter_texture_new_from_pixbuf (worm_pixmaps[worm->number]);
@@ -366,19 +366,17 @@ gnibbles_worm_add_actor (GnibblesWorm *worm)
g_object_set_property (G_OBJECT (actor), "keep-aspect-ratio", &val);
- ClutterActor *tmp = NULL;
-
if (worm->list)
- tmp = gnibbles_worm_get_head_actor (worm);
+ 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 worm's head, set its size
- if (!tmp) {
+ // if it's the first actor, set its size
+ if (!head) {
clutter_actor_set_size (CLUTTER_ACTOR (actor),
- properties->tilesize * worm->length,
+ properties->tilesize * SLENGTH,
properties->tilesize);
} else {
@@ -387,11 +385,11 @@ gnibbles_worm_add_actor (GnibblesWorm *worm)
g_object_set_property (G_OBJECT (actor), "repeat-x", &val);
} else if (worm->direction == WORMDOWN || worm->direction == WORMUP) {
- // if it's the worm's head, set its size
- if (!tmp) {
+ // if it's the first actor, set its size
+ if (!head) {
clutter_actor_set_size (CLUTTER_ACTOR (actor),
properties->tilesize,
- properties->tilesize * worm->length);
+ properties->tilesize * SLENGTH);
} else {
clutter_actor_set_size (CLUTTER_ACTOR (actor), properties->tilesize, 0);
}
@@ -400,7 +398,7 @@ gnibbles_worm_add_actor (GnibblesWorm *worm)
}
//if it's the head, set its position according to its direction
- if (!tmp) {
+ if (!head) {
if (worm->direction == WORMLEFT || worm->direction == WORMUP) {
clutter_actor_set_position (CLUTTER_ACTOR (actor),
worm->xhead * properties->tilesize,
@@ -508,6 +506,7 @@ gnibbles_worm_reset (GnibblesWorm * worm)
worm->xtail = worm->xhead;
worm->ytail = worm->yhead;
worm->direction = worm->direction_start;
+ worm->length = 0;
if (!(worm->lives <= 0))
gnibbles_worm_add_actor (worm);
@@ -591,8 +590,7 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
case WORMRIGHT:
clutter_actor_set_position (CLUTTER_ACTOR (head),
x + properties->tilesize, y);
- level->walls[worm->xhead][worm->yhead] = WORMCHAR;
- worm->xhead++;
+ level->walls[++worm->xhead][worm->yhead] = WORMCHAR;
level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
if (worm->xtail == BOARDWIDTH)
worm->xtail = 0;
@@ -602,8 +600,7 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
case WORMDOWN:
clutter_actor_set_position (CLUTTER_ACTOR (head),
x, y + properties->tilesize);
- level->walls[worm->xhead][worm->yhead] = WORMCHAR;
- worm->yhead++;
+ level->walls[worm->xhead][++worm->yhead] = WORMCHAR;
level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
if (worm->ytail == BOARDHEIGHT)
worm->ytail = 0;
@@ -613,8 +610,7 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
case WORMLEFT:
clutter_actor_set_position (CLUTTER_ACTOR (head),
x - properties->tilesize, y);
- level->walls[worm->xhead][worm->yhead] = WORMCHAR;
- worm->xhead--;
+ level->walls[--worm->xhead][worm->yhead] = WORMCHAR;
level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
if (worm->xtail == 0)
worm->xtail = BOARDWIDTH - 1;
@@ -624,8 +620,7 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
case WORMUP:
clutter_actor_set_position (CLUTTER_ACTOR (head),
x, y - properties->tilesize);
- level->walls[worm->xhead][worm->yhead] = WORMCHAR;
- worm->yhead--;
+ level->walls[worm->xhead][--worm->yhead] = WORMCHAR;
level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
if (worm->ytail == 0)
worm->ytail = BOARDHEIGHT - 1;
@@ -635,7 +630,7 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
default:
break;
}
- printf ("\nfail here 3");
+
if (key_queue[worm->number] && !g_queue_is_empty (key_queue[worm->number])) {
gnibbles_worm_dequeue_keypress (worm);
}
@@ -681,15 +676,13 @@ gnibbles_worm_move_head (GnibblesWorm *worm)
clutter_actor_set_size (CLUTTER_ACTOR (head),
size,
properties->tilesize);
- level->walls[worm->xhead][worm->yhead] = WORMCHAR;
- worm->xhead++;
+ level->walls[++worm->xhead][worm->yhead] = WORMCHAR;
break;
case WORMDOWN:
clutter_actor_set_size (CLUTTER_ACTOR (head),
properties->tilesize,
size);
- level->walls[worm->xhead][worm->yhead] = WORMCHAR;
- worm->yhead++;
+ level->walls[worm->xhead][++worm->yhead] = WORMCHAR;
break;
case WORMLEFT:
clutter_actor_set_size (CLUTTER_ACTOR (head),
@@ -697,8 +690,7 @@ gnibbles_worm_move_head (GnibblesWorm *worm)
properties->tilesize);
clutter_actor_set_position (CLUTTER_ACTOR (head),
x - properties->tilesize, y);
- level->walls[worm->xhead][worm->yhead] = WORMCHAR;
- worm->xhead--;
+ level->walls[--worm->xhead][worm->yhead] = WORMCHAR;
break;
case WORMUP:
clutter_actor_set_size (CLUTTER_ACTOR (head),
@@ -706,14 +698,13 @@ gnibbles_worm_move_head (GnibblesWorm *worm)
size);
clutter_actor_set_position (CLUTTER_ACTOR (head),
x, y - properties->tilesize);
- level->walls[worm->xhead][worm->yhead] = WORMCHAR;
- worm->yhead--;
+ level->walls[worm->xhead][--worm->yhead] = WORMCHAR;
break;
default:
break;
}
- printf ("\nfail here 4");
+ worm->length++;
if (key_queue[worm->number] && !g_queue_is_empty (key_queue[worm->number])) {
gnibbles_worm_dequeue_keypress (worm);
}
@@ -791,6 +782,7 @@ gnibbles_worm_move_tail (GnibblesWorm *worm)
break;
}
}
+ worm->length--;
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]