[PATCH] gnibbles: only the crashed worm dies



Hi,

the following patch changes the behaviour of gnibbles when a worm
crashes in a wall or inside another worm. Currently, in this case all
worms start at their origin. This patch changes this, so that only the
crashed worm goes back to his origin.

This patch changes this, but I could add a option in the setup-dialog
where you can set this behaviour. Are there any interests to add such a
feature/behaviour to gnibbles?

regards,
        Johannes Hölzl

diff -urd -x '*.o' -x '*.la' -x '*.lo' -x '\.deps' -x Makefile gnome-games-2.8.2/gnibbles/gnibbles.c ../gnome-games-2.8.2/gnibbles/gnibbles.c
--- gnome-games-2.8.2/gnibbles/gnibbles.c	2004-04-27 14:24:43 +0200
+++ ../gnome-games-2.8.2/gnibbles/gnibbles.c	2005-02-15 15:40:34 +0100
@@ -500,29 +500,32 @@
 		if (dead[i]) {
 			if (properties->numworms > 1)
 				worms[i]->score *= .7;
-			status |= gnibbles_worm_lose_life (worms[i]) << 1;
+				
+			if (gnibbles_worm_lose_life (worms[i]))
+				status |= GAMEOVER;
 		}
 
 	for (i = 0; i < properties->numworms; i++)
 		if (!dead[i])
 			gnibbles_worm_move_tail (worms[i]);
-
+			
 	for (i = 0; i < properties->numworms; i++)
 		if (!dead[i])
 			gnibbles_worm_draw_head (worms[i]);
 
+	for (i = 0; i < properties->numworms; i++)
+		if (dead[i])
+			gnibbles_worm_reset(worms[i]);
+			
+	g_free (dead);
+
 	if (status & GAMEOVER) {
 		gnibbles_play_sound ("crash");
 		gnibbles_play_sound ("gameover");
 		return (GAMEOVER);
 	}
 
-	if (status)
-		return (CONTINUE);
-
-	gnibbles_play_sound ("crash");
-	g_free (dead);
-	return (NEWROUND);
+	return (CONTINUE);
 }
 
 gint gnibbles_keypress_worms (guint keyval)
diff -urd -x '*.o' -x '*.la' -x '*.lo' -x '\.deps' -x Makefile gnome-games-2.8.2/gnibbles/worm.c ../gnome-games-2.8.2/gnibbles/worm.c
--- gnome-games-2.8.2/gnibbles/worm.c	2004-02-14 03:43:12 +0100
+++ ../gnome-games-2.8.2/gnibbles/worm.c	2005-02-15 15:39:42 +0100
@@ -108,11 +108,11 @@
 gnibbles_worm_set_start (GnibblesWorm *worm, guint t_xhead, guint t_yhead,
 			 gint t_direction)
 {
-	worm->xhead = t_xhead;
-	worm->yhead = t_yhead;
+	worm->init_xhead = worm->xhead = t_xhead;
+	worm->init_yhead =worm->yhead = t_yhead;
 	worm->xtail = t_xhead;
 	worm->ytail = t_yhead;
-	worm->direction = t_direction;
+	worm->init_direction = worm->direction = t_direction;
 	worm->xoff[0] = 0;
 	worm->yoff[0] = 0;
 	worm->start = 0;
@@ -492,3 +492,29 @@
 		}
 	}
 }
+
+void gnibbles_worm_reset (GnibblesWorm *worm)
+{
+	/* Remove Worm from Field */
+	
+	while (worm->stop != worm->start)
+	{
+		board[worm->xtail][worm->ytail] = EMPTYCHAR;
+		gnibbles_draw_pixmap(BLANKPIXMAP, worm->xtail,
+			worm->ytail);
+
+		worm->xtail -= worm->xoff[worm->stop];
+		worm->ytail -= worm->yoff[worm->stop];
+		
+		worm->stop ++;
+		if (worm->stop == CAPACITY)
+			worm->stop = 0;
+	}
+	
+	board[worm->xtail][worm->ytail] = EMPTYCHAR;
+	gnibbles_draw_pixmap(BLANKPIXMAP, worm->xtail,
+		worm->ytail);
+	
+	gnibbles_worm_set_start (worm,
+		worm->init_xhead, worm->init_yhead, worm->init_direction);
+}
diff -urd -x '*.o' -x '*.la' -x '*.lo' -x '\.deps' -x Makefile gnome-games-2.8.2/gnibbles/worm.h ../gnome-games-2.8.2/gnibbles/worm.h
--- gnome-games-2.8.2/gnibbles/worm.h	2003-06-17 23:10:46 +0200
+++ ../gnome-games-2.8.2/gnibbles/worm.h	2005-02-15 15:09:39 +0100
@@ -28,7 +28,7 @@
 #define WORMLEFT  3
 #define WORMUP    4
 #define SLENGTH   5
-#define SLIVES    3
+#define SLIVES    6
 #define CAPACITY  BOARDWIDTH * BOARDHEIGHT
 #define ERASESIZE 6
 #define ERASETIME 500
@@ -36,7 +36,9 @@
 #define GROWFACTOR 4
 
 typedef struct
-{
+{	
+	gint init_xhead, init_yhead, init_direction;
+	
 	gint xhead, yhead;
 	gint xtail, ytail;
 	gint direction;
@@ -69,6 +71,8 @@
 
 void gnibbles_worm_erase_tail (GnibblesWorm *worm);
 
+void gnibbles_worm_reset (GnibblesWorm *worm);
+
 gint gnibbles_worm_lose_life (GnibblesWorm *worm);
 
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]