Package edu.ups.gamedev.weapons

Source Code of edu.ups.gamedev.weapons.DroppableFireable

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 DroppableFireable extends PhysicsFireable{
  static final long serialVersionUID = 1;

  @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, TankGame.GAMESTATE.getRoot());
  }

  @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 BasicPhysicsFireableController(this));
   
    final SyntheticButton detonator = getCollisionEventHandler();
    TankGame.GAMESTATE.getInput().addAction(new DetonationAction(), detonator, false);

    //Change numbers
    linearDragCoefficient = .0f;
   
    Vector3f cannonForce = vector.direction;
    cannonForce.x *= -3000;
    cannonForce.y *= -3000;
    cannonForce.z *= -3000;
   
    this.addForce(cannonForce);
    this.addForce(initialLinearVelocity);
   
  }
}
TOP

Related Classes of edu.ups.gamedev.weapons.DroppableFireable

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.