[gnome-nibbles/wip/vala: 34/64] Take into the account the worm's reduction of body when checking for collision with itself
- From: Iulian Radu <iulianradu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles/wip/vala: 34/64] Take into the account the worm's reduction of body when checking for collision with itself
- Date: Sun, 9 Aug 2015 12:54:16 +0000 (UTC)
commit 3acf5e700ea1b10ae0ee48272017bb91fc961b67
Author: Iulian Radu <iulian radu67 gmail com>
Date: Fri Jul 3 16:14:07 2015 +0300
Take into the account the worm's reduction of body when checking for collision with itself
src/nibbles-game.vala | 4 ++--
src/worm.vala | 12 ++++++++----
2 files changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index 7a61c7b..3282969 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -205,9 +205,9 @@ public class NibblesGame : Object
foreach (var other_worm in worms)
{
if (worm.will_collide_with_head (other_worm)
- && worm != other_worm)
+ && worm != other_worm
+ && !other_worm.is_stopped)
{
- stderr.printf("[Debug] Head collision\n");
worm.die (walls);
other_worm.die (walls);
continue;
diff --git a/src/worm.vala b/src/worm.vala
index f88f786..b760437 100644
--- a/src/worm.vala
+++ b/src/worm.vala
@@ -122,8 +122,6 @@ public class Worm : Object
/* Add a new body piece */
list.offer_head (position);
- /* Mark the tile as occupied by the worm's body */
- walls[head ().x, head ().y] = NibblesGame.WORMCHAR + id;
if (remove)
{
@@ -134,6 +132,9 @@ public class Worm : Object
else
added ();
+ /* Mark the tile as occupied by the worm's body */
+ walls[head ().x, head ().y] = NibblesGame.WORMCHAR + id;
+
if (!key_queue.is_empty)
dequeue_keypress ();
}
@@ -142,9 +143,12 @@ public class Worm : Object
{
var position = position_move ();
- if (walls[position.x, position.y] > NibblesGame.EMPTYCHAR &&
- walls[position.x, position.y] < 'z' + numworms)
+ if (walls[position.x, position.y] > NibblesGame.EMPTYCHAR
+ && walls[position.x, position.y] < 'z' + numworms
+ && position != list.last ()) /* The last position of the worm won't exist in the next frame */
+ {
return false;
+ }
return true;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]