[gnome-nibbles] Increase the length of the worm when collecting a bonus



commit 721275b32768d13a7416bd1bcb3ff920fc492233
Author: Iulian Radu <iulian radu67 gmail com>
Date:   Wed Jul 8 15:02:43 2015 +0300

    Increase the length of the worm when collecting a bonus

 src/nibbles-game.vala |   12 +++++++++---
 src/nibbles-view.vala |   24 +++++++++++-------------
 src/worm.vala         |    2 ++
 3 files changed, 22 insertions(+), 16 deletions(-)
---
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index 7ac0347..59817af 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -63,7 +63,7 @@ public class NibblesGame : Object
 
     public signal void worm_moved (Worm worm);
 
-    public signal void bonus_applied (Bonus bonus);
+    public signal void bonus_applied (Worm worm);
 
     public Gee.HashMap<Worm, WormProperties?> worm_props;
 
@@ -270,7 +270,13 @@ public class NibblesGame : Object
                 continue;
             }
 
-            worm.move (walls, true);
+            if (worm.change > 0)
+            {
+                worm.move (walls, false);
+                worm.change--;
+            }
+            else
+                worm.move (walls, true);
         }
     }
 
@@ -316,7 +322,7 @@ public class NibblesGame : Object
         if (bonus == null)
             return;
         apply_bonus (bonus, worm);
-        bonus_applied (bonus);
+        bonus_applied (worm);
 
         if (walls[worm.head ().x, worm.head ().y] == BonusType.REGULAR + 'A'
             && !bonus.fake)
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index 44a9e36..6eb3afc 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -448,12 +448,9 @@ public class NibblesView : GtkClutter.Embed
     {
         var actors = worm_actors.get (worm);
 
-        /* Make the worms last actor (the tail) the new head. Then remove it
-         * and add it again so the head is always the last child added */
         var tail_actor = actors.first_child;
-        tail_actor.set_position (worm.list.first ().x * game.tile_size, worm.list.first ().y * 
game.tile_size);
         actors.remove_child (tail_actor);
-        actors.add_child (tail_actor);
+        worm_added_cb (worm);
     }
 
     public void worm_rescaled_cb (Worm worm, int tile_size)
@@ -552,16 +549,17 @@ public class NibblesView : GtkClutter.Embed
         stage.remove_child (bonus_actor);
     }
 
-    public void bonus_applied_cb (Bonus bonus)
+    public void bonus_applied_cb (Worm worm)
     {
-        var bonus_actor = bonus_actors.get (bonus);
-
-        bonus_actor.save_easing_state ();
-        bonus_actor.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUINT);
-        bonus_actor.set_easing_duration (NibblesGame.GAMEDELAY * 15);
-        bonus_actor.set_scale (1.45f, 1.45f);
-        bonus_actor.set_pivot_point (0.5f, 0.5f);
-        bonus_actor.restore_easing_state ();
+        var actors = worm_actors.get (worm);
+        var actor = actors.last_child;
+
+        actor.save_easing_state ();
+        actor.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUINT);
+        actor.set_easing_duration (NibblesGame.GAMEDELAY * 15);
+        actor.set_scale (1.45f, 1.45f);
+        actor.set_pivot_point (0.5f, 0.5f);
+        actor.restore_easing_state ();
     }
 
     public void boni_rescale (int tile_size)
diff --git a/src/worm.vala b/src/worm.vala
index be4dd0c..c1aa6dd 100644
--- a/src/worm.vala
+++ b/src/worm.vala
@@ -74,6 +74,7 @@ public class Worm : Object
         starting_direction = direction;
         lives = STARTING_LIVES;
         score = 0;
+        change = 0;
         list = new Gee.LinkedList<Position?> ();
         key_queue = new Gee.ArrayQueue<WormDirection> ();
     }
@@ -198,6 +199,7 @@ public class Worm : Object
         list.clear ();
         list.add (starting_position);
         direction = starting_direction;
+        change = 0;
         spawn (walls);
 
         key_queue.clear ();


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