seed r592 - trunk/examples/lightsoff
- From: hortont svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r592 - trunk/examples/lightsoff
- Date: Wed, 31 Dec 2008 03:30:01 +0000 (UTC)
Author: hortont
Date: Wed Dec 31 03:30:00 2008
New Revision: 592
URL: http://svn.gnome.org/viewvc/seed?rev=592&view=rev
Log:
I think I'm done reorganizing lightsoff for now.
Modified:
trunk/examples/lightsoff/board.js
trunk/examples/lightsoff/main.js
trunk/examples/lightsoff/score.js
Modified: trunk/examples/lightsoff/board.js
==============================================================================
--- trunk/examples/lightsoff/board.js (original)
+++ trunk/examples/lightsoff/board.js Wed Dec 31 03:30:00 2008
@@ -114,8 +114,6 @@
}
}
-Seed.import_namespace("GObject");
-
function flip_region (act, evt, light)
{
if(!in_setup && in_fade)
@@ -127,15 +125,17 @@
var fadeline = new Clutter.Timeline({num_frames: 20});
light.flip(fadeline);
+
+ var lights = light.get_parent().get_lights();
if(x + 1 < tiles)
- light.get_parent().lights[x + 1][y].flip(fadeline);
+ lights[x + 1][y].flip(fadeline);
if(x - 1 >= 0)
- light.get_parent().lights[x - 1][y].flip(fadeline);
+ lights[x - 1][y].flip(fadeline);
if(y + 1 < tiles)
- light.get_parent().lights[x][y + 1].flip(fadeline);
+ lights[x][y + 1].flip(fadeline);
if(y - 1 >= 0)
- light.get_parent().lights[x][y - 1].flip(fadeline);
+ lights[x][y - 1].flip(fadeline);
fadeline.start();
in_fade = true;
@@ -145,21 +145,34 @@
return true;
}
-BoardType = {
+Board = new GType({
parent: Clutter.Group.type,
name: "Board",
- class_init: function(klass, prototype)
+ instance_init: function(klass)
{
- prototype.cleared = function ()
+ // Global
+ animating_board = false;
+ in_fade = false;
+
+ // Private
+ var lights = new Array();
+
+ // Public
+ this.get_lights = function ()
+ {
+ return lights;
+ }
+
+ this.cleared = function ()
{
- for(x in this.lights)
- for(y in this.lights[x])
- if(this.lights[x][y].get_state())
+ for(x in lights)
+ for(y in lights[x])
+ if(lights[x][y].get_state())
return false;
return true;
}
- prototype.randomize = function ()
+ this.randomize = function ()
{
in_setup = true;
@@ -167,52 +180,51 @@
do
{
- var count = Math.floor(Math.log(score.get_value()*score.get_value()) + 1);
- var sym = Math.floor(3*GLib.random_double());
+ var count = Math.floor(Math.log(score.get_value() *
+ score.get_value()) + 1);
+ var sym = Math.floor(3 * GLib.random_double());
for (q = 0; q < count; ++q)
{
- i = Math.round((tiles-1) * GLib.random_double());
- j = Math.round((tiles-1) * GLib.random_double());
+ i = Math.round((tiles - 1) * GLib.random_double());
+ j = Math.round((tiles - 1) * GLib.random_double());
- flip_region(null, null, this.lights[i][j]);
+ flip_region(null, null, lights[i][j]);
+
+ var x_sym_offset = Math.abs(i-(tiles-1));
+ var y_sym_offset = Math.abs(j-(tiles-1));
if(sym == 0)
- flip_region(null, null, this.lights[Math.abs(i-(tiles-1))][j]);
+ flip_region(null, null, lights[x_sym_offset][j]);
else if(sym == 1)
flip_region(null, null,
- this.lights[Math.abs(i-(tiles-1))][Math.abs(j-(tiles-1))]);
+ lights[x_sym_offset][y_sym_offset]);
else
- flip_region(null, null, this.lights[i][Math.abs(j-(tiles-1))]);
+ flip_region(null, null, lights[i][y_sym_offset]);
}
}
while(this.cleared());
in_setup = false;
}
- },
- instance_init: function(klass)
- {
- animating_board = false;
- in_fade = false;
-
- this.lights = new Array();
+ // Implementation
for(var x = 0; x < tiles; x++)
{
- this.lights[x] = new Array();
+ lights[x] = new Array();
for(var y = 0; y < tiles; y++)
{
- this.lights[x][y] = new Light();
- this.lights[x][y].light_x = x;
- this.lights[x][y].light_y = y;
- this.lights[x][y].set_position(x * (tile_size+margin) + margin + tile_size/2,
- y * (tile_size+margin) + margin + tile_size/2);
- this.add_actor(this.lights[x][y]);
+ var offset = margin + tile_size/2;
+ lights[x][y] = new Light();
+ lights[x][y].light_x = x;
+ lights[x][y].light_y = y;
+ lights[x][y].set_position(x * (tile_size+margin) + offset,
+ y * (tile_size+margin) + offset);
+ this.add_actor(lights[x][y]);
}
}
this.randomize();
- }};
-
-Board = new GType(BoardType);
+ }
+});
+
Modified: trunk/examples/lightsoff/main.js
==============================================================================
--- trunk/examples/lightsoff/main.js (original)
+++ trunk/examples/lightsoff/main.js Wed Dec 31 03:30:00 2008
@@ -57,10 +57,12 @@
rect.set_size(stage.width, stage.height);
back.set_arrow_direction(0);
-back.set_position(score.x - back.width - 2*margin, score.y + (.5 * score.height) - (.5 * back.height));
+back.set_position(score.x - back.width - 2*margin,
+ score.y + (.5 * score.height) - (.5 * back.height));
forward.set_arrow_direction(1);
-forward.set_position(score.x + score.width + 2*margin, score.y + (.5 * score.height) - (.5 * forward.height));
+forward.set_position(score.x + score.width + 2*margin,
+ score.y + (.5 * score.height) - (.5 * forward.height));
stage.add_actor(board);
stage.add_actor(rect);
Modified: trunk/examples/lightsoff/score.js
==============================================================================
--- trunk/examples/lightsoff/score.js (original)
+++ trunk/examples/lightsoff/score.js Wed Dec 31 03:30:00 2008
@@ -11,6 +11,7 @@
name: "Score",
instance_init: function(klass)
{
+ // Private
var value = 0;
var current_set = null;
@@ -23,6 +24,7 @@
var off_svg = Clutter.Texture.new_from_file("./lcd-off.svg");
off_svg.filter_quality = Clutter.TextureQuality.High;
+ // Public
this.get_value = function ()
{
return value;
@@ -59,6 +61,7 @@
bkg_top.raise_top();
};
+ // Implementation
this.add_actor(bkg);
for(var i = 0; i < 5; i++)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]