[gnome-games] [same-gnome-clutter] Significant overhaul fixes most of the animation/stickyness problems



commit 96979ddb7dc47c7b41f5c7cf20bed3ce8b09a56b
Author: Tim Horton <hortont424 gmail com>
Date:   Sun Jun 28 03:52:36 2009 -0400

    [same-gnome-clutter] Significant overhaul fixes most of the animation/stickyness problems

 same-gnome-clutter/board.js    |  106 ++++++++++++----------------------------
 same-gnome-clutter/light.js.in |   37 +++++++-------
 same-gnome-clutter/score.js    |   20 +++----
 3 files changed, 59 insertions(+), 104 deletions(-)
---
diff --git a/same-gnome-clutter/board.js b/same-gnome-clutter/board.js
index eefd2ee..975c006 100644
--- a/same-gnome-clutter/board.js
+++ b/same-gnome-clutter/board.js
@@ -11,34 +11,17 @@ Board = new GType({
 	{
 		// Private
 		var lights = [], all_lights = [];
-		var cl, oldcl = [], oldpicked;
+		var last_light;
 		var animating = false;
+		var anim_timeline;
 		var final_score;
 		
+		// TODO: when a click is rejected, queue it up, like in the C version
+		
 		function done_animating()
 		{
 			animating = false;
 			
-			/*var x = {}, y = {};
-			window.window.get_pointer(x, y, null);
-			
-			var picked = stage.get_actor_at_pos(x.value, y.value);
-			
-			print(picked);
-			
-			if(picked)
-				picked = picked.get_parent();
-			
-			if(picked && picked.get_light_x)
-			{
-				if(picked == oldpicked)
-					return false;
-			
-				oldpicked = picked;
-				
-				light_lights_from(picked);
-			}*/
-			
 			return false;
 		}
 		
@@ -87,31 +70,6 @@ Board = new GType({
 			return _connected_lights(li);
 		}
 		
-		function any_connected_lights(li)
-		{
-			if(!li || li.get_closed())
-				return false;
-			
-			var x = li.get_light_x();
-			var y = li.get_light_y();
-			
-			if(lights[x][y+1] && (li.get_state() == lights[x][y+1].get_state()))
-				return !lights[x][y+1].get_closed();
-
-			if(lights[x][y-1] && (li.get_state() == lights[x][y-1].get_state()))
-				return !lights[x][y-1].get_closed();
-			
-			if(lights[x+1] && lights[x+1][y] &&
-			   (li.get_state() == lights[x+1][y].get_state()))
-				return !lights[x+1][y].get_closed();
-			
-			if(lights[x-1] && lights[x-1][y] &&
-			   (li.get_state() == lights[x-1][y].get_state()))
-				return !lights[x-1][y].get_closed();
-			
-			return false;
-		}
-		
 		function calculate_score(n_lights)
 		{
 			if (n_lights < 3)
@@ -124,11 +82,7 @@ Board = new GType({
 		{
 			var i;
 			
-			cl = connected_lights(li);
-			
-			for(i in oldcl)
-				if(!oldcl[i].get_closed())
-					oldcl[i].opacity = 180;
+			var cl = connected_lights(li);
 			
 			if(cl.length < 2)
 				return false;
@@ -165,18 +119,25 @@ Board = new GType({
 			}
 		}
 		
-		function enter_tile(actor, event)
+		function light_entered(actor, event)
 		{
-			var picked = main.stage.get_actor_at_pos(Clutter.PickMode.ALL,
-			                                    event.motion.x,
-			                                    event.motion.y).get_parent();
-			
-			if(picked === oldpicked)
+			if(actor === last_light)
 				return false;
 			
-			oldpicked = picked;
+			last_light = actor;
 			
-			light_lights_from(picked);
+			light_lights_from(actor);
+			
+			return false;
+		}
+		
+		function light_left(actor, event)
+		{
+			var connected = connected_lights(actor);
+			
+			for(var i in connected)
+				if(!connected[i].get_closed())
+					connected[i].opacity = 180;
 			
 			return false;
 		}
@@ -188,7 +149,7 @@ Board = new GType({
 			{
 				li = all_lights[i];
 				
-				if(!li.get_closed() && any_connected_lights(li))
+				if(!li.get_closed() && (connected_lights(li).length > 1))
 					return false;
 			}
 			
@@ -217,9 +178,8 @@ Board = new GType({
 		{
 			if(animating)
 				return false;
-				
-			if(!cl)
-				light_lights_from(actor.get_parent());
+						
+			var cl = connected_lights(actor);
 			
 			if(cl.length < 2)
 				return false;
@@ -235,7 +195,7 @@ Board = new GType({
 			
 			animating = true;
 			
-			var anim_timeline = new Clutter.Timeline({duration: 500});
+			anim_timeline = new Clutter.Timeline({duration: 500});
 			
 			for(var x in lights)
 			{
@@ -284,21 +244,16 @@ Board = new GType({
 				if(!empty_col)
 					real_x++;
 			}
-
-			if(anim_timeline)
-            {
-				anim_timeline.signal.completed.connect(done_animating);
-				anim_timeline.start();
-			}
-			else
-				animating = false;
+		
+			anim_timeline.signal.completed.connect(done_animating);
+			anim_timeline.start();
 			
 			for(; real_x < main.tiles_w; real_x++)
 				lights[real_x] = null;
 			
 			update_score(cl.length);
 			
-			cl = oldpicked = null;
+			cl = last_light = null;
 			
 			return false;
 		};
@@ -328,7 +283,9 @@ Board = new GType({
 					li.set_position(x * main.tile_size + main.offset,
 									(main.tiles_h - y - 1) * main.tile_size + main.offset);
 					self.add_actor(li);
-					li.on.signal.button_release_event.connect(self.remove_region);
+					li.signal.button_release_event.connect(self.remove_region);
+					li.signal.enter_event.connect(light_entered);
+					li.signal.leave_event.connect(light_left);
 				
 					lights[x][y] = li;
 					all_lights.push(lights[x][y]);
@@ -337,7 +294,6 @@ Board = new GType({
 		};
 		
 		// Implementation
-		this.signal.motion_event.connect(enter_tile);
 		this.reactive = true;
 	}
 });
diff --git a/same-gnome-clutter/light.js.in b/same-gnome-clutter/light.js.in
index 5f019f7..d983f95 100644
--- a/same-gnome-clutter/light.js.in
+++ b/same-gnome-clutter/light.js.in
@@ -29,8 +29,7 @@ Light = new GType({
 	this.visited = false;
 	
 	if(loaded_colors[state])
-		this.on = new Clutter.Clone({source: loaded_colors[state],
-		                             reactive: true});
+		this.on = new Clutter.Clone({source: loaded_colors[state]});
 	else
 		this.on = loaded_colors[state] = load_svg(colors[state]);
 	
@@ -42,18 +41,18 @@ Light = new GType({
 	
 	this.animate_out = function (timeline)
 	{
-	    this.on.anim = this.on.animate_with_timeline(Clutter.AnimationMode.LINEAR, timeline,
-							 {
-							     height: main.tile_size * 2,
-							     width: main.tile_size * 2,
-							     x: -main.tile_size/2,
-							     y: -main.tile_size/2
-							 });
+	    this.on.animate_with_timeline(Clutter.AnimationMode.LINEAR, timeline,
+		{
+			height: main.tile_size * 2,
+			width: main.tile_size * 2,
+			x: -main.tile_size/2,
+			y: -main.tile_size/2
+		});
 	    
-	    this.anim = this.animate_with_timeline(Clutter.AnimationMode.LINEAR, timeline,
-						   {
-						       opacity: 0
-						   });
+	    this.animate_with_timeline(Clutter.AnimationMode.LINEAR, timeline,
+		{
+		   opacity: 0
+		});
 	    
 	    timeline.signal.completed.connect(this.hide_light, this);
 	    
@@ -62,11 +61,11 @@ Light = new GType({
 	
 	this.animate_to = function (new_x, new_y, timeline)
 	{
-	    this.anim = this.animate_with_timeline(Clutter.AnimationMode.EASE_OUT_BOUNCE, timeline,
-						   {
-						       x: new_x,
-						       y: new_y
-						   });
+	    this.animate_with_timeline(Clutter.AnimationMode.EASE_OUT_BOUNCE, timeline,
+		{
+			x: new_x,
+			y: new_y
+		});
 	    
 	    GLib.main_context_iteration();
 	};
@@ -118,6 +117,7 @@ Light = new GType({
 	this.on.set_size(main.tile_size, main.tile_size);
 	
 	this.opacity = 180;
+	this.reactive = true;
 	
 	this.set_anchor_point(main.tile_size / 2, main.tile_size / 2);
 	
@@ -125,3 +125,4 @@ Light = new GType({
     }
 });
 
+
diff --git a/same-gnome-clutter/score.js b/same-gnome-clutter/score.js
index adab97d..f7f6ad5 100644
--- a/same-gnome-clutter/score.js
+++ b/same-gnome-clutter/score.js
@@ -27,19 +27,18 @@ Score = new GType({
 			
 			label.set_font_name("Bitstrem Vera Sans Bold 40");
 			label.set_text("+" + points);
-			this.set_anchor_point(this.width/2, this.height/2);
 			
 			main.stage.add_actor(this);
 			this.show();
 			
-			this.anim = this.animate(Clutter.AnimationMode.EASE_OUT_SINE,400,
+			var a = this.animate(Clutter.AnimationMode.EASE_OUT_SINE,600,
 			{
 			    depth:  500,
-			    opacity: 0,
+			    opacity: 0
 			});
-			this.anim.timeline.start();
-			
-			this.anim.timeline.signal.completed.connect(this.hide_score, this);
+
+			a.timeline.start();			
+			a.timeline.signal.completed.connect(this.hide_score, this);
 		};
 		
 		this.animate_final_score = function (points)
@@ -48,8 +47,6 @@ Score = new GType({
 			label.set_markup("<b>Game Over!</b>\n" + points + " points");
 			label.set_line_alignment(Pango.Alignment.CENTER);
 			
-			this.set_anchor_point(this.width/2, this.height/2);
-			
 			main.stage.add_actor(this);
 			this.show();
 			
@@ -57,22 +54,23 @@ Score = new GType({
 			//this.y = -this.height;
 			this.scale_x = this.scale_y = 0;
 			
-			this.anim = this.animate(Clutter.AnimationMode.EASE_OUT_ELASTIC,2000,
+			var a = this.animate(Clutter.AnimationMode.EASE_OUT_ELASTIC,2000,
 			{
 			    scale_x: 1,
 			    scale_y: 1,
 				//y: [GObject.TYPE_INT, stage.width / 2],
 			    opacity: 255,
 			});
-			this.anim.timeline.start();
 			
-			//this.anim.timeline.signal.completed.connect(this.hide_score, this);
+			a.timeline.start();
+			//a.timeline.signal.completed.connect(this.hide_score, this);
 		};
 		
 		// Implementation
 		label = new Clutter.Text();
 		label.set_color({red:255, green:255, blue:255, alpha:255});
 		
+		this.anchor_gravity = Clutter.Gravity.CENTER;
 		this.add_actor(label);
 		label.show();
 		



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