[gnome-games] Not reseting the worm score and lives on new level
- From: Jason Clinton <jclinton src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-games] Not reseting the worm score and lives on new level
- Date: Wed, 14 Oct 2009 02:55:42 +0000 (UTC)
commit 9c6975d8340256ca91a33ff73fe426c8bfdee19f
Author: Guillaume Beland <guillaume beland gmail com>
Date: Fri Aug 21 19:26:15 2009 -0400
Not reseting the worm score and lives on new level
gnibbles/board.c | 28 ++++++++++------------------
gnibbles/gnibbles.c | 6 ++++--
gnibbles/main.c | 5 +++--
gnibbles/scoreboard.c | 6 +++---
gnibbles/worm.c | 38 ++++++++++++++++++++++++++------------
gnibbles/worm.h | 6 +++---
6 files changed, 49 insertions(+), 40 deletions(-)
---
diff --git a/gnibbles/board.c b/gnibbles/board.c
index 5b04bf6..5402e06 100644
--- a/gnibbles/board.c
+++ b/gnibbles/board.c
@@ -248,8 +248,8 @@ gnibbles_board_level_new (GnibblesBoard *board, gint level)
boni = gnibbles_boni_new ();
for (i = 0; i < properties->numworms; i++)
- if (worms[i])
- gnibbles_worm_destroy (worms[i]);
+ if (!worms[i])
+ worms[i] = gnibbles_worm_new (i);
for (i = 0; i < BOARDHEIGHT; i++) {
if (!fgets (tmpboard, sizeof (tmpboard), in)) {
@@ -267,31 +267,23 @@ gnibbles_board_level_new (GnibblesBoard *board, gint level)
switch (board->walls[j][i]) {
case 'm':
board->walls[j][i] = EMPTYCHAR;
- if (count < properties->numworms) {
- worms[count] = gnibbles_worm_new (count, j, i, WORMUP);
- count++;
- }
+ if (count < properties->numworms)
+ gnibbles_worm_set_start (worms[count++], j, i, WORMUP);
break;
case 'n':
board->walls[j][i] = EMPTYCHAR;
- if (count < properties->numworms) {
- worms[count] = gnibbles_worm_new (count, j, i, WORMLEFT);
- count++;
- }
+ if (count < properties->numworms)
+ gnibbles_worm_set_start(worms[count++], j, i, WORMLEFT);
break;
case 'o':
board->walls[j][i] = EMPTYCHAR;
- if (count < properties->numworms) {
- worms[count] = gnibbles_worm_new (count, j, i, WORMDOWN);
- count++;
- }
+ if (count < properties->numworms)
+ gnibbles_worm_set_start (worms[count++], j, i, WORMDOWN);
break;
case 'p':
board->walls[j][i] = EMPTYCHAR;
- if (count < properties->numworms) {
- worms[count] = gnibbles_worm_new (count, j, i, WORMRIGHT);
- count++;
- }
+ if (count < properties->numworms)
+ gnibbles_worm_set_start (worms[count++], j, i, WORMRIGHT);
break;
case 'Q':
gnibbles_warpmanager_add_warp (warpmanager, j - 1, i - 1, -1, -1);
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index 5584ee6..1e9d782 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -210,8 +210,10 @@ gnibbles_init ()
for (i = 0; i < properties->numworms; i++) {
if (worms[i]) {
- clutter_container_add_actor (CLUTTER_CONTAINER (stage), worms[i]->actors);
- clutter_actor_raise_top (worms[i]->actors);
+ if (!clutter_actor_get_stage (worms[i]->actors)) {
+ clutter_container_add_actor (CLUTTER_CONTAINER (stage), worms[i]->actors);
+ clutter_actor_raise_top (worms[i]->actors);
+ }
gnibbles_worm_show (worms[i]);
}
}
diff --git a/gnibbles/main.c b/gnibbles/main.c
index f03a4e0..91567d9 100644
--- a/gnibbles/main.c
+++ b/gnibbles/main.c
@@ -541,7 +541,8 @@ restart_game (gpointer data)
gnibbles_board_level_add_bonus (board, 1);
for (i = 0; i < properties->numworms; i++) {
- clutter_container_add_actor (CLUTTER_CONTAINER (stage), worms[i]->actors);
+ if (!clutter_actor_get_stage (worms[i]->actors))
+ clutter_container_add_actor (CLUTTER_CONTAINER (stage), worms[i]->actors);
gnibbles_worm_show (worms[i]);
}
@@ -611,7 +612,7 @@ main_loop (gpointer data)
add_bonus_id = 0;
erase_id = g_timeout_add_seconds (3,
(GSourceFunc) erase_worms_cb,
- (gpointer) ERASESIZE);
+ (gpointer) ERASESIZE);
gnibbles_log_score (window);
return FALSE;
diff --git a/gnibbles/scoreboard.c b/gnibbles/scoreboard.c
index 0488a8d..404aa0e 100644
--- a/gnibbles/scoreboard.c
+++ b/gnibbles/scoreboard.c
@@ -85,9 +85,9 @@ gnibbles_scoreboard_update (GnibblesScoreboard * scoreboard)
for (i = 0; i < scoreboard->count; i++) {
buffer = g_strdup_printf ("%02d, %04d",
- (scoreboard->worms[i]->lives > -1) ?
- scoreboard->worms[i]->lives : 0,
- scoreboard->worms[i]->score);
+ (scoreboard->worms[i]->lives > -1) ?
+ scoreboard->worms[i]->lives : 0,
+ scoreboard->worms[i]->score);
buffer2 = gtk_label_get_text (GTK_LABEL (scoreboard->data[i]));
if (strcmp (buffer, buffer2))
gtk_label_set_text (GTK_LABEL (scoreboard->data[i]), buffer);
diff --git a/gnibbles/worm.c b/gnibbles/worm.c
index d24db10..97970c4 100644
--- a/gnibbles/worm.c
+++ b/gnibbles/worm.c
@@ -337,8 +337,8 @@ gnibbles_worm_grok_bonus (GnibblesWorm *worm)
case BONUSREVERSE:
for (i = 0; i < properties->numworms; i++)
if (worm != worms[i])
- g_timeout_add (1, (GSourceFunc)
- gnibbles_worm_reverse, worms[i]);
+ g_timeout_add (1, (GSourceFunc)
+ gnibbles_worm_reverse, worms[i]);
games_sound_play ("reverse");
break;
}
@@ -370,12 +370,12 @@ gnibbles_worm_handle_bonus (GnibblesWorm *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_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);
+ gnibbles_board_level_add_bonus (board, 1);
} else
gnibbles_boni_remove_bonus_final (boni, worm->xhead, worm->yhead);
@@ -475,7 +475,8 @@ gnibbles_worm_animate_death (GnibblesWorm *worm)
clutter_container_add_actor (CLUTTER_CONTAINER (group), tmp);
}
- for (i = 0; i < g_list_length (worm->list); i++)
+ worm->length = g_list_length (worm->list);
+ for (i = 0; i < worm->length ; i++)
worm->list = g_list_remove (worm->list, g_list_nth_data (worm->list, i));
clutter_actor_set_opacity (CLUTTER_ACTOR (worm->actors), 0x00);
@@ -498,8 +499,7 @@ gnibbles_worm_animate_death (GnibblesWorm *worm)
}
GnibblesWorm*
-gnibbles_worm_new (guint number, guint t_xhead,
- guint t_yhead, gint t_direction)
+gnibbles_worm_new (guint number)
{
GnibblesWorm *worm = g_new (GnibblesWorm, 1);
@@ -508,14 +508,30 @@ gnibbles_worm_new (guint number, guint t_xhead,
worm->number = number;
worm->lives = SLIVES;
worm->human = FALSE;
- worm->stop = FALSE;
+ worm->score = 0;
+
+ return worm;
+}
+
+void
+gnibbles_worm_set_start (GnibblesWorm *worm, guint t_xhead,
+ guint t_yhead, gint t_direction)
+{
+ int i;
+ worm->length = g_list_length (worm->list);
+ for (i = 0; i < worm->length ; i++)
+ worm->list = g_list_remove (worm->list, g_list_nth_data (worm->list, i));
+ g_list_free (worm->list);
+ worm->list = NULL;
+
+ clutter_group_remove_all (CLUTTER_GROUP (worm->actors));
worm->xhead = t_xhead;
- worm->xstart = t_xhead;
worm->yhead = t_yhead;
- worm->ystart = t_yhead;
worm->xtail = t_xhead;
worm->ytail = t_yhead;
+ worm->xstart = t_xhead;
+ worm->ystart = t_yhead;
worm->direction = t_direction;
worm->direction_start = t_direction;
@@ -523,8 +539,6 @@ gnibbles_worm_new (guint number, guint t_xhead,
worm->change = 0;
gnibbles_worm_queue_empty (worm);
-
- return worm;
}
void
diff --git a/gnibbles/worm.h b/gnibbles/worm.h
index 1e15b2f..5dadeda 100644
--- a/gnibbles/worm.h
+++ b/gnibbles/worm.h
@@ -58,9 +58,9 @@ typedef struct {
void worm_set_direction (int worm, int dir);
void worm_handle_direction (int worm, int dir);
-GnibblesWorm* gnibbles_worm_new (guint number, guint t_xhead,
- guint t_yhead, gint t_direction);
-
+GnibblesWorm* gnibbles_worm_new (guint number);
+void gnibbles_worm_set_start (GnibblesWorm *worm, guint t_xhead,
+ guint t_yhead, gint t_direction);
void gnibbles_worm_show (GnibblesWorm *worm);
gboolean gnibbles_worm_handle_keypress (GnibblesWorm * worm, guint keyval);
void gnibbles_worm_move_head_pointer (GnibblesWorm *worm);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]