[gnome-games/gnibbles-clutter-rebased: 118/129] Solved the bug when traveling through warp, warp reset and tail follow properly
- From: Jason Clinton <jclinton src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-games/gnibbles-clutter-rebased: 118/129] Solved the bug when traveling through warp, warp reset and tail follow properly
- Date: Mon, 12 Oct 2009 21:36:08 +0000 (UTC)
commit fa0ec589ec62e005212ce1512c7d76a7a2810646
Author: Guillaume Beland <guillaume beland gmail com>
Date: Wed Aug 26 16:04:41 2009 -0400
Solved the bug when traveling through warp, warp reset and tail follow properly
gnibbles/gnibbles.c | 2 +-
gnibbles/warpmanager.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++
gnibbles/warpmanager.h | 13 ++++-----
gnibbles/worm.c | 24 ++++++++++++++++++-
4 files changed, 91 insertions(+), 9 deletions(-)
---
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index 81c6267..b13cded 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -257,7 +257,7 @@ gnibbles_move_worms (void)
}
}
/*
- printf ("head: (%d,%d) tail: (%d,%d) \n",
+ printf ("head: (%d,%d) \t tail: (%d,%d) \n",
worms[0]->xhead, worms[0]->yhead,
worms[0]->xtail, worms[0]->ytail);
*/
diff --git a/gnibbles/warpmanager.c b/gnibbles/warpmanager.c
index b610f30..a13c857 100644
--- a/gnibbles/warpmanager.c
+++ b/gnibbles/warpmanager.c
@@ -149,6 +149,15 @@ gnibbles_warpmanager_worm_change_pos (GnibblesWarpManager * warpmanager,
if (board->walls[x][y] != EMPTYCHAR)
gnibbles_boni_remove_bonus (boni, x, y);
}
+ //reset warps
+ board->walls
+ [warpmanager->warps[i]->x][warpmanager->warps[i]->y] = WARPLETTER;
+ board->walls
+ [warpmanager->warps[i]->x + 1][warpmanager->warps[i]->y] = WARPLETTER;
+ board->walls
+ [warpmanager->warps[i]->x][warpmanager->warps[i]->y + 1] = WARPLETTER;
+ board->walls
+ [warpmanager->warps[i]->x+1][warpmanager->warps[i]->y+1] = WARPLETTER;
worm->xhead = x;
worm->yhead = y;
@@ -156,6 +165,58 @@ gnibbles_warpmanager_worm_change_pos (GnibblesWarpManager * warpmanager,
}
}
+void
+gnibbles_warpmanager_worm_change_tail_pos (GnibblesWarpManager * warpmanager,
+ GnibblesWorm * worm)
+{
+ int i, x, y, good;
+
+ for (i = 0; i < warpmanager->numwarps; i++) {
+ if ((worm->xtail == warpmanager->warps[i]->x &&
+ worm->ytail == warpmanager->warps[i]->y) ||
+ (worm->xtail == warpmanager->warps[i]->x + 1 &&
+ worm->ytail == warpmanager->warps[i]->y) ||
+ (worm->xtail == warpmanager->warps[i]->x &&
+ worm->ytail == warpmanager->warps[i]->y + 1) ||
+ (worm->xtail == warpmanager->warps[i]->x + 1 &&
+ worm->ytail == warpmanager->warps[i]->y + 1)) {
+
+ if (warpmanager->warps[i]->wx == -1) {
+ good = 0;
+ while (!good) {
+ // In network games, warps should be fair.
+ if (ggz_network_mode) {
+ x = 10 % BOARDWIDTH;
+ y = 10 % BOARDHEIGHT;
+ } else {
+ x = rand () % BOARDWIDTH;
+ y = rand () % BOARDHEIGHT;
+ }
+ if (board->walls[x][y] == EMPTYCHAR)
+ good = 1;
+ }
+ } else {
+ x = warpmanager->warps[i]->wx;
+ y = warpmanager->warps[i]->wy;
+ if (board->walls[x][y] != EMPTYCHAR)
+ gnibbles_boni_remove_bonus (boni, x, y);
+ }
+ //reset warps
+ board->walls
+ [warpmanager->warps[i]->x][warpmanager->warps[i]->y] = WARPLETTER;
+ board->walls
+ [warpmanager->warps[i]->x + 1][warpmanager->warps[i]->y] = WARPLETTER;
+ board->walls
+ [warpmanager->warps[i]->x][warpmanager->warps[i]->y + 1] = WARPLETTER;
+ board->walls
+ [warpmanager->warps[i]->x+1][warpmanager->warps[i]->y+1] = WARPLETTER;
+
+ worm->xtail = x;
+ worm->ytail = y;
+ }
+ }
+}
+
void
gnibbles_warpmanager_resize (GnibblesWarpManager *warpmanager, gint newtile)
{
diff --git a/gnibbles/warpmanager.h b/gnibbles/warpmanager.h
index 80461f0..0edce7f 100644
--- a/gnibbles/warpmanager.h
+++ b/gnibbles/warpmanager.h
@@ -36,14 +36,13 @@ typedef struct {
} GnibblesWarpManager;
GnibblesWarpManager *gnibbles_warpmanager_new (void);
-
-void gnibbles_warpmanager_destroy (GnibblesWarpManager * warpmanager);
-
-void gnibbles_warpmanager_add_warp (GnibblesWarpManager * warpmanager,
+void gnibbles_warpmanager_destroy (GnibblesWarpManager *warpmanager);
+void gnibbles_warpmanager_add_warp (GnibblesWarpManager *warpmanager,
gint t_x, gint t_y, gint t_wx, gint t_wy);
-
-void gnibbles_warpmanager_worm_change_pos (GnibblesWarpManager * warpmanager,
- GnibblesWorm * worm);
+void gnibbles_warpmanager_worm_change_pos (GnibblesWarpManager *warpmanager,
+ GnibblesWorm *worm);
+void gnibbles_warpmanager_worm_change_tail_pos (GnibblesWarpManager *warpmanager,
+ GnibblesWorm *worm);
void gnibbles_warpmanager_resize (GnibblesWarpManager *warpmanager,
gint tilesize);
diff --git a/gnibbles/worm.c b/gnibbles/worm.c
index a205af3..d141592 100644
--- a/gnibbles/worm.c
+++ b/gnibbles/worm.c
@@ -244,7 +244,7 @@ gnibbles_worm_get_tail_direction (GnibblesWorm *worm)
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;
+ next = CLUTTER_ACTOR (g_list_previous (g_list_last (worm->list))->data);
else
return worm->direction;
@@ -451,6 +451,28 @@ gnibbles_worm_move_tail_pointer (GnibblesWorm *worm)
worm->xtail = 0;
if (worm->ytail >= BOARDHEIGHT)
worm->ytail = 0;
+
+ if (board->walls[worm->xtail][worm->ytail] == WARPLETTER) {
+ gnibbles_warpmanager_worm_change_tail_pos (warpmanager, worm);
+ //FIXME: this solution is ugly
+ switch (tail_dir) {
+ case WORMRIGHT:
+ worm->xtail++;
+ break;
+ case WORMDOWN:
+ worm->ytail++;
+ break;
+ case WORMLEFT:
+ worm->xtail--;
+ break;
+ case WORMUP:
+ worm->ytail--;
+ break;
+ default:
+ break;
+ }
+ }
+
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]