[gnome-games/gnibbles-clutter] Made a lot of fix on worm movement, still can't put the finger on what is wrong
- From: Guillaume Béland <guillaubel src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games/gnibbles-clutter] Made a lot of fix on worm movement, still can't put the finger on what is wrong
- Date: Wed, 29 Jul 2009 03:28:48 +0000 (UTC)
commit 1330c450d0aa887155c6f8344975521c9b8d8314
Author: Guillaume Beland <guillaume beland gmail com>
Date: Tue Jul 28 23:23:45 2009 -0400
Made a lot of fix on worm movement, still can't put the finger on what is wrong
gnibbles/board.c | 31 ++--
gnibbles/gnibbles.c | 5 +-
gnibbles/main.c | 24 ++--
gnibbles/worm-clutter.c | 383 +++++++++++++++++++++++++++++++----------------
gnibbles/worm-clutter.h | 6 +-
5 files changed, 287 insertions(+), 162 deletions(-)
---
diff --git a/gnibbles/board.c b/gnibbles/board.c
index 548459b..47282ea 100644
--- a/gnibbles/board.c
+++ b/gnibbles/board.c
@@ -213,8 +213,7 @@ gnibbles_board_resize (GnibblesBoard *board, gint newtile)
void
gnibbles_board_level_new (GnibblesBoard *board, gint level)
{
- //GnibblesLevel *board = g_new (GnibblesLevel, 1);
- //board->level = level;
+
board->current_level = level;
gchar *tmp = NULL;
const char *dirname;
@@ -327,25 +326,29 @@ gnibbles_board_level_new (GnibblesBoard *board, gint level)
fclose (in);
for (i = 0; i < count; i++) {
- board->walls[worms[i]->xhead][worms[i]->yhead] = WORMCHAR;
-
if (worms[i]->direction == WORMRIGHT) {
- for (j = 0; j < worms[i]->length; j++)
- board->walls[++worms[i]->xhead][worms[i]->yhead] = WORMCHAR;
+ for (j = 0; j < worms[i]->length; j++) {
+ board->walls[worms[i]->xhead][worms[i]->yhead] = WORMCHAR + worms[i]->number;
+ worms[i]->xhead++;
+ }
} else if ( worms[i]->direction == WORMLEFT) {
- for (j = 0; j < worms[i]->length; j++)
- board->walls[--worms[i]->xhead][worms[i]->yhead] = WORMCHAR;
+ for (j = 0; j < worms[i]->length; j++){
+ board->walls[worms[i]->xhead][worms[i]->yhead] = WORMCHAR + worms[i]->number;
+ worms[i]->xhead--;
+ }
} else if (worms[i]->direction == WORMDOWN) {
- for (j = 0; j < worms[i]->length; j++)
- board->walls[worms[i]->xhead][++worms[i]->yhead] = WORMCHAR;
+ for (j = 0; j < worms[i]->length; j++) {
+ board->walls[worms[i]->xhead][worms[i]->yhead] = WORMCHAR + worms[i]->number;
+ worms[i]->yhead++;
+ }
} else if (worms[i]->direction == WORMUP) {
- for (j = 0; j < worms[i]->length; j++)
- board->walls[worms[i]->xhead][--worms[i]->yhead] = WORMCHAR;
+ for (j = 0; j < worms[i]->length; j++) {
+ board->walls[worms[i]->xhead][worms[i]->yhead] = WORMCHAR + worms[i]->number;
+ worms[i]->yhead--;
+ }
}
}
-
gnibbles_board_load_level (board);
-
}
void
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index 3cd91f3..0547d5a 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -254,11 +254,12 @@ 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)
@@ -269,7 +270,7 @@ gnibbles_move_worms (void)
if (g_list_length (worms[i]->list) > 1 && !dead[i] && worms[i]->lives > 0)
gnibbles_worm_move_head (worms[i]);
}
-
+
for (i = 0; i < properties->numworms; i++) {
if (g_list_length (worms[i]->list) == 1 && !dead[i] && worms[i]->lives > 0)
gnibbles_worm_move_straight_worm (worms[i]);
diff --git a/gnibbles/main.c b/gnibbles/main.c
index 64e9570..ee82270 100644
--- a/gnibbles/main.c
+++ b/gnibbles/main.c
@@ -332,12 +332,12 @@ new_game_2_cb (GtkWidget * widget, gpointer data)
#ifdef GGZ_CLIENT
if (!main_id && ggz_network_mode && network_is_host ()) {
main_id = g_timeout_add (GAMEDELAY * (properties->gamespeed + NETDELAY),
- (GSourceFunc) network_loop, NULL);
+ (GSourceFunc) network_loop, NULL);
} else
#endif
if (!main_id && !ggz_network_mode) {
main_id = g_timeout_add (GAMEDELAY * properties->gamespeed,
- (GSourceFunc) main_loop, NULL);
+ (GSourceFunc) main_loop, NULL);
}
#ifdef GGZ_CLIENT
if (!add_bonus_id && network_is_host ()) {
@@ -345,8 +345,8 @@ new_game_2_cb (GtkWidget * widget, gpointer data)
if (!add_bonus_id) {
#endif
add_bonus_id = g_timeout_add (BONUSDELAY *
- properties->gamespeed,
- (GSourceFunc) add_bonus_cb, NULL);
+ properties->gamespeed,
+ (GSourceFunc) add_bonus_cb, NULL);
}
}
@@ -551,8 +551,8 @@ erase_worms_cb (gpointer datap)
} else {
gnibbles_undraw_worms (ERASESIZE - data);
erase_id = g_timeout_add (ERASETIME / ERASESIZE,
- (GSourceFunc) erase_worms_cb,
- GINT_TO_POINTER (data - 1));
+ (GSourceFunc) erase_worms_cb,
+ GINT_TO_POINTER (data - 1));
}
return (FALSE);
@@ -575,7 +575,7 @@ main_loop (gpointer data)
return FALSE;
str = g_strdup_printf (_("Game over! The game has been won by %s!"),
- names[winner]);
+ names[winner]);
#ifdef GGZ_CLIENT
add_chat_text (str);
#endif
@@ -594,8 +594,8 @@ main_loop (gpointer data)
}
add_bonus_id = 0;
erase_id = g_timeout_add_seconds (3,
- (GSourceFunc) erase_worms_cb,
- (gpointer) ERASESIZE);
+ (GSourceFunc) erase_worms_cb,
+ (gpointer) ERASESIZE);
gnibbles_log_score (window);
return FALSE;
@@ -613,8 +613,8 @@ main_loop (gpointer data)
}
add_bonus_id = 0;
erase_id = g_timeout_add_seconds (3,
- (GSourceFunc) erase_worms_cb,
- (gpointer) ERASESIZE);
+ (GSourceFunc) erase_worms_cb,
+ (gpointer) ERASESIZE);
gnibbles_log_score (window);
return (FALSE);
}
@@ -664,7 +664,7 @@ main_loop (gpointer data)
main_id = 0;
}
if ((current_level < MAXLEVEL) && (!properties->random
- || ggz_network_mode))
+ || ggz_network_mode))
current_level++;
else if (properties->random && !ggz_network_mode) {
tmp = rand () % MAXLEVEL + 1;
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index 16d6fad..0397b8e 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -353,6 +353,8 @@ gnibbles_worm_reset (ClutterAnimation *animation, gpointer data)
gnibbles_worm_remove_actor (worm);
}
+ //printf ("\n\n %d)XHEAD %d, YHEAD %d",worm->number, worm->xhead, worm->yhead);
+ //printf ("\n\n %d)XTAIL %d, YTAIL %d",worm->number, worm->xtail, worm->ytail);
worm->xhead = worm->xstart;
worm->yhead = worm->ystart;
worm->xtail = worm->xhead;
@@ -362,35 +364,42 @@ gnibbles_worm_reset (ClutterAnimation *animation, gpointer data)
if (!(worm->lives <= 0)) {
gnibbles_worm_show (worm);
- board->walls[worm->xhead][worm->yhead] = WORMCHAR;
if (worm->direction == WORMRIGHT) {
- for (j = 0; j < worm->length; j++)
- board->walls[++worm->xhead][worm->yhead] = WORMCHAR;
+ for (j = 0; j < worm->length; j++) {
+ board->walls[worm->xhead][worm->yhead] = WORMCHAR + worm->number;
+ worm->xhead++;
+ }
} else if ( worm->direction == WORMLEFT) {
- for (j = 0; j < worm->length; j++)
- board->walls[--worm->xhead][worm->yhead] = WORMCHAR;
+ for (j = 0; j < worm->length; j++) {
+ board->walls[worm->xhead][worm->yhead] = WORMCHAR + worm->number;
+ worm->yhead--;
+ }
} else if (worm->direction == WORMDOWN) {
- for (j = 0; j < worm->length; j++)
- board->walls[worm->xhead][++worm->yhead] = WORMCHAR;
+ for (j = 0; j < worm->length; j++) {
+ board->walls[worm->xhead][worm->yhead] = WORMCHAR + worm->number;
+ worm->yhead++;
+ }
} else if (worm->direction == WORMUP) {
- for (j = 0; j < worm->length; j++)
- board->walls[worm->xhead][--worm->yhead] = WORMCHAR;
+ for (j = 0; j < worm->length; j++) {
+ board->walls[worm->xhead][worm->yhead] = WORMCHAR + worm->number;
+ worm->yhead--;
+ }
}
}
/*
FILE *fo;
fo = fopen ("output.txt", "w" );
- for (i = 0; i < BOARDWIDTH; i++) {
- for (j = 0; j < BOARDHEIGHT; j++) {
- if (board->walls[i][j] == 'a')
+ for (i = 0; i < BOARDHEIGHT; i++) {
+ for (j = 0; j < BOARDWIDTH; j++) {
+ if (board->walls[j][i] == 'a')
fprintf(fo, "%c", ' ');
else
- fprintf (fo , "%c", board->walls[i][j]);
+ fprintf (fo , "%c", board->walls[j][i]);
}
fprintf (fo, "\n");
}
fclose (fo);
- */
+*/
}
static void *
@@ -437,9 +446,13 @@ gnibbles_worm_new (guint number, guint t_xhead,
worm->ystart = t_yhead;
worm->xtail = t_xhead;
worm->ytail = t_yhead;
+
+ worm->start = 0;
+ worm->stop = 0;
worm->direction = t_direction;
worm->direction_start = t_direction;
worm->length = SLENGTH;
+ worm->change = 1; //SLENGTH - 1;
gnibbles_worm_queue_empty (worm);
@@ -548,7 +561,6 @@ void
gnibbles_worm_inverse (gpointer data)
{
GnibblesWorm *worm;
-
worm = (GnibblesWorm *) data;
worm->list = g_list_reverse (worm->list);
@@ -573,6 +585,7 @@ gnibbles_worm_inverse (gpointer data)
worm->yhead = worm->ytail;
worm->ytail = tmp;
tmp = worm->yhead;
+
}
void
@@ -643,63 +656,137 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
clutter_actor_get_position (CLUTTER_ACTOR (head), &x, &y);
- if ((board->walls[worm->xhead][worm->yhead] != EMPTYCHAR) &&
- (board->walls[worm->xhead][worm->yhead] != WARPLETTER)) {
+ if (worm->change <= 0) {
+ switch (worm->direction) {
+ case WORMRIGHT:
+ clutter_actor_set_x (CLUTTER_ACTOR (head),
+ x + properties->tilesize);
+ worm->xhead++;
+ worm->xtail++;
+ break;
+ case WORMDOWN:
+ clutter_actor_set_y (CLUTTER_ACTOR (head),
+ y + properties->tilesize);
+ worm->yhead++;
+ worm->ytail++;
+ break;
+ case WORMLEFT:
+ clutter_actor_set_x (CLUTTER_ACTOR (head),
+ x - properties->tilesize);
+ worm->xhead--;
+ worm->xtail--;
+ break;
+ case WORMUP:
+ clutter_actor_set_y (CLUTTER_ACTOR (head),
+ y - properties->tilesize);
+ worm->yhead--;
+ worm->ytail--;
+ break;
+ default:
+ break;
+ }
+ if (worm->xhead == BOARDWIDTH) {
+ worm->xhead = 0;
+ }
+ if (worm->xhead < 0) {
+ worm->xhead = BOARDWIDTH - 1;
+ }
+ if (worm->yhead == BOARDHEIGHT) {
+ worm->yhead = 0;
+ }
+ if (worm->yhead < 0) {
+ worm->yhead = BOARDHEIGHT - 1;
+ }
+
+ if ((board->walls[worm->xhead][worm->yhead] != EMPTYCHAR) &&
+ (board->walls[worm->xhead][worm->yhead] != WARPLETTER)) {
+
+ gnibbles_worm_grok_bonus (worm);
- gnibbles_worm_grok_bonus (worm);
+ if ((board->walls[worm->xhead][worm->yhead] == BONUSREGULAR + 'A') &&
+ !gnibbles_boni_fake (boni, worm->xhead, worm->yhead)) {
+
+ gnibbles_boni_remove_bonus_final (boni, worm->xhead, worm->yhead);
+
+ if (boni->numleft != 0)
+ gnibbles_board_level_add_bonus (board, 1);
+
+ } else
+ gnibbles_boni_remove_bonus_final (boni, worm->xhead, worm->yhead);
+ }
+
+ board->walls[worm->xhead][worm->yhead] = WORMCHAR + worm->number;
+
+ if (worm->change) {
+ switch (worm->direction) {
+ case WORMRIGHT:
+ clutter_actor_set_x (CLUTTER_ACTOR (head),
+ x + properties->tilesize);
+ worm->xhead++;
+ worm->xtail++;
+ break;
+ case WORMDOWN:
+ clutter_actor_set_y (CLUTTER_ACTOR (head),
+ y + properties->tilesize);
+ worm->yhead++;
+ worm->ytail++;
+ break;
+ case WORMLEFT:
+ clutter_actor_set_x (CLUTTER_ACTOR (head),
+ x - properties->tilesize);
+ worm->xhead--;
+ worm->xtail--;
+ break;
+ case WORMUP:
+ clutter_actor_set_y (CLUTTER_ACTOR (head),
+ y - properties->tilesize);
+ worm->yhead--;
+ worm->ytail--;
+ break;
+ default:
+ break;
+ }
+
+ if (worm->xhead == BOARDWIDTH) {
+ worm->xhead = 0;
+ }
+ if (worm->xhead < 0) {
+ worm->xhead = BOARDWIDTH - 1;
+ }
+ if (worm->yhead == BOARDHEIGHT) {
+ worm->yhead = 0;
+ }
+ if (worm->yhead < 0) {
+ worm->yhead = BOARDHEIGHT - 1;
+ }
+
+ if ((board->walls[worm->xhead][worm->yhead] != EMPTYCHAR) &&
+ (board->walls[worm->xhead][worm->yhead] != WARPLETTER)) {
+
+ gnibbles_worm_grok_bonus (worm);
- if ((board->walls[worm->xhead][worm->yhead] == BONUSREGULAR + 'A') &&
- !gnibbles_boni_fake (boni, worm->xhead, worm->yhead)) {
- gnibbles_boni_remove_bonus_final (boni, worm->xhead, worm->yhead);
- if (boni->numleft != 0)
- gnibbles_board_level_add_bonus (board, 1);
- } else
- gnibbles_boni_remove_bonus_final (boni, worm->xhead, worm->yhead);
- }
+ if ((board->walls[worm->xhead][worm->yhead] == BONUSREGULAR + 'A') &&
+ !gnibbles_boni_fake (boni, worm->xhead, worm->yhead)) {
+
+ gnibbles_boni_remove_bonus_final (boni, worm->xhead, worm->yhead);
+
+ if (boni->numleft != 0)
+ gnibbles_board_level_add_bonus (board, 1);
+
+ } else
+ gnibbles_boni_remove_bonus_final (boni, worm->xhead, worm->yhead);
+ }
+
+ board->walls[worm->xhead][worm->yhead] = WORMCHAR + worm->number;
- switch (worm->direction) {
- case WORMRIGHT:
- clutter_actor_set_x (CLUTTER_ACTOR (head),
- x + properties->tilesize);
- board->walls[++worm->xhead][worm->yhead] = WORMCHAR;
- board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
- if (worm->xtail == BOARDWIDTH)
- worm->xtail = 0;
- else
- worm->xtail++;
- break;
- case WORMDOWN:
- clutter_actor_set_y (CLUTTER_ACTOR (head),
- y + properties->tilesize);
- board->walls[worm->xhead][++worm->yhead] = WORMCHAR;
- board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
- if (worm->ytail == BOARDHEIGHT)
- worm->ytail = 0;
- else
- worm->ytail++;
- break;
- case WORMLEFT:
- clutter_actor_set_x (CLUTTER_ACTOR (head),
- x - properties->tilesize);
- board->walls[--worm->xhead][worm->yhead] = WORMCHAR;
- board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
- if (worm->xtail == 0)
- worm->xtail = BOARDWIDTH - 1;
- else
- worm->xtail--;
- break;
- case WORMUP:
- clutter_actor_set_y (CLUTTER_ACTOR (head),
- y - properties->tilesize);
- board->walls[worm->xhead][--worm->yhead] = WORMCHAR;
board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
- if (worm->ytail == 0)
- worm->ytail = BOARDHEIGHT - 1;
- else
- worm->ytail--;
- break;
- default:
- break;
+
+ worm->change++;
+ worm->length--;
+ }
+ } else {
+ worm->change--;
+ worm->length++;
}
if (key_queue[worm->number] && !g_queue_is_empty (key_queue[worm->number])) {
@@ -727,47 +814,63 @@ gnibbles_worm_move_head (GnibblesWorm *worm)
size = w < h ? floorf (h) : floorf (w);
size = floorf (size + properties->tilesize);
- if ((board->walls[worm->xhead][worm->yhead] != EMPTYCHAR) &&
- (board->walls[worm->xhead][worm->yhead] != WARPLETTER)) {
-
- gnibbles_worm_grok_bonus (worm);
-
- if ((board->walls[worm->xhead][worm->yhead] == BONUSREGULAR + 'A') &&
- !gnibbles_boni_fake (boni, worm->xhead, worm->yhead)) {
- gnibbles_boni_remove_bonus_final (boni, worm->xhead, worm->yhead);
- if (boni->numleft != 0)
- gnibbles_board_level_add_bonus (board, 1);
- } else
- gnibbles_boni_remove_bonus_final (boni, worm->xhead, worm->yhead);
- }
-
// set the size of the head actor
switch (worm->direction) {
case WORMRIGHT:
clutter_actor_set_width (CLUTTER_ACTOR (head), size);
- board->walls[++worm->xhead][worm->yhead] = WORMCHAR;
+ worm->xhead++;
break;
case WORMDOWN:
clutter_actor_set_height (CLUTTER_ACTOR (head), size);
- board->walls[worm->xhead][++worm->yhead] = WORMCHAR;
+ worm->yhead++;
break;
case WORMLEFT:
clutter_actor_set_width (CLUTTER_ACTOR (head), size);
clutter_actor_set_x (CLUTTER_ACTOR (head),
- x - properties->tilesize);
- board->walls[--worm->xhead][worm->yhead] = WORMCHAR;
+ x - properties->tilesize);
+ worm->xhead--;
break;
case WORMUP:
clutter_actor_set_height (CLUTTER_ACTOR (head), size);
clutter_actor_set_y (CLUTTER_ACTOR (head),
- y - properties->tilesize);
- board->walls[worm->xhead][--worm->yhead] = WORMCHAR;
+ y - properties->tilesize);
+ worm->yhead--;
break;
default:
break;
}
+ if (worm->xhead == BOARDWIDTH) {
+ worm->xhead = 0;
+ }
+ if (worm->xhead < 0) {
+ worm->xhead = BOARDWIDTH - 1;
+ }
+ if (worm->yhead == BOARDHEIGHT) {
+ worm->yhead = 0;
+ }
+ if (worm->yhead < 0) {
+ worm->yhead = BOARDHEIGHT - 1;
+ }
+
+ if ((board->walls[worm->xhead][worm->yhead] != EMPTYCHAR) &&
+ (board->walls[worm->xhead][worm->yhead] != WARPLETTER)) {
+
+ gnibbles_worm_grok_bonus (worm);
+
+ if ((board->walls[worm->xhead][worm->yhead] == BONUSREGULAR + 'A') &&
+ !gnibbles_boni_fake (boni, worm->xhead, worm->yhead)) {
+ gnibbles_boni_remove_bonus_final (boni, worm->xhead, worm->yhead);
+ if (boni->numleft != 0)
+ gnibbles_board_level_add_bonus (board, 1);
+ } else
+ gnibbles_boni_remove_bonus_final (boni, worm->xhead, worm->yhead);
+ }
+
+ board->walls[worm->xhead][worm->yhead] = WORMCHAR + worm->number;
+
worm->length++;
+
if (key_queue[worm->number] && !g_queue_is_empty (key_queue[worm->number])) {
gnibbles_worm_dequeue_keypress (worm);
}
@@ -790,54 +893,74 @@ gnibbles_worm_move_tail (GnibblesWorm *worm)
clutter_actor_get_position (CLUTTER_ACTOR (tail), &x, &y);
size = MAX (w, h);
size = floorf (size - properties->tilesize);
-
- if (size <= 0) {
- gnibbles_worm_remove_actor (worm);
- } else {
- tail_dir = gnibbles_worm_get_tail_direction (worm);
- switch (tail_dir) {
- case WORMRIGHT:
- clutter_actor_set_width (CLUTTER_ACTOR (tail), size);
- clutter_actor_set_x (CLUTTER_ACTOR (tail),
- x + properties->tilesize);
-
- board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
- if (worm->xtail == BOARDWIDTH)
- worm->xtail = 0;
- else
+
+ if (worm->change <= 0) {
+ if (size <= 0) {
+ gnibbles_worm_remove_actor (worm);
+ } else {
+ tail_dir = gnibbles_worm_get_tail_direction (worm);
+ switch (tail_dir) {
+ case WORMRIGHT:
+ clutter_actor_set_width (CLUTTER_ACTOR (tail), size);
+ clutter_actor_set_x (CLUTTER_ACTOR (tail),
+ x + properties->tilesize);
worm->xtail++;
- break;
- case WORMDOWN:
- clutter_actor_set_height (CLUTTER_ACTOR (tail), size);
- clutter_actor_set_y (CLUTTER_ACTOR (tail),
- y + properties->tilesize);
- board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
- if (worm->ytail == BOARDHEIGHT)
- worm->ytail = 0;
- else
+ case WORMDOWN:
+ clutter_actor_set_height (CLUTTER_ACTOR (tail), size);
+ clutter_actor_set_y (CLUTTER_ACTOR (tail),
+ y + properties->tilesize);
worm->ytail++;
- break;
- case WORMLEFT:
- clutter_actor_set_width (CLUTTER_ACTOR (tail), size);
- board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
- if (worm->xtail == 0)
- worm->xtail = BOARDWIDTH - 1;
- else
+ break;
+ case WORMLEFT:
+ clutter_actor_set_width (CLUTTER_ACTOR (tail), size);
worm->xtail--;
- break;
- case WORMUP:
- clutter_actor_set_height (CLUTTER_ACTOR (tail), size);
- board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
- if (worm->ytail == 0)
- worm->ytail = BOARDHEIGHT - 1;
- else
+ break;
+ case WORMUP:
+ clutter_actor_set_height (CLUTTER_ACTOR (tail), size);
worm->ytail--;
- break;
- default:
- break;
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (worm->change) {
+ if (size <= 0) {
+ gnibbles_worm_remove_actor (worm);
+ } else {
+ tail_dir = gnibbles_worm_get_tail_direction (worm);
+ switch (tail_dir) {
+ case WORMRIGHT:
+ clutter_actor_set_width (CLUTTER_ACTOR (tail), size);
+ clutter_actor_set_x (CLUTTER_ACTOR (tail),
+ x + properties->tilesize);
+ worm->xtail++;
+ case WORMDOWN:
+ clutter_actor_set_height (CLUTTER_ACTOR (tail), size);
+ clutter_actor_set_y (CLUTTER_ACTOR (tail),
+ y + properties->tilesize);
+ worm->ytail++;
+ break;
+ case WORMLEFT:
+ clutter_actor_set_width (CLUTTER_ACTOR (tail), size);
+ worm->ytail--;
+ break;
+ case WORMUP:
+ clutter_actor_set_height (CLUTTER_ACTOR (tail), size);
+ worm->ytail--;
+ break;
+ default:
+ break;
+ }
+ }
+ board->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
+ worm->change++;
+ worm->length--;
}
+ } else {
+ worm->change--;
+ worm->length++;
}
- worm->length--;
}
void
diff --git a/gnibbles/worm-clutter.h b/gnibbles/worm-clutter.h
index 94984af..cb8cbc7 100644
--- a/gnibbles/worm-clutter.h
+++ b/gnibbles/worm-clutter.h
@@ -44,14 +44,12 @@ typedef struct {
gint xstart, ystart;
guint xhead, yhead;
guint xtail, ytail;
- gint direction;
- gint direction_start;
+ gint direction, direction_start;
gint length;
gint lives;
guint score;
guint number;
- gint start;
- gint stop;
+ gint start, stop;
gint change;
gint keypress;
gboolean human;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]