diff resources/pants.js @ 0:0b8d8ce99f46 default tip

commit
author Daiki KINJYO <e085722@ie.u-ryukyu.ac.jp>
date Mon, 14 Feb 2011 17:06:56 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/resources/pants.js	Mon Feb 14 17:06:56 2011 +0900
@@ -0,0 +1,51 @@
+pants_move = function(node, sgroot, w, h){
+
+	if(node.frame > 200){
+		node.dx = Math.sin(Math.random()*360) * 2;
+		node.dy = Math.sin(Math.random()*270) * 2;
+		node.dz = Math.sin(Math.random()*360) * 2;
+		node.frame = 0;
+	}
+
+	node.xyz[0] += node.dx;
+	node.xyz[2] += node.dz;
+	if(node.xyz[1] <= 0){
+		node.xyz[1] += node.dy;
+	}else{
+		node.xyz[1] = 0;
+	}
+
+	this.frame++;
+}
+
+
+pants_fall_move = function(node, sgroot, w, h){
+	var g = 0.098;
+	node.dx = 0;
+	node.dz = 0;
+	if(node.xyz[1] < 100){
+		node.dy += g;
+		node.xyz[0] += node.dx;
+		node.xyz[1] += node.dy;
+		node.xyz[2] += node.dz;
+	}
+}
+
+
+
+
+pants_collision = function(node, sgroot, w, h){
+	for(num in sg_exec_tree.child){
+		if(sg_exec_tree.child[num].id == "yellow"){
+			var bullet = sg_exec_tree.child[num];
+			var dx = node.xyz[0] - bullet.xyz[0];
+			var dy = node.xyz[1] - bullet.xyz[1];
+			var dz = node.xyz[2] - bullet.xyz[2];
+			var dxy = Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2) + Math.pow(dz,2));
+
+			if(dxy < 20){
+				node.set_move_collision(pants_fall_move, no_collision_idle);
+			}
+		}
+	}
+}