package edu.ups.gamedev.weapons;
import java.io.IOException;
import com.jme.bounding.BoundingBox;
import com.jme.math.Ray;
import com.jme.scene.Node;
import com.jme.scene.shape.Teapot;
import edu.ups.gamedev.game.TankGame;
import edu.ups.gamedev.net.NetworkConstants;
/**
* A rather silly <code>Warhead</code> which places a teapot at the point of detonation.
* @author stefan
*
*/
public class TeapotPlacingWarhead extends Warhead {
static final long serialVersionUID = 1;
@Override
public void detonate(Ray vector, Node node){
detonate(vector);
}
@Override
public void detonate(Ray vector) {
final Teapot teapot = new Teapot("killer teapot");
TankGame.GAME.lock();
TankGame.GAMESTATE.getRoot().attachChild(teapot);
teapot.updateRenderState();
teapot.setModelBound(new BoundingBox());
teapot.updateModelBound();
teapot.updateWorldBound();
teapot.setLocalTranslation(vector.origin);
TankGame.GAME.unlock();
//remove teapot after 5 seconds
new Thread() {
public void run() {
try {
Thread.sleep(5*1000);
} catch (InterruptedException e) {}
TankGame.NETWORK.unregister(teapot);
TankGame.GAME.lock();
teapot.removeFromParent();
TankGame.GAME.unlock();
}
}.start();
try {
TankGame.NETWORK.register(teapot, NetworkConstants.TEAPOT);
} catch (IOException e) {
System.out.println("Error while registering teapot");
e.printStackTrace();
}
}
}