[gnome-nibbles/wip/vala] Add animation with delay for respawning worm. Ignore keypresses when game is not running and when wo



commit 614be6c8b32e25eb9ba4e0aa03385ecf7cdcc688
Author: Razvan Chitu <razvan ch95 gmail com>
Date:   Tue Sep 29 16:12:24 2015 +0300

    Add animation with delay for respawning worm. Ignore keypresses when game is not running and when worm is 
stopped
    
    https://bugzilla.gnome.org/show_bug.cgi?id=754608

 src/nibbles-game.vala |    8 ++++----
 src/nibbles-view.vala |   22 ++++++++++++++++++++++
 src/worm.vala         |   13 +++++++------
 3 files changed, 33 insertions(+), 10 deletions(-)
---
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index 2e63f99..a8e9125 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -269,9 +269,9 @@ public class NibblesGame : Object
 
             foreach (var other_worm in worms)
             {
-                if (worm.will_collide_with_head (other_worm)
-                    && worm != other_worm
-                    && !other_worm.is_stopped)
+                if (worm != other_worm
+                    && !other_worm.is_stopped
+                    && worm.will_collide_with_head (other_worm))
                     {
                         if (!dead_worms.contains (worm))
                             dead_worms.add (worm);
@@ -572,7 +572,7 @@ public class NibblesGame : Object
 
     public bool handle_keypress (uint keyval)
     {
-        if (is_paused)
+        if (!is_running)
             return false;
 
         foreach (var worm in worms)
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index 830930d..7961a92 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -405,6 +405,7 @@ public class NibblesView : GtkClutter.Embed
         foreach (var worm in game.worms)
         {
             worm.added.connect (worm_added_cb);
+            worm.finish_added.connect (worm_finish_added_cb);
             worm.moved.connect (worm_moved_cb);
             worm.rescaled.connect (worm_rescaled_cb);
             worm.died.connect (worm_died_cb);
@@ -526,6 +527,27 @@ public class NibblesView : GtkClutter.Embed
         actors.add_child (actor);
     }
 
+    private void worm_finish_added_cb (Worm worm)
+    {
+        var actors = worm_actors.get (worm);
+
+        actors.set_opacity (0);
+        actors.set_scale (3.0, 3.0);
+
+        actors.save_easing_state ();
+        actors.set_easing_mode (Clutter.AnimationMode.EASE_OUT);
+        actors.set_easing_duration (NibblesGame.GAMEDELAY * 20);
+        actors.set_scale (1.0, 1.0);
+        actors.set_pivot_point (0.5f, 0.5f);
+        actors.set_opacity (0xff);
+        actors.restore_easing_state ();
+
+        Timeout.add (NibblesGame.GAMEDELAY * 27, () => {
+            worm.is_stopped = false;
+            return Source.REMOVE;
+        });
+    }
+
     private void worm_moved_cb (Worm worm)
     {
         var actors = worm_actors.get (worm);
diff --git a/src/worm.vala b/src/worm.vala
index 2bc191c..448ec8a 100644
--- a/src/worm.vala
+++ b/src/worm.vala
@@ -67,6 +67,7 @@ public class Worm : Object
     public Gee.LinkedList<Position?> list { get; private set; }
 
     public signal void added ();
+    public signal void finish_added ();
     public signal void moved ();
     public signal void rescaled (int tile_size);
     public signal void died ();
@@ -250,6 +251,8 @@ public class Worm : Object
     public void reset (int[,] board)
     {
         is_stopped = true;
+        key_queue.clear ();
+
         lose_life ();
 
         died ();
@@ -264,9 +267,7 @@ public class Worm : Object
         change = 0;
         spawn (board);
 
-        key_queue.clear ();
-
-        is_stopped = false;
+        finish_added ();
     }
 
     private Position position_move ()
@@ -339,12 +340,12 @@ public class Worm : Object
 
     public bool handle_keypress (uint keyval, Gee.HashMap<Worm, WormProperties?> worm_props)
     {
+        if (lives <= 0 || is_stopped)
+            return false;
+
         WormProperties properties;
         uint propsUp, propsDown, propsLeft, propsRight, keyvalUpper;
 
-        if (lives <= 0)
-            return false;
-
         properties = worm_props.get (this);
         propsUp = upper_key (properties.up);
         propsLeft = upper_key (properties.left);


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