seed r245 - trunk/examples/lightsoff
- From: hortont svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r245 - trunk/examples/lightsoff
- Date: Tue, 11 Nov 2008 12:15:40 +0000 (UTC)
Author: hortont
Date: Tue Nov 11 12:15:40 2008
New Revision: 245
URL: http://svn.gnome.org/viewvc/seed?rev=245&view=rev
Log:
Improved replaced lights off (win animation, memory, etc.)
Modified:
trunk/examples/lightsoff/board.js
trunk/examples/lightsoff/light.js
trunk/examples/lightsoff/main.js
Modified: trunk/examples/lightsoff/board.js
==============================================================================
--- trunk/examples/lightsoff/board.js (original)
+++ trunk/examples/lightsoff/board.js Tue Nov 11 12:15:40 2008
@@ -1,3 +1,34 @@
+function check_won (timeline, light)
+{
+ if(light.get_parent().cleared() && !in_setup)
+ win_animation();
+}
+
+function flip_region (act, evt, light)
+{
+ var x = light.light_x;
+ var y = light.light_y;
+
+ var fadeline = new Clutter.Timeline({num_frames:30});
+
+ light.flip(fadeline);
+
+ if(x + 1 < tiles)
+ light.get_parent().lights[x + 1][y].flip(fadeline);
+ if(x - 1 >= 0)
+ light.get_parent().lights[x - 1][y].flip(fadeline);
+ if(y + 1 < tiles)
+ light.get_parent().lights[x][y + 1].flip(fadeline);
+ if(y - 1 >= 0)
+ light.get_parent().lights[x][y - 1].flip(fadeline);
+
+ fadeline.start();
+
+ fadeline.signal.completed.connect(check_won, null, light);
+
+ return true;
+}
+
BoardType = {
parent: Clutter.Group.type,
name: "Board",
@@ -7,10 +38,41 @@
{
for(x in this.lights)
for(y in this.lights[x])
- if(!this.lights[x][y].state)
+ if(this.lights[x][y].state)
return false;
return true;
}
+
+ prototype.randomize = function ()
+ {
+ in_setup = true;
+
+ //var count = Math.round(tiles*5* Math.random());
+ var count = -4;
+
+ var sym = Math.floor(3*Math.random());
+
+ for (q = 0; q < count + 5; ++q)
+ {
+ i = Math.round((tiles-1) * Math.random());
+ j = Math.round((tiles-1) * Math.random());
+
+ flip_region(null, null, this.lights[i][j]);
+
+ if(sym == 0)
+ flip_region(null, null, this.lights[Math.abs(i-(tiles-1))][j]);
+ else if(sym == 1)
+ flip_region(null, null,
+ this.lights[Math.abs(i-(tiles-1))][Math.abs(j-(tiles-1))]);
+ else
+ flip_region(null, null, this.lights[i][Math.abs(j-(tiles-1))]);
+ }
+
+ if(this.cleared())
+ this.randomize();
+
+ in_setup = false;
+ }
},
instance_init: function(klass)
{
@@ -28,6 +90,8 @@
this.add_actor(this.lights[x][y]);
}
}
+
+ this.randomize();
}};
Board = new GType(BoardType);
Modified: trunk/examples/lightsoff/light.js
==============================================================================
--- trunk/examples/lightsoff/light.js (original)
+++ trunk/examples/lightsoff/light.js Tue Nov 11 12:15:40 2008
@@ -3,7 +3,7 @@
name: "Light",
class_init: function(klass, prototype)
{
- prototype.flip = function ()
+ prototype.flip = function (fadeline)
{
this.state = !this.state;
@@ -11,38 +11,39 @@
{
this.on.opacity = this.state * 255;
this.off.opacity = !this.state * 255;
-
+
return true;
}
- var fadeline = new Clutter.Timeline({fps:60, num_frames:20});
var effect = Clutter.EffectTemplate._new(fadeline,
Clutter.sine_inc_func);
Clutter.effect_fade(effect, this.on, this.state * 255);
Clutter.effect_fade(effect, this.off, !this.state * 255);
- fadeline.start();
+ Clutter.effect_rotate(effect, this, Clutter.RotateAxis.x_axis, 360, 25, 25, 25);
+ //Clutter.effect_rotate(effect, this, Clutter.RotateAxis.y_axis, 180, 25, 0, 0);
return true;
}
},
instance_init: function(klass)
{
- this.state = true;
+ this.state = false;
+ this.on = new Clutter.CloneTexture({parent_texture: on_svg,
+ reactive: true});
this.off = new Clutter.CloneTexture({parent_texture: off_svg,
reactive: true});
- this.on = new Clutter.CloneTexture({parent_texture: on_svg,
- reactive: true});
-
- this.off.opacity = 0.0;
-
+
+ this.on.opacity = 0.0;
+
this.on.signal.button_press_event.connect(flip_region, null, this);
this.off.signal.button_press_event.connect(flip_region, null, this);
- this.add_actor(this.off);
this.add_actor(this.on);
+ this.add_actor(this.off);
+
}};
Light = new GType(LightType);
Modified: trunk/examples/lightsoff/main.js
==============================================================================
--- trunk/examples/lightsoff/main.js (original)
+++ trunk/examples/lightsoff/main.js Tue Nov 11 12:15:40 2008
@@ -12,63 +12,54 @@
Seed.include("light.js");
Seed.include("board.js");
-flip_region = function (act, evt, light)
+function alpha_func(alpha)
{
- var x = light.light_x;
- var y = light.light_y;
-
- light.flip();
-
- if(x + 1 < tiles)
- light.get_parent().lights[x + 1][y].flip();
- if(x - 1 >= 0)
- light.get_parent().lights[x - 1][y].flip();
- if(y + 1 < tiles)
- light.get_parent().lights[x][y + 1].flip();
- if(y - 1 >= 0)
- light.get_parent().lights[x][y - 1].flip();
-
- if(board.cleared() && !in_setup)
- Seed.print("Glorious victory!");
-
- return true;
+ timeline = alpha.get_timeline();
+ frame = timeline.get_current_frame();
+ n_frames = timeline.num_frames;
+ fps = timeline.fps;
+ duration = n_frames/fps;
+ time = frame/fps;
+
+ if ((time/=duration) < (1/2.75))
+ return Clutter.ALPHA_MAX_ALPHA*(7.5625*time*time);
+ else if (time < (2/2.75))
+ return Clutter.ALPHA_MAX_ALPHA*(7.5625 * (time-=(1.5/2.75))*time+.75);
+ else if (time < (2.5/2.75))
+ return Clutter.ALPHA_MAX_ALPHA*(7.5625 *(time-=(2.25/2.75))*time+.9375);
+ else
+ return Clutter.ALPHA_MAX_ALPHA*(7.5625 * (time-=(2.625/2.75))*time+.984375);
}
-function random_clicks()
+function destroy_board()
{
- in_setup = true;
-
- //var count = Math.round(tiles*5* Math.random());
- var count = -4;
-
- var sym = Math.floor(3*Math.random());
-
- for (q = 0; q < count + 5; ++q)
- {
- i = Math.round((tiles-1) * Math.random());
- j = Math.round((tiles-1) * Math.random());
-
- flip_region(null, null, board.lights[i][j]);
-
- if(sym == 0)
- flip_region(null, null, board.lights[Math.abs(i-(tiles-1))][j]);
- else if(sym == 1)
- flip_region(null, null,
- board.lights[Math.abs(i-(tiles-1))][Math.abs(j-(tiles-1))]);
- else
- flip_region(null, null, board.lights[i][Math.abs(j-(tiles-1))]);
- }
-
- in_setup = false;
-
- // do it again if you won already
- if(board.cleared())
- random_clicks();
+ this.destroy();
}
function win_animation()
{
+ var direction = Math.floor(2 * Math.random());
+ var sign = Math.floor(2 * Math.random()) ? 1 : -1;
+ var offscreen = 55 * tiles + 5;
+
+ var new_board = new Board();
+ new_board.set_position(sign * direction * offscreen,
+ sign * (!direction) * offscreen);
+ new_board.show();
+ stage.add_actor(new_board);
+ var fadeline = new Clutter.Timeline({num_frames:80});
+ var effect = Clutter.EffectTemplate._new(fadeline, alpha_func);
+
+ Clutter.effect_move(effect, new_board, 0, 0);
+ var remove_line = Clutter.effect_move(effect, board,
+ -(sign)*(direction * offscreen), -(sign)*((!direction) * offscreen));
+
+ fadeline.start();
+
+ remove_line.signal.completed.connect(destroy_board, board);
+
+ board = new_board;
}
var on_svg = Clutter.Texture.new_from_file("./tim-on.svg");
@@ -86,7 +77,5 @@
stage.add_actor(board);
stage.show_all();
-random_clicks();
-
Clutter.main();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]