[gnome-nibbles] Save number of players before switching to the controls screen



commit 76b0b2cc706df74ed7127a7e0de385e14400b28b
Author: Iulian Radu <iulian radu67 gmail com>
Date:   Tue Jul 14 17:59:31 2015 +0300

    Save number of players before switching to the controls screen

 src/gnome-nibbles.vala |   53 +++++++++++++++++++++++++++++-------------------
 src/nibbles-game.vala  |    3 +-
 src/nibbles-view.vala  |   10 +++-----
 3 files changed, 37 insertions(+), 29 deletions(-)
---
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index 2bfa16b..d9717bb 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -137,26 +137,6 @@ public class Nibbles : Gtk.Application
 
         frame.add (view);
         frame.show ();
-        // frame.show_all ();
-
-        /* TODO Fix problem and remove this call
-         * For some reason tile_size gets set to 0 after calling
-         * frame.add (view). start_level stays the same
-         */
-        game.load_properties (settings);
-        game.current_level = game.start_level;
-        view.new_level (game.current_level);
-        view.configure_event.connect (configure_event_cb);
-
-        foreach (var worm in game.worms)
-        {
-            var actors = view.worm_actors.get (worm);
-            if (actors.get_stage () == null) {
-                view.stage.add_child (actors);
-            }
-            actors.show ();
-        }
-        game.load_worm_properties (worm_settings);
 
         /* Check wether to display the first run screen */
         var first_run = settings.get_boolean ("first-run");
@@ -239,6 +219,27 @@ public class Nibbles : Gtk.Application
     private void start_game_cb ()
     {
         settings.set_boolean ("first-run", false);
+        stderr.printf("[Debug] cl %d\n", game.current_level);
+        stderr.printf("[Debug] %d\n", game.numworms);
+
+        /* TODO Fix problem and remove this call
+         * For some reason tile_size gets set to 0 after calling
+         * frame.add (view). start_level stays the same
+         */
+        game.load_properties (settings);
+        game.current_level = game.start_level;
+        view.new_level (game.current_level);
+        view.configure_event.connect (configure_event_cb);
+
+        foreach (var worm in game.worms)
+        {
+            var actors = view.worm_actors.get (worm);
+            if (actors.get_stage () == null) {
+                view.stage.add_child (actors);
+            }
+            actors.show ();
+        }
+        game.load_worm_properties (worm_settings);
         game.add_worms ();
         show_game_view ();
 
@@ -247,8 +248,8 @@ public class Nibbles : Gtk.Application
             countdown.set_label ("%d".printf (seconds));
             if (seconds == 0)
             {
-                countdown.hide ();
                 countdown.set_label ("GO!");
+                countdown.hide ();
                 game.start ();
                 return Source.REMOVE;
             }
@@ -269,6 +270,16 @@ public class Nibbles : Gtk.Application
 
     private void show_controls_screen_cb ()
     {
+        /* Save selected number of players before changing the screen */
+        foreach (var button in number_of_players_buttons)
+        {
+            if (button.get_active ())
+            {
+                var label = button.get_label ();
+                game.numworms = int.parse (label);
+            }
+        }
+
         main_stack.set_visible_child_name ("controls");
     }
 
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index f761327..0ee4fd1 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -42,7 +42,7 @@ public class NibblesGame : Object
     public const int GAMEDELAY = 35;
     public const int BONUSDELAY = 100;
 
-    public const int NUMWORMS = 1;
+    public const int NUMWORMS = 2;
 
     public const int WIDTH = 92;
     public const int HEIGHT = 66;
@@ -90,7 +90,6 @@ public class NibblesGame : Object
 
     public void add_worms ()
     {
-        stderr.printf("[Debug] Loading worms\n");
         foreach (var worm in worms)
         {
             worm.spawn (walls);
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index 6834aef..a66e41d 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -365,17 +365,16 @@ public class NibblesView : GtkClutter.Embed
                 {
                     x_pos = j * game.tile_size;
 
-                    ((Clutter.Actor) tmp).set_size (game.tile_size,
-                                                    game.tile_size);
-                    ((Clutter.Actor) tmp).set_position (x_pos, y_pos);
-                    level.add_child ((Clutter.Actor) tmp);
+                    tmp.set_size (game.tile_size, game.tile_size);
+                    tmp.set_position (x_pos, y_pos);
+                    level.add_child (tmp);
                 }
             }
         }
         stage.add_child (level);
 
         level.set_opacity (0);
-        ((Clutter.Actor) level).set_scale (0.2, 0.2);
+        level.set_scale (0.2, 0.2);
 
         level.save_easing_state ();
         level.set_easing_mode (Clutter.AnimationMode.EASE_OUT_BOUNCE);
@@ -436,7 +435,6 @@ public class NibblesView : GtkClutter.Embed
             /* Fatal console error when a worm's texture could not be set. */
             error (_("Nibbles failed to set texture: %s"), e.message);
         }
-
         actor.set_size (game.tile_size, game.tile_size);
         actor.set_position (worm.list.first ().x * game.tile_size, worm.list.first ().y * game.tile_size);
 


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