[gnome-nibbles] Add name labels to worms before game starts



commit ae48789d21b9e9e3c9ee550b0f3784c1f399774d
Author: Iulian Radu <iulian radu67 gmail com>
Date:   Tue Aug 4 00:51:18 2015 +0300

    Add name labels to worms before game starts

 src/gnome-nibbles.vala |    5 +++-
 src/nibbles-view.vala  |   50 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletions(-)
---
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index c56419c..485ba41 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -45,7 +45,7 @@ public class Nibbles : Gtk.Application
     private NibblesView? view;
     private NibblesGame? game = null;
 
-    private const int COUNTDOWN_TIME = 0;
+    private const int COUNTDOWN_TIME = 3;
 
     private const ActionEntry action_entries[] =
     {
@@ -251,6 +251,7 @@ public class Nibbles : Gtk.Application
         game.load_worm_properties (worm_settings);
 
         view.new_level (game.current_level);
+        view.create_name_labels ();
         view.connect_worm_signals ();
 
         foreach (var worm in game.worms)
@@ -277,11 +278,13 @@ public class Nibbles : Gtk.Application
         statusbar_stack.set_visible_child_name ("countdown");
 
         var seconds = COUNTDOWN_TIME;
+        view.name_labels.show ();
         Timeout.add (1000, () => {
             countdown.set_label (seconds.to_string ());
             if (seconds == 0)
             {
                 statusbar_stack.set_visible_child_name ("scoreboard");
+                view.name_labels.hide ();
                 countdown.set_label (COUNTDOWN_TIME.to_string ());
                 game.start ();
                 return Source.REMOVE;
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index a451219..ed10361 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -40,6 +40,7 @@ public class NibblesView : GtkClutter.Embed
 
     public Clutter.Stage stage { get; private set; }
     private Clutter.Actor level;
+    public Clutter.Actor name_labels { get; private set; }
 
     private Gdk.Pixbuf wall_pixmaps[11];
     public Gdk.Pixbuf worm_pixmaps[7];
@@ -350,6 +351,44 @@ public class NibblesView : GtkClutter.Embed
         level.restore_easing_state ();
     }
 
+    public void create_name_labels ()
+    {
+        name_labels = new Clutter.Actor ();
+        foreach (var worm in game.worms)
+        {
+            var color = game.worm_props.get (worm).color;
+
+            var label = new Clutter.Text.with_text ("Source Pro 10", _(@"<b>PLAYER $(worm.id + 1)</b>"));
+            label.set_use_markup (true);
+            label.set_color (Clutter.Color.from_string (colorval_name (color)));
+            // TODO: Better aligb these
+            switch (worm.direction)
+            {
+                case WormDirection.UP:
+                    label.x = (worm.head ().x - 4) * game.tile_size;
+                    label.y = (worm.head ().y - 8) * game.tile_size;
+                    break;
+                case WormDirection.DOWN:
+                    label.x = (worm.head ().x - 4) * game.tile_size;
+                    label.y = (worm.head ().y - 2) * game.tile_size;
+                    break;
+                case WormDirection.LEFT:
+                    label.x = (worm.head ().x - 6) * game.tile_size;
+                    label.y = (worm.head ().y - 4) * game.tile_size;
+                    break;
+                case WormDirection.RIGHT:
+                    label.x = (worm.head ().x - 0) * game.tile_size;
+                    label.y = (worm.head ().y - 4) * game.tile_size;
+                    break;
+                default:
+                    break;
+            }
+            name_labels.add (label);
+        }
+
+        stage.add_child (name_labels);
+    }
+
     public void connect_worm_signals ()
     {
         foreach (var worm in game.worms)
@@ -380,6 +419,17 @@ public class NibblesView : GtkClutter.Embed
                                 (y_pos / game.tile_size) * tile_size);
             actor.set_size (tile_size, tile_size);
         }
+
+        if (!name_labels.visible)
+            return;
+
+        foreach (var worm in game.worms)
+        {
+            var actor = name_labels.get_child_at_index (worm.id);
+            actor.get_position (out x_pos, out y_pos);
+            actor.x = ((x_pos / game.tile_size) * tile_size);
+            actor.y = ((y_pos / game.tile_size) * tile_size);
+        }
     }
 
     public void animate_end_game_cb ()


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