package edu.ups.gamedev.weapons;
import com.jme.input.action.InputAction;
import com.jme.input.action.InputActionEvent;
import com.jme.scene.Node;
import com.jmex.physics.contact.ContactInfo;
import edu.ups.gamedev.game.TankGame;
import edu.ups.gamedev.game.Tools;
import edu.ups.gamedev.scene.Collidable;
public class DetonationAction extends InputAction {
private ContactInfo info;
public void performAction(InputActionEvent action) {
TankGame.GAME.lock();
info = (ContactInfo) action.getTriggerData();
handleFireable(info.getNode1(), info.getNode2());
handleFireable(info.getNode2(), info.getNode1());
TankGame.GAME.unlock();
}
private void handleFireable(Node node, Node other) {
Collidable parent = Tools.getCollidableParent(node);
if (parent instanceof Fireable) {
((Fireable) parent).detonate(other);
}
}
}