Package framework.collision

Source Code of framework.collision.PointCollisionMask

package framework.collision;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Vector2f;

public class PointCollisionMask implements CollisionMask {
 
  private Vector2f relativeOrigin;
 
  public PointCollisionMask(Vector2f relativeOrigin){
    this.relativeOrigin = relativeOrigin;
  }
 
  public PointCollisionMask(){
    this(new Vector2f(0,0));
  }
 
  /**
   * @param relativeOrigin the relativeOrigin to set
   */
  public void setRelativeOrigin(Vector2f relativeOrigin) {
    this.relativeOrigin = relativeOrigin;
  }

  @Override
  public float getMaxWidth() {
    return 0;
  }

  @Override
  public float getMaxHeight() {
    return 0;
  }

  @Override
  public void rotate(float theta) {
    if(relativeOrigin != null && theta != 0){
      relativeOrigin.setTheta(relativeOrigin.getTheta() + theta);
    }
  }

  @Override
  public boolean isCollision(Vector2f thisOrigin, Vector2f otherOrigin, CollisionMask otherMask) {
    if(thisOrigin != null && otherOrigin != null && otherMask != null){
      if(relativeOrigin != null){
        thisOrigin.add(relativeOrigin);
      }
      if(otherMask instanceof PointCollisionMask){
        return thisOrigin.equals(otherOrigin);
      }else if(otherMask instanceof CircularCollisionMask){
        return otherMask.isCollision(otherOrigin,thisOrigin, this);
      }else if(otherMask instanceof LineCollisionMask){
        return otherMask.isCollision(otherOrigin, thisOrigin, this);
      }
    }
    return false;
  }

  @Override
  public Vector2f getRelativePositionOfOrigin() {
    return relativeOrigin;
  }

  @Override
  public void renderForDebug(Graphics g, Vector2f pos) {
    pos.add(relativeOrigin);
    g.drawOval(Math.round(pos.getX()), Math.round(pos.getY()), 1, 1);
  }
 
  @Override
  public void setRelativePositionOfOrigin(Vector2f newOrigin) {
    //TODO fill this in
  }
}
TOP

Related Classes of framework.collision.PointCollisionMask

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.