seed r243 - in trunk/examples/lightsoff: . legacy



Author: hortont
Date: Tue Nov 11 10:59:05 2008
New Revision: 243
URL: http://svn.gnome.org/viewvc/seed?rev=243&view=rev

Log:
Beginnings of a Clutter rewrite of Lights Off.


Added:
   trunk/examples/lightsoff/board.js
   trunk/examples/lightsoff/legacy/
   trunk/examples/lightsoff/legacy/lightsoff.js   (props changed)
      - copied unchanged from r242, /trunk/examples/lightsoff/lightsoff.js
   trunk/examples/lightsoff/light.js
   trunk/examples/lightsoff/main.js   (contents, props changed)
Removed:
   trunk/examples/lightsoff/lightsoff.js

Added: trunk/examples/lightsoff/board.js
==============================================================================
--- (empty file)
+++ trunk/examples/lightsoff/board.js	Tue Nov 11 10:59:05 2008
@@ -0,0 +1,33 @@
+BoardType = {
+    parent: Clutter.Group.type,
+    name: "Board",
+    class_init: function(klass, prototype)
+    {
+		prototype.cleared = function ()
+		{
+			for(x in this.lights)
+				for(y in this.lights[x])
+					if(!this.lights[x][y].state)
+						return false;
+			return true;
+		}
+    },
+    instance_init: function(klass)
+    {
+		this.lights = new Array();
+
+		for(var x = 0; x < tiles; x++)
+		{
+			this.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 * 55 + 5, y * 55 + 5);
+				this.add_actor(this.lights[x][y]);
+			}
+		}
+    }};
+
+Board = new GType(BoardType);

Added: trunk/examples/lightsoff/light.js
==============================================================================
--- (empty file)
+++ trunk/examples/lightsoff/light.js	Tue Nov 11 10:59:05 2008
@@ -0,0 +1,48 @@
+LightType = {
+    parent: Clutter.Group.type,
+    name: "Light",
+    class_init: function(klass, prototype)
+    {
+		prototype.flip = function ()
+		{
+			this.state = !this.state;
+			
+			if(in_setup)
+			{
+				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();
+
+			return true;
+		}
+    },
+    instance_init: function(klass)
+    {
+    	this.state = 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.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);
+    }};
+
+Light = new GType(LightType);

Added: trunk/examples/lightsoff/main.js
==============================================================================
--- (empty file)
+++ trunk/examples/lightsoff/main.js	Tue Nov 11 10:59:05 2008
@@ -0,0 +1,92 @@
+#!/usr/bin/env seed
+
+// images are 50x50
+
+var tiles = 5;
+var in_setup = false;
+
+Seed.import_namespace("Clutter");
+
+Clutter.init(null, null);
+
+Seed.include("light.js");
+Seed.include("board.js");
+
+flip_region = function (act, evt, light)
+{
+	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;
+}
+
+function random_clicks()
+{
+	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();
+}
+
+function win_animation()
+{
+	
+}
+
+var on_svg = Clutter.Texture.new_from_file("./tim-on.svg");
+var off_svg = Clutter.Texture.new_from_file("./tim-off.svg");
+
+var black = Clutter.Color._new();
+Clutter.color_parse("Black", black);
+
+var stage = new Clutter.Stage({color: black});
+stage.signal.hide.connect(Clutter.main_quit);
+stage.set_size(55 * tiles + 5, 55 * tiles + 5);
+
+board = new Board();
+
+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]