Package Global_Package

Source Code of Global_Package.MovableEntity

package Global_Package;

import java.awt.geom.Point2D;

import physics.NoDirectionException;
import physics.Vector2D;
import Server.GameState;

public abstract class MovableEntity extends Entity{
 
 
  public MovableEntity(int ID,int OwnerID ,int type,double mass) {
    super(ID,OwnerID, type);
    this.mass=mass;
    v=new Vector2D();
    a=new Vector2D();
    // TODO Auto-generated constructor stub
  }

 
  public Point2D getLoc() {
    return loc;
  }
 
  public Point2D getOldLoc() {
    return oldLoc;
  }
  public void setOldLoc(Point2D p) {
    oldLoc=p;
  }
 
  public boolean checkType(int in) {
    if(type==in)
      return true;
    else
      return false;
  }
 
  /** units/tick */
  protected Vector2D v;
  /**
   * units/tick <br>
   */
  protected Vector2D a;
  /**
   * Degree's from horizontal
   */
  protected double theta;
  /**
   * Set theta though the use of 2  points
   *
   */
  public int getType() {
    return type;
  }

  protected final double mass;

 
  public void setTheta(){
    try {
      theta = new Vector2D(oldLoc,loc).direction();
    } catch (NoDirectionException e) {
      theta=0;
    }
  }
  public void setLoc(Point2D p) {
    loc=p;
  }
  public double getTheta(){
    return theta;
  }
  /** kilograms */
 

  /**
   * Performs one tick of physics calculations.
   *
   * @param g
   *            the {@link GameState}
   * @return <code>true</code> if the entity collided with something
   *
   * */
 
  public void tick(GameState g){
    if (oldLoc==null){
      oldLoc=new Point2D.Double();
    }
    oldLoc.setLocation(loc);
    v.translate(loc, 1D);
    a.translate(v, 1D);
    a.set(0,0);
  }
 
  public void apply(Vector2D force){
    Vector2D a_=new Vector2D();
    a_.scale(1.0/mass,force);
    a.add(a_);
  }
 
}
TOP

Related Classes of Global_Package.MovableEntity

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.