view paper_shooting/resources/pants.js @ 25:158b846e3874

paper
author <e085737>
date Mon, 14 Feb 2011 16:37:16 +0900
parents
children
line wrap: on
line source

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);
			}
		}
	}
}


land_move = function(node, sgroot, w, h){
    var radian = Math.sin(node.time/90);
    node.xyz[1] = 100 * radian;
    if(node.frame > 10){
		var bullet_speed = 1;
		var bullet = new sgroot.createSceneGraph1("blue");
		bullet.xyz[0] = node.xyz[0] + 8;
		bullet.xyz[1] = node.xyz[1];
		bullet.xyz[2] = node.xyz[2];
		bullet.dx = -bullet_speed;
		bullet.dy = 0.0;
		bullet.dz = 0.0;
		bullet.scale = 0.3;
		bullet.set_move_collision(bullet_move2, no_collision_idle);
        node.frame = 0;
    }
}