package edu.ups.gamedev.weapons;
import com.jme.input.util.SyntheticButton;
import com.jme.math.Ray;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jmex.physics.material.Material;
import edu.ups.gamedev.game.TankGame;
import edu.ups.gamedev.scene.Collidable;
public class MissileFireable extends PhysicsFireable {
static final long serialVersionUID = 1;
// objects
Vector3f burnStrength = new Vector3f(0, 0, 0);
// parameters
protected float motorBurnTime = 0;
protected float motorStrength = 0;
@Override
public boolean canCollideWith(Collidable object) {
// TODO handle canCollideWith
return true;
}
@Override
public void onDetonate(Node other) {
Vector3f dummy = new Vector3f();
Vector3f direction = new Vector3f();
getWorldRotation().toAxes(new Vector3f[] {dummy, dummy, direction});
Ray ray = new Ray(getWorldTranslation(), direction);
warhead.detonate(ray, other);
}
@Override
public void onFire(Ray vector, Vector3f initialLinearVelocity, Node rootNode) {
final Box model = new Box("missile", new Vector3f(0, 0, 0), 1f, 1f, 4f);
// attach the chain:
// rootNode -> MissileFireable -> Geometry
attachChild(model);
// generate physics geom
generatePhysicsGeometry();
rootNode.attachChild(this);
getLocalTranslation().set(vector.getOrigin());
getLocalRotation().lookAt(vector.getDirection(),
TankGame.GAMESTATE.UP);
model.updateRenderState();
setMaterial(Material.IRON);
addController(new MissileFireableController(this));
final SyntheticButton detonator = getCollisionEventHandler();
TankGame.GAMESTATE.getInput().addAction(new DetonationAction(), detonator, false);
// TODO unhack parameters
motorBurnTime = 2f;
motorStrength = 5000000f;
setMass(10000f);
addForce(initialLinearVelocity);
}
/**
* Set this MissileFireable's motor burn time
*
* @param time
* motor burn time in seconds
*/
public void setMotorBurnTime(float time) {
motorBurnTime = time;
}
}