seed r837 - trunk/examples/same-seed
- From: hortont svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r837 - trunk/examples/same-seed
- Date: Tue, 3 Feb 2009 15:14:20 +0000 (UTC)
Author: hortont
Date: Tue Feb 3 15:14:20 2009
New Revision: 837
URL: http://svn.gnome.org/viewvc/seed?rev=837&view=rev
Log:
Lots and lots of Same Seed updates.
Modified:
trunk/examples/same-seed/blue.svg
trunk/examples/same-seed/board.js
trunk/examples/same-seed/green.svg
trunk/examples/same-seed/light.js
trunk/examples/same-seed/main.js
trunk/examples/same-seed/red.svg
trunk/examples/same-seed/yellow.svg
Modified: trunk/examples/same-seed/blue.svg
==============================================================================
--- trunk/examples/same-seed/blue.svg (original)
+++ trunk/examples/same-seed/blue.svg Tue Feb 3 15:14:20 2009
@@ -9,8 +9,8 @@
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
- width="150.57143"
- height="150.57143"
+ width="50"
+ height="50"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.46"
@@ -46,7 +46,7 @@
x2="315.28571"
y2="344.79077"
gradientUnits="userSpaceOnUse"
- gradientTransform="matrix(0.9445351,0,0,0.9445351,13.311582,14.948077)" />
+ gradientTransform="matrix(0.3187856,0,0,0.3187856,113.20576,133.30501)" />
</defs>
<sodipodi:namedview
id="base"
@@ -59,8 +59,8 @@
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="4.0711576"
- inkscape:cx="75.285713"
- inkscape:cy="80.411518"
+ inkscape:cx="44.4591"
+ inkscape:cy="80.411519"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
@@ -85,13 +85,13 @@
id="layer1"
transform="translate(-164.71428,-194.21933)">
<rect
- style="opacity:1;fill:url(#linearGradient3193);fill-opacity:1;stroke:#729fcf;stroke-width:1.88907015;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ style="opacity:1;fill:url(#linearGradient3193);fill-opacity:1;stroke:#729fcf;stroke-width:0.63757122;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect3157"
- width="140.33092"
- height="140.33092"
- x="169.83453"
- y="199.33958"
- rx="9.4453506"
- ry="9.4453506" />
+ width="47.362427"
+ height="47.362431"
+ x="166.03307"
+ y="195.53812"
+ rx="3.187856"
+ ry="3.187856" />
</g>
</svg>
Modified: trunk/examples/same-seed/board.js
==============================================================================
--- trunk/examples/same-seed/board.js (original)
+++ trunk/examples/same-seed/board.js Tue Feb 3 15:14:20 2009
@@ -1,36 +1,31 @@
-function delete_board(timeline, board)
-{
- board.destroy();
-
- return true;
-}
-
Board = new GType({
parent: Clutter.Group.type,
name: "Board",
init: function(klass)
{
- // Global
-
-
// Private
- var lights = new Array();
- var all_lights = new Array();
- var cl, oldpicked;
+ var lights = [], all_lights = [];
+ var cl, oldcl = [ ], oldpicked;
var animating = false;
function done_animating()
{
animating = false;
+ Seed.print("asdf");
+
+ var x = new Object(), y = new Object();
+ window.window.get_pointer(x, y, null);
+
+ var picked = stage.get_actor_at_pos(x.value, y.value).get_parent();
+
+ light_lights_from(picked);
+
return false;
}
- function _light_connected_lights(li)
+ function _connected_lights(li)
{
- // Anything anyone can do to make this function faster
- // will make the game snappier.
-
if(!li || li.visited || li.get_closed())
return [ ];
@@ -41,63 +36,60 @@
var con = [li];
- //while(GLib.main_context_pending())
- // GLib.main_context_iteration();
-
- // Do all of the concatenation together for performance
+ while(GLib.main_context_pending())
+ GLib.main_context_iteration();
var a = [], b = [], c = [], d = [];
if(lights[x][y+1] && (li.get_state() == lights[x][y+1].get_state()))
- a = _light_connected_lights(lights[x][y+1]);
+ a = _connected_lights(lights[x][y+1]);
if(lights[x][y-1] && (li.get_state() == lights[x][y-1].get_state()))
- b = _light_connected_lights(lights[x][y-1]);
+ b = _connected_lights(lights[x][y-1]);
- if(lights[x+1] && (li.get_state() == lights[x+1][y].get_state()))
- c = _light_connected_lights(lights[x+1][y]);
-
- if(lights[x-1] && (li.get_state() == lights[x-1][y].get_state()))
- d = _light_connected_lights(lights[x-1][y]);
+ if(lights[x+1] && lights[x+1][y] &&
+ (li.get_state() == lights[x+1][y].get_state()))
+ c = _connected_lights(lights[x+1][y]);
+
+ if(lights[x-1] && lights[x-1][y] &&
+ (li.get_state() == lights[x-1][y].get_state()))
+ d = _connected_lights(lights[x-1][y]);
return con.concat(a,b,c,d);
};
- function light_connected_lights(li)
+ function connected_lights(li)
{
for(var i in all_lights)
- {
all_lights[i].visited = false;
- }
if(!li.get_light_x) // We're picking something other than a light!
return [ li ];
- return _light_connected_lights(li);
+ return _connected_lights(li);
};
function any_connected_lights(li)
{
- if(!li)
+ if(!li || li.get_closed())
return false;
var x = li.get_light_x();
var y = li.get_light_y();
- if(li.get_closed())
- return false;
-
if(lights[x][y+1] && (li.get_state() == lights[x][y+1].get_state()))
- return true;
+ return !lights[x][y+1].get_closed();
if(lights[x][y-1] && (li.get_state() == lights[x][y-1].get_state()))
- return true;
+ return !lights[x][y-1].get_closed();
- if(lights[x+1] && (li.get_state() == lights[x+1][y].get_state()))
- return true;
-
- if(lights[x-1] && (li.get_state() == lights[x-1][y].get_state()))
- return true;
+ 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;
};
@@ -110,34 +102,62 @@
return (n_lights - 2) * (n_lights - 2);
};
- var mouse_moved = function (actor, event)
+ function light_lights_from(li)
{
- if(animating)
- return false;
+ cl = connected_lights(li);
- var picked = stage.get_actor_at_pos(event.motion.x,
- event.motion.y).get_parent();
+ for(var i in oldcl)
+ oldcl[i].opacity = 180;
- if(picked == oldpicked)
+ if(cl.length < 2)
return false;
- else
- oldpicked = picked;
- cl = light_connected_lights(picked);
+ for(var i in cl)
+ cl[i].opacity = 255;
- for(var i in all_lights)
+ oldcl = cl;
+ };
+
+ function update_score(tiles)
+ {
+ var points_awarded = calculate_score(tiles);
+
+ if(fly_score)
{
- if(!all_lights[i].get_closed())
- all_lights[i].opacity = 180;
+ var score_text = new Score();
+ score_text.animate_score(points_awarded);
}
- if(cl.length < 2)
- return false;
+ score += points_awarded;
- for(var i in cl)
+ Seed.print(score);
+
+ if(board.has_completed())
{
- cl[i].opacity = 255;
+ if(board.has_won())
+ score += 1000;
+
+ var score_text = new Score();
+ score_text.animate_final_score(score);
+
+ Seed.print("Done with: " + score + " points!");
}
+ }
+
+ var enter_tile = function (actor, event)
+ {
+ if(animating)
+ return false;
+
+ var picked = stage.get_actor_at_pos(event.motion.x,
+ event.motion.y).get_parent();
+
+ if(picked == oldpicked)
+ return false;
+
+ oldpicked = picked;
+
+ light_lights_from(picked);
return false;
};
@@ -149,8 +169,6 @@
{
li = all_lights[i];
- // For some reason, any_connected_lights isn't always right...
-
if(!li.get_closed() && any_connected_lights(li))
return false;
}
@@ -178,15 +196,19 @@
this.remove_region = function (actor, event)
{
+ if(animating)
+ return false;
+
+ if(!cl)
+ light_lights_from(actor.get_parent());
+
if(cl.length < 2)
return false;
for(var i in cl)
- {
cl[i].close_tile();
- }
- var real_x = 0;
+ var real_x = 0, timeline = 0;
for(var x in lights)
{
@@ -214,39 +236,15 @@
li.set_light_x(real_x);
li.set_light_y(parseInt(y,10));
- if(li.get_closed() && !li.on.anim)
- {
- Seed.print("hiding");
- li.on.anim = li.on.animate(Clutter.AnimationMode.LINEAR,500,
- {
- height: [GObject.TYPE_INT, tile_size * 2],
- width: [GObject.TYPE_INT, tile_size * 2],
- x: [GObject.TYPE_INT, -tile_size/2],
- y: [GObject.TYPE_INT, -tile_size/2]
- });
- li.on.anim.timeline.start();
-
- li.on.anim.timeline.signal.completed.connect(li.hide_light, li);
-
- li.anim = li.animate(Clutter.AnimationMode.LINEAR,500,
- {
- opacity: [GObject.TYPE_UCHAR, 0]
- });
- li.anim.timeline.start();
- }
- else if(((real_x * tile_size + offset) != li.x) ||
- (((tiles_h - y - 1) * tile_size + offset) != li.y))
+ var new_x = real_x * tile_size + offset;
+ var new_y = (tiles_h - y - 1) * tile_size + offset;
+
+ if(!li.get_closed() && ((new_x != li.x) ||
+ (new_y != li.y)))
{
animating = true;
- li.anim = li.animate(Clutter.AnimationMode.EASE_OUT_BOUNCE, 500,
- {
- x: [GObject.TYPE_INT, real_x * tile_size + offset],
- y: [GObject.TYPE_INT, (tiles_h - y - 1) * tile_size + offset]
- });
- li.anim.timeline.start();
-
- li.anim.timeline.signal.completed.connect(done_animating);
+ timeline = li.animate_to(new_x, new_y);
}
if(!li.get_closed())
@@ -257,20 +255,15 @@
real_x++;
}
+ if(timeline)
+ timeline.signal.completed.connect(done_animating);
+
for(;real_x < tiles_w; real_x++)
lights[real_x] = null;
- score += calculate_score(cl.length);
+ update_score(cl.length);
- Seed.print(score);
-
- if(board.has_completed())
- {
- if(board.has_won())
- score += 1000;
-
- Seed.print("Done with: " + score + " points!");
- }
+ cl = oldpicked = null;
return false;
}
@@ -281,7 +274,6 @@
lights[x] = new Array();
for(var y = 0; y < tiles_h; y++)
{
- var offset = tile_size/2;
var li = new Light();
li.set_light_x(x);
@@ -297,7 +289,7 @@
}
}
- this.signal.motion_event.connect(mouse_moved);
+ this.signal.enter_event.connect(enter_tile);
this.reactive = true;
}
});
Modified: trunk/examples/same-seed/green.svg
==============================================================================
--- trunk/examples/same-seed/green.svg (original)
+++ trunk/examples/same-seed/green.svg Tue Feb 3 15:14:20 2009
@@ -9,8 +9,8 @@
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
- width="150.57143"
- height="150.57143"
+ width="50"
+ height="50"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.46"
@@ -46,7 +46,7 @@
x2="315.28571"
y2="344.79077"
gradientUnits="userSpaceOnUse"
- gradientTransform="matrix(0.9445351,0,0,0.9445351,13.311582,14.948077)" />
+ gradientTransform="matrix(0.3187856,0,0,0.3187856,113.20576,133.30501)" />
</defs>
<sodipodi:namedview
id="base"
@@ -58,9 +58,9 @@
objecttolerance="10"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
- inkscape:zoom="4.0711576"
- inkscape:cx="32.054766"
- inkscape:cy="80.288704"
+ inkscape:zoom="4.310224"
+ inkscape:cx="46.168896"
+ inkscape:cy="75.285713"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
@@ -85,13 +85,13 @@
id="layer1"
transform="translate(-164.71428,-194.21933)">
<rect
- style="opacity:1;fill:url(#linearGradient3193);fill-opacity:1;stroke:#8ae234;stroke-width:1.88907015000000000;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ style="opacity:1;fill:url(#linearGradient3193);fill-opacity:1;stroke:#8ae234;stroke-width:0.63757122;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect3157"
- width="140.33092"
- height="140.33092"
- x="169.83453"
- y="199.33958"
- rx="9.4453506"
- ry="9.4453506" />
+ width="47.362427"
+ height="47.362431"
+ x="166.03307"
+ y="195.53812"
+ rx="3.187856"
+ ry="3.187856" />
</g>
</svg>
Modified: trunk/examples/same-seed/light.js
==============================================================================
--- trunk/examples/same-seed/light.js (original)
+++ trunk/examples/same-seed/light.js Tue Feb 3 15:14:20 2009
@@ -2,18 +2,13 @@
function load_svg(file)
{
- var pb = new GdkPixbuf.Pixbuf.from_file_at_size(file, tile_svg_size,
- tile_svg_size);
- var tx = GtkClutter.texture_new_from_pixbuf(pb);
+ var tx = new Clutter.Texture({filename: file});
tx.filter_quality = Clutter.TextureQuality.HIGH;
-
- stage.add_actor(tx);
- tx.x = tx.y = -2000;
-
return tx;
}
-var colors;
+var colors = [load_svg("blue.svg"), load_svg("green.svg"),
+ load_svg("red.svg"), load_svg("yellow.svg")];
Light = new GType({
parent: Clutter.Group.type,
@@ -23,7 +18,7 @@
// Private
var closed = false;
var light_x, light_y;
- var state = Math.floor(Math.random() * colors.length);
+ var state = Math.floor(Math.random() * max_colors);
// Public
this.visited = false;
@@ -36,6 +31,39 @@
return state;
}
+ this.animate_out = function ()
+ {
+ this.on.anim = this.on.animate(Clutter.AnimationMode.LINEAR,500,
+ {
+ height: [GObject.TYPE_INT, tile_size * 2],
+ width: [GObject.TYPE_INT, tile_size * 2],
+ x: [GObject.TYPE_INT, -tile_size/2],
+ y: [GObject.TYPE_INT, -tile_size/2]
+ });
+ this.on.anim.timeline.start();
+
+ this.on.anim.timeline.signal.completed.connect(this.hide_light, this);
+
+ this.anim = this.animate(Clutter.AnimationMode.LINEAR,500,
+ {
+ opacity: [GObject.TYPE_UCHAR, 0]
+ });
+
+ this.anim.timeline.start();
+ }
+
+ this.animate_to = function (new_x, new_y)
+ {
+ this.anim = this.animate(Clutter.AnimationMode.EASE_OUT_BOUNCE, 500,
+ {
+ x: [GObject.TYPE_INT, new_x],
+ y: [GObject.TYPE_INT, new_y]
+ });
+ this.anim.timeline.start();
+
+ return this.anim.timeline;
+ }
+
this.get_closed = function ()
{
return closed;
@@ -44,6 +72,7 @@
this.close_tile = function ()
{
closed = true;
+ this.animate_out();
}
this.hide_light = function (timeline, light)
@@ -52,6 +81,9 @@
delete on;
+ if(light.anim)
+ delete light.anim;
+
return false;
}
Modified: trunk/examples/same-seed/main.js
==============================================================================
--- trunk/examples/same-seed/main.js (original)
+++ trunk/examples/same-seed/main.js Tue Feb 3 15:14:20 2009
@@ -1,45 +1,54 @@
#!/usr/bin/env seed
+// Configuration
+
var tiles_w = 15;
var tiles_h = 10;
var tile_size = 50;
+var offset = tile_size/2;
+
+var max_colors = 4;
+var fly_score = true;
-// Configuration
Seed.import_namespace("Gtk");
Seed.import_namespace("Clutter", "0.9");
Seed.import_namespace("GtkClutter", "0.9");
Seed.import_namespace("GdkPixbuf");
Seed.import_namespace("GConf");
Seed.import_namespace("GLib");
+Seed.import_namespace("Pango");
-Clutter.init(null, null);
+GtkClutter.init(null, null);
GConf.init(null, null);
Seed.include("light.js");
Seed.include("board.js");
+Seed.include("score.js");
var score = 0;
var timelines = [];
-var black = new Clutter.Color();
-Clutter.color_parse("Black", black);
+var window = new Gtk.Window();
+var clutter = new GtkClutter.Embed();
+var stage = clutter.get_stage();
+var vbox = new Gtk.VBox();
-Clutter.set_motion_events_frequency(10);
-
-var stage = new Clutter.Stage();
+window.signal.hide.connect(function () { Gtk.main_quit(); });
stage.title = "Same Seed";
-stage.signal.hide.connect(function () { Clutter.main_quit(); });
-stage.color = black;
+stage.color = {alpha: 0};
stage.set_size((tiles_w * tile_size),(tiles_h * tile_size));
-colors = [load_svg("blue.svg"), load_svg("green.svg"),
- load_svg("red.svg"), load_svg("yellow.svg")]
-
board = new Board();
stage.add_actor(board);
stage.show_all();
-Clutter.main();
+clutter.set_size_request(stage.width, stage.height);
+vbox.pack_start(clutter, true, true);
+
+window.add(vbox);
+window.show_all();
+
+Gtk.main();
Modified: trunk/examples/same-seed/red.svg
==============================================================================
--- trunk/examples/same-seed/red.svg (original)
+++ trunk/examples/same-seed/red.svg Tue Feb 3 15:14:20 2009
@@ -9,8 +9,8 @@
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
- width="150.57143"
- height="150.57143"
+ width="50"
+ height="50"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.46"
@@ -46,7 +46,7 @@
x2="315.28571"
y2="344.79077"
gradientUnits="userSpaceOnUse"
- gradientTransform="matrix(0.9445351,0,0,0.9445351,13.311582,14.948077)" />
+ gradientTransform="matrix(0.3187856,0,0,0.3187856,113.20576,133.30501)" />
</defs>
<sodipodi:namedview
id="base"
@@ -58,9 +58,9 @@
objecttolerance="10"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
- inkscape:zoom="4.0711576"
- inkscape:cx="32.054766"
- inkscape:cy="80.288704"
+ inkscape:zoom="12.26"
+ inkscape:cx="14.763458"
+ inkscape:cy="25"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
@@ -85,13 +85,13 @@
id="layer1"
transform="translate(-164.71428,-194.21933)">
<rect
- style="opacity:1;fill:url(#linearGradient3193);fill-opacity:1;stroke:#fcaf3e;stroke-width:1.88907015000000000;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ style="opacity:1;fill:url(#linearGradient3193);fill-opacity:1;stroke:#fcaf3e;stroke-width:0.63757122;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect3157"
- width="140.33092"
- height="140.33092"
- x="169.83453"
- y="199.33958"
- rx="9.4453506"
- ry="9.4453506" />
+ width="47.362427"
+ height="47.362431"
+ x="166.03307"
+ y="195.53812"
+ rx="3.187856"
+ ry="3.187856" />
</g>
</svg>
Modified: trunk/examples/same-seed/yellow.svg
==============================================================================
--- trunk/examples/same-seed/yellow.svg (original)
+++ trunk/examples/same-seed/yellow.svg Tue Feb 3 15:14:20 2009
@@ -9,8 +9,8 @@
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
- width="150.57143"
- height="150.57143"
+ width="50"
+ height="50"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.46"
@@ -46,7 +46,7 @@
x2="315.28571"
y2="344.79077"
gradientUnits="userSpaceOnUse"
- gradientTransform="matrix(0.9445351,0,0,0.9445351,13.311582,14.948077)" />
+ gradientTransform="matrix(0.3187856,0,0,0.3187856,113.20576,133.30501)" />
</defs>
<sodipodi:namedview
id="base"
@@ -58,9 +58,9 @@
objecttolerance="10"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
- inkscape:zoom="4.0711576"
- inkscape:cx="32.054766"
- inkscape:cy="80.288704"
+ inkscape:zoom="1.5325"
+ inkscape:cx="-12.236982"
+ inkscape:cy="-5.5115365"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
@@ -85,13 +85,13 @@
id="layer1"
transform="translate(-164.71428,-194.21933)">
<rect
- style="opacity:1;fill:url(#linearGradient3193);fill-opacity:1;stroke:#fce94f;stroke-width:1.88907015000000000;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ style="opacity:1;fill:url(#linearGradient3193);fill-opacity:1;stroke:#fce94f;stroke-width:0.63757122;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect3157"
- width="140.33092"
- height="140.33092"
- x="169.83453"
- y="199.33958"
- rx="9.4453506"
- ry="9.4453506" />
+ width="47.362427"
+ height="47.362431"
+ x="166.03307"
+ y="195.53812"
+ rx="3.187856"
+ ry="3.187856" />
</g>
</svg>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]