[gnome-games/gnibbles-clutter-rebased: 21/129] Small fix regarding head & tail position and other small stuff
- From: Jason Clinton <jclinton src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-games/gnibbles-clutter-rebased: 21/129] Small fix regarding head & tail position and other small stuff
- Date: Mon, 12 Oct 2009 21:27:59 +0000 (UTC)
commit 3c84c6c13454b280dc19f767dee4c7aecd451f19
Author: Guillaume Beland <guillaume beland gmail com>
Date: Sat Jun 20 12:28:49 2009 -0400
Small fix regarding head & tail position and other small stuff
The game now hang in gnibbles_cworm_ai_wander for an unknown reason to date..
i'm investigating
gnibbles/level.c | 12 ++--
gnibbles/main.c | 21 +++----
gnibbles/worm-clutter.c | 140 +++++++++++++++++++++++++---------------------
3 files changed, 90 insertions(+), 83 deletions(-)
---
diff --git a/gnibbles/level.c b/gnibbles/level.c
index 0db6ace..afb2ab7 100644
--- a/gnibbles/level.c
+++ b/gnibbles/level.c
@@ -29,7 +29,7 @@
extern GnibblesCWorm *cworms[];
extern GnibblesProperties *properties;
-
+extern GnibblesWarpManager *warpmanager;
GnibblesLevel *
gnibbles_level_new (gint level)
{
@@ -98,7 +98,7 @@ gnibbles_level_new (gint level)
cworms[count] = gnibbles_cworm_new (count++, j, i, WORMRIGHT);
break;
case 'Q':
- //gnibbles_warpmanager_add_warp (warpmanager, j - 1, i - 1, -1, -1);
+ gnibbles_warpmanager_add_warp (warpmanager, j - 1, i - 1, -1, -1);
break;
case 'R':
case 'S':
@@ -109,8 +109,8 @@ gnibbles_level_new (gint level)
case 'X':
case 'Y':
case 'Z':
- //gnibbles_warpmanager_add_warp
- // (warpmanager, j - 1, i - 1, -board[j][i], 0);
+ gnibbles_warpmanager_add_warp
+ (warpmanager, j - 1, i - 1, -(lvl->walls[j][i]), 0);
break;
case 'r':
case 's':
@@ -121,8 +121,8 @@ gnibbles_level_new (gint level)
case 'x':
case 'y':
case 'z':
- //gnibbles_warpmanager_add_warp
- // (warpmanager, -(board[j][i] - 'a' + 'A'), 0, j, i);
+ gnibbles_warpmanager_add_warp
+ (warpmanager, -(lvl->walls[j][i] - 'a' + 'A'), 0, j, i);
lvl->walls[j][i] = EMPTYCHAR;
break;
}
diff --git a/gnibbles/main.c b/gnibbles/main.c
index dd747a1..a6e566c 100644
--- a/gnibbles/main.c
+++ b/gnibbles/main.c
@@ -1263,19 +1263,16 @@ render_logo (void)
static void
move_worm_cb (ClutterTimeline *timeline, gint msecs, gpointer data)
{
-
const int elapsed_time = clutter_timeline_get_elapsed_time (timeline);
const int duration = clutter_timeline_get_duration (timeline);
+
if (!(elapsed_time == duration))
return;
- gfloat w,h;
- gfloat x,y;
- guint size;
- gint i, olddir, length, tmp_dir;
+ gint i, olddir, length;
- for (i = 0; i < 4 /*numworms*/; i++) {
+ for (i = 0; i < properties->numworms; i++) {
// get the current direction of the worm
olddir = cworms[i]->direction;
// determine the new direction the worm will take
@@ -1285,18 +1282,16 @@ move_worm_cb (ClutterTimeline *timeline, gint msecs, gpointer data)
gnibbles_cworm_add_straight_actor (cworms[i]);
length = g_list_length (cworms[i]->list);
+ printf ("Worm ID: %d, Length:%d", i, length);
//if there's only one actor in the list, just move the actor
if (length == 1) {
gnibbles_cworm_move_straight_worm (cworms[i]);
} else if (length >= 2) {
gnibbles_cworm_move_head (cworms[i]);
gnibbles_cworm_move_tail (cworms[i]);
-
- if (size <= 0)
- gnibbles_cworm_remove_actor (cworms[i]);
- } else {
- //worm's dead
- return;
+ } else if ( length < 1) {
+ //worm's dead
+ return;
}
}
}
@@ -1381,7 +1376,7 @@ main (int argc, char **argv)
int i;
- level = gnibbles_level_new (5);
+ level = gnibbles_level_new (1);
gnibbles_board_load_level (board, level);
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index 05019aa..50504e9 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -99,27 +99,28 @@ gnibbles_cworm_add_straight_actor (GnibblesCWorm *worm)
}
if (worm->direction == WORMRIGHT || worm->direction == WORMLEFT) {
-
+ worm->xtail = worm->xhead;
if (worm->direction == WORMRIGHT)
- worm->xhead += properties->tilesize;
+ worm->xhead += size * properties->tilesize;
else
- worm->xhead -= properties->tilesize;
-
- if (!tmp)
+ worm->xhead -= size * properties->tilesize;
+
+ if (!tmp) {
clutter_actor_set_size (CLUTTER_ACTOR (actor),
properties->tilesize * size,
properties->tilesize);
- else
+ } else {
clutter_actor_set_size (CLUTTER_ACTOR (actor), 0, properties->tilesize);
+ }
g_object_set_property (G_OBJECT (actor), "repeat-x", &val);
} else if (worm->direction == WORMDOWN || worm->direction == WORMUP) {
-
+ worm->ytail = worm->ytail;
if (worm->direction == WORMDOWN)
- worm->yhead += properties->tilesize;
+ worm->yhead += size * properties->tilesize;
else
- worm->yhead -= properties->tilesize;
-
+ worm->yhead -= size * properties->tilesize;
+
if (!tmp)
clutter_actor_set_size (CLUTTER_ACTOR (actor),
properties->tilesize,
@@ -307,6 +308,7 @@ gnibbles_cworm_move (ClutterTimeline *timeline, gint frame_num, gpointer data)
void
gnibbles_cworm_move_straight_worm (GnibblesCWorm *worm)
{
+ //g_return_if_fail (!(g_list_length (worm->list) == 1));
gfloat x,y;
ClutterActor *head = g_list_first (worm->list)->data;
@@ -340,6 +342,7 @@ gnibbles_cworm_move_straight_worm (GnibblesCWorm *worm)
void
gnibbles_cworm_move_head (GnibblesCWorm *worm)
{
+ //g_return_if_fail (g_list_length (worm->list) <= 1);
gfloat w,h;
gfloat x,y;
guint size;
@@ -349,23 +352,25 @@ gnibbles_cworm_move_head (GnibblesCWorm *worm)
clutter_actor_get_size (CLUTTER_ACTOR (head), &w, &h);
clutter_actor_get_position (CLUTTER_ACTOR (head), &x, &y);
size = w < h ? h : w;
+ size = size + properties->tilesize;
+ size = size / properties->tilesize;
// set the size of the head actor
switch (worm->direction) {
case WORMRIGHT:
clutter_actor_set_size (CLUTTER_ACTOR (head),
- size + properties->tilesize,
+ size * properties->tilesize,
properties->tilesize);
worm->xhead += properties->tilesize;
break;
case WORMDOWN:
clutter_actor_set_size (CLUTTER_ACTOR (head),
properties->tilesize,
- size + properties->tilesize);
+ size * properties->tilesize);
worm->yhead += properties->tilesize;
break;
case WORMLEFT:
clutter_actor_set_size (CLUTTER_ACTOR (head),
- size + (2 * properties->tilesize),
+ size * (2 * properties->tilesize),
properties->tilesize);
clutter_actor_set_position (CLUTTER_ACTOR (head),
x - properties->tilesize, y);
@@ -374,7 +379,7 @@ gnibbles_cworm_move_head (GnibblesCWorm *worm)
case WORMUP:
clutter_actor_set_size (CLUTTER_ACTOR (head),
properties->tilesize,
- size + (2 * properties->tilesize));
+ size * (2 * properties->tilesize));
clutter_actor_set_position (CLUTTER_ACTOR (head),
x, y - properties->tilesize);
worm->yhead -= properties->tilesize;
@@ -387,6 +392,8 @@ gnibbles_cworm_move_head (GnibblesCWorm *worm)
void
gnibbles_cworm_move_tail (GnibblesCWorm *worm)
{
+ //g_return_if_fail ( g_list_length (worm->list) <= 1);
+
gfloat w,h;
gfloat x,y;
guint size;
@@ -397,44 +404,49 @@ gnibbles_cworm_move_tail (GnibblesCWorm *worm)
clutter_actor_get_size (CLUTTER_ACTOR (tail), &w, &h);
clutter_actor_get_position (CLUTTER_ACTOR (tail), &x, &y);
size = w < h ? h : w;
+ size = size - properties->tilesize;
+ size = size / properties->tilesize;
tmp_dir = gnibbles_cworm_get_next_actor_position (worm);
switch (tmp_dir) {
- case WORMRIGHT:
- clutter_actor_set_size (CLUTTER_ACTOR (tail),
- size - properties->tilesize,
+ case WORMRIGHT:
+ clutter_actor_set_size (CLUTTER_ACTOR (tail),
+ size * properties->tilesize,
+ properties->tilesize);
+ clutter_actor_set_position (CLUTTER_ACTOR (tail),
+ x + properties->tilesize, y);
+ worm->xtail -= properties->tilesize;
+ break;
+ case WORMDOWN:
+ clutter_actor_set_size (CLUTTER_ACTOR (tail),
+ properties->tilesize,
+ size * properties->tilesize);
+ clutter_actor_set_position (CLUTTER_ACTOR (tail),
+ x, y + properties->tilesize);
+ worm->ytail -= properties->tilesize;
+ break;
+ case WORMLEFT:
+ clutter_actor_set_size (CLUTTER_ACTOR (tail),
+ properties->tilesize * size,
properties->tilesize);
- clutter_actor_set_position (CLUTTER_ACTOR (tail),
- x + properties->tilesize, y);
- worm->xtail -= properties->tilesize;
- break;
- case WORMDOWN:
- clutter_actor_set_size (CLUTTER_ACTOR (tail),
- properties->tilesize,
- size - properties->tilesize);
- clutter_actor_set_position (CLUTTER_ACTOR (tail),
- x, y + properties->tilesize);
- worm->ytail -= properties->tilesize;
- break;
- case WORMLEFT:
- clutter_actor_set_size (CLUTTER_ACTOR (tail),
- properties->tilesize * size,
- properties->tilesize);
- clutter_actor_set_position (CLUTTER_ACTOR (tail),
- x - properties->tilesize, y);
- worm->xtail += properties->tilesize;
- break;
- case WORMUP:
- clutter_actor_set_size (CLUTTER_ACTOR (tail),
- properties->tilesize,
- properties->tilesize * size);
- clutter_actor_set_position (CLUTTER_ACTOR (tail),
- x, y - properties->tilesize);
- worm->ytail += properties->tilesize;
- break;
- default:
- break;
- }
+ clutter_actor_set_position (CLUTTER_ACTOR (tail),
+ x - properties->tilesize, y);
+ worm->xtail += properties->tilesize;
+ break;
+ case WORMUP:
+ clutter_actor_set_size (CLUTTER_ACTOR (tail),
+ properties->tilesize,
+ properties->tilesize * size);
+ clutter_actor_set_position (CLUTTER_ACTOR (tail),
+ x, y - properties->tilesize);
+ worm->ytail += properties->tilesize;
+ break;
+ default:
+ break;
+ }
+
+ if (size <= 0)
+ gnibbles_cworm_remove_actor (worm);
}
gint
@@ -721,23 +733,23 @@ gnibbles_cworm_ai_wander (gint x, gint y, gint dir, gint ox, gint oy)
y = BOARDHEIGHT - 1;
switch (level->walls[x][y] - 'A') {
- case BONUSREGULAR:
- case BONUSDOUBLE:
- case BONUSLIFE:
- case BONUSREVERSE:
- return 1;
- break;
- case BONUSHALF:
- return 0;
- break;
- default:
- if (level->walls[x][y] > EMPTYCHAR && level->walls[x][y] < 'z' + properties->numworms) {
+ case BONUSREGULAR:
+ case BONUSDOUBLE:
+ case BONUSLIFE:
+ case BONUSREVERSE:
+ return 1;
+ break;
+ case BONUSHALF:
return 0;
- } else {
- if (ox == x && oy == y)
- return 0;
- return gnibbles_cworm_ai_wander (x, y, dir, ox, oy);
- }
+ break;
+ default:
+ if (level->walls[x][y] > EMPTYCHAR && level->walls[x][y] < 'z' + properties->numworms) {
+ return 0;
+ } else {
+ if (ox == x && oy == y)
+ return 0;
+ return gnibbles_cworm_ai_wander (x, y, dir, ox, oy);
+ }
break;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]