[gnome-nibbles/wip/vala: 56/64] Implement end game animation
- From: Iulian Radu <iulianradu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles/wip/vala: 56/64] Implement end game animation
- Date: Sun, 9 Aug 2015 12:56:07 +0000 (UTC)
commit 0257dee2984b27aa760aff2c301b2adc4e228afa
Author: Iulian Radu <iulian radu67 gmail com>
Date: Mon Jul 27 19:18:27 2015 +0300
Implement end game animation
src/gnome-nibbles.vala | 2 +-
src/nibbles-game.vala | 37 +++++++++++++++++++++++++++++-----
src/nibbles-view.vala | 50 ++++++++++++++++++++++++++++++++++++++++++-----
3 files changed, 76 insertions(+), 13 deletions(-)
---
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index 665d168..817db85 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -253,7 +253,7 @@ public class Nibbles : Gtk.Application
*/
game.load_properties (settings);
game.current_level = game.start_level;
- game.loop_ended.connect (scoreboard.update);
+ game.loop_started.connect (scoreboard.update);
view.new_level (game.current_level);
view.configure_event.connect (configure_event_cb);
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index ecc6ad7..04851bd 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -61,10 +61,14 @@ public class NibblesGame : Object
public bool fakes = false;
+ private uint main_id = 0;
+ private uint add_bonus_id = 0;
+
public signal void worm_moved (Worm worm);
public signal void bonus_applied (Worm worm);
- public signal void loop_ended ();
+ public signal void loop_started ();
public signal void log_score (Worm worm);
+ public signal void animate_end_game ();
public Gee.HashMap<Worm, WormProperties?> worm_props;
@@ -83,13 +87,28 @@ public class NibblesGame : Object
{
add_bonus (true);
- var main_id = Timeout.add (GAMEDELAY * game_speed, main_loop_cb);
+ main_id = Timeout.add (GAMEDELAY * game_speed, main_loop_cb);
Source.set_name_by_id (main_id, "[Nibbles] main_loop_cb");
- var add_bonus_id = Timeout.add (BONUSDELAY * game_speed, add_bonus_cb);
+ add_bonus_id = Timeout.add (BONUSDELAY * game_speed, add_bonus_cb);
Source.set_name_by_id (add_bonus_id, "[Nibbles] add_bonus_cb");
}
+ private void stop ()
+ {
+ if (main_id != 0)
+ {
+ Source.remove (main_id);
+ main_id = 0;
+ }
+
+ if (add_bonus_id != 0)
+ {
+ Source.remove (add_bonus_id);
+ add_bonus_id = 0;
+ }
+ }
+
public void add_worms ()
{
foreach (var worm in worms)
@@ -336,22 +355,21 @@ public class NibblesGame : Object
public bool main_loop_cb ()
{
var status = get_game_status ();
+ loop_started ();
if (status == GameStatus.VICTORY)
{
- // end_game ();
+ end_game ();
var winner = get_winner ();
if (winner == null)
return Source.REMOVE;
- stderr.printf("[Debug] Logging score\n");
log_score (winner);
return Source.REMOVE;
}
move_worms ();
- loop_ended ();
return Source.CONTINUE;
}
@@ -366,6 +384,7 @@ public class NibblesGame : Object
}
if (worms_left == 1 && numworms > 1)
+ /* There were multiple worms but only one is still alive */
return GameStatus.VICTORY;
else if (worms_left == 0) {
/* There was only one worm and it died */
@@ -386,6 +405,12 @@ public class NibblesGame : Object
return null;
}
+ private void end_game ()
+ {
+ stop ();
+ animate_end_game ();
+ }
+
public void load_properties (Settings settings)
{
tile_size = settings.get_int ("tile-size");
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index 85cb9bc..cf1df92 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -33,6 +33,8 @@ public class NibblesView : GtkClutter.Embed
_game.boni.bonus_removed.connect (bonus_removed_cb);
_game.bonus_applied.connect (bonus_applied_cb);
+
+ _game.animate_end_game.connect (animate_end_game_cb);
}
}
@@ -356,6 +358,15 @@ public class NibblesView : GtkClutter.Embed
level.restore_easing_state ();
}
+ private void connect_signals (Worm worm)
+ {
+ worm.added.connect (worm_added_cb);
+ worm.moved.connect (worm_moved_cb);
+ worm.rescaled.connect (worm_rescaled_cb);
+ worm.died.connect (worm_died_cb);
+ worm.tail_reduced.connect (worm_tail_reduced_cb);
+ }
+
public void board_rescale (int tile_size)
{
int board_width, board_height;
@@ -376,13 +387,40 @@ public class NibblesView : GtkClutter.Embed
}
}
- private void connect_signals (Worm worm)
+ public void animate_end_game_cb ()
{
- worm.added.connect (worm_added_cb);
- worm.moved.connect (worm_moved_cb);
- worm.rescaled.connect (worm_rescaled_cb);
- worm.died.connect (worm_died_cb);
- worm.tail_reduced.connect (worm_tail_reduced_cb);
+ foreach (var worm in game.worms)
+ {
+ var actors = worm_actors.get (worm);
+
+ actors.save_easing_state ();
+ actors.set_easing_mode (Clutter.AnimationMode.EASE_IN_QUAD);
+ actors.set_easing_duration (NibblesGame.GAMEDELAY * 15);
+ actors.set_scale (0.4f, 0.4f);
+ actors.set_opacity (0);
+ actors.restore_easing_state ();
+ }
+
+ foreach (var bonus in game.boni.bonuses)
+ {
+ var actor = bonus_actors.get (bonus);
+
+ actor.save_easing_state ();
+ actor.set_easing_mode (Clutter.AnimationMode.EASE_IN_QUAD);
+ actor.set_easing_duration (NibblesGame.GAMEDELAY * 15);
+ actor.set_scale (0.4f, 0.4f);
+ actor.set_pivot_point (0.5f, 0.5f);
+ actor.set_opacity (0);
+ actor.restore_easing_state ();
+ }
+
+ level.save_easing_state ();
+ level.set_easing_mode (Clutter.AnimationMode.EASE_IN_QUAD);
+ level.set_easing_duration (NibblesGame.GAMEDELAY * 20);
+ level.set_scale (0.4f, 0.4f);
+ level.set_pivot_point (0.5f, 0.5f);
+ level.set_opacity (0);
+ level.restore_easing_state ();
}
public void worm_added_cb (Worm worm)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]