function Missile(weapon) {
	THREE.Object3D.call(this);
	this.weapon = weapon;
	this.speed = 0;
	this.range = 0;
	this.target = null;
	var geometry = new THREE.CubeGeometry(2.0, 1.0, 1.0);
	var material = new THREE.MeshBasicMaterial({ color: 0x555555 });
	this.mesh = new THREE.Mesh(geometry, material);
	this.add(this.mesh);
}
Missile.prototype = Object.create(THREE.Object3D.prototype);

Missile.prototype.update = function(dt) {
	if (this.target) {
		// TODO: Home to the target
	}
	var angle = this.rotation.z;
	var dpos = this.speed * dt;
	this.position.x += Math.cos(angle) * dpos;
	this.position.y += Math.sin(angle) * dpos;
	this.range -= dpos;
	// TODO: Check for collisions

	if (this.range <= 0) {
		// TODO: Remove object
	}
};


function Weapon(name, params) {
	this.name = name;
	this.range = params.range;
	this.damage = params.damage;
	this.ammo = params.ammo;
	this.maxAmmo = params.ammo;
	this.radius = params.radius || 1;
	this.delay = params.delay || 0.1;
	this.speed = params.speed || 150;
	this.guided  = params.guided || false;
	this.bullets = [];
	this.lastTime = 0;
}

Weapon.prototype.shoot = function(shooter) {
	if (this.ammo <= 0) return;
	var t = Date.now() * 0.001;
	if (t < this.lastTime + this.delay) return;
	this.lastTime = t;
	--this.ammo;
	var bullet = new Missile(this);
	bullet.position.copy(shooter.position);
	bullet.rotation.copy(shooter.rotation);
	bullet.range = this.range;
	bullet.speed = this.speed + shooter.speed;
	if (this.guided) bullet.target = shooter.target;
	this.bullets.push(bullet);
	scene.add(bullet);
};

Weapon.prototype.update = function(dt) {
	for (var i = 0, l = this.bullets.length; i < l; ++i)
		this.bullets[i].update(dt);
};

@@ -681,60 +681,8 @@
 ns%0A%0A
-%09if (this.range %3C= 0) %7B%0A%09%09// TODO: Remove object%0A%09%7D%0A
 %7D;%0A%0A
@@ -1563,15 +1563,8 @@
  i =
- 0, l =
  thi
@@ -1583,24 +1583,42 @@
 ngth
+-1
 ; i 
-%3C l; ++i)%0A%09%09
+%3E= 0; --i) %7B%0A%09%09var bullet = 
 this
@@ -1628,16 +1628,26 @@
 llets%5Bi%5D
+;%0A%09%09bullet
 .update(
@@ -1647,15 +1647,139 @@
 update(dt);%0A
+%09%09// Remove the bullet if it's dead%0A%09%09if (bullet.range %3C= 0) %7B%0A%09%09%09scene.remove(bullet)%0A%09%09%09this.bullets.splice(i, 1);%0A%09%09%7D%0A%09%7D%0A
 %7D;%0A

Remove bullets that have used their range.