<commit_before>package alfredo.sprite;

import alfredo.geom.Point;

/**
 * An Entity represents an object that has a position and a direction.
 * 
 * Entities are useful in that they can be parented to one another.
 * @author TheMonsterFromTheDeep
 */
public abstract class Entity implements Anchor {
    private Anchor parent;
    
    public Entity() {
        parent = new Empty();
    }
    
    public final Point getPosition() {
        return new Point(getX(), getY());
    }
    
    @Override
    public final double getDirection() {
        return parent.getDirection() + getLocalDirection();
    }
    
    @Override
    public final float getX() {
        return parent.getX() + getLocalX();
    }
    
    @Override
    public final float getY() {
        return parent.getY() + getLocalY();
    }
    
    public abstract float getLocalX();
    public abstract float getLocalY();
    public abstract double getLocalDirection();
    public abstract void setLocalX(float x);
    public abstract void setLocalY(float y);
    
    public void setParent(Anchor p, boolean retainPosition) {
        if(p != null) {
            if(retainPosition) {
                float newX = getX() - p.getX();
                float newY = getY() - p.getY();
                setLocalX(newX);
                setLocalY(newY);
            }
            parent = p;
        }
    }
    
    public void clearParent(boolean retainPosition) {
        if(retainPosition) {
            float newX = getX(), newY = getY();
            setLocalX(newX);
            setLocalY(newY);
        }
        parent = new Empty();
    }
}<commit_msg>Make rotation affect Entity parented movement<commit_after>package alfredo.sprite;

import alfredo.geom.Point;

/**
 * An Entity represents an object that has a position and a direction.
 * 
 * Entities are useful in that they can be parented to one another.
 * @author TheMonsterFromTheDeep
 */
public abstract class Entity implements Anchor {
    private Anchor parent;
    
    public Entity() {
        parent = new Empty();
    }
    
    public final Point getPosition() {
        return new Point(getX(), getY());
    }
    
    @Override
    public final double getDirection() {
        return parent.getDirection() + getLocalDirection();
    }
    
    @Override
    public final float getX() {
        return (float)(parent.getX() + Math.cos(Math.toRadians(parent.getDirection())) * getLocalY() + Math.cos(Math.toRadians(parent.getDirection() + 90)) * getLocalX());
    }
    
    @Override
    public final float getY() {
        return (float)(parent.getY() + Math.sin(Math.toRadians(parent.getDirection())) * getLocalY() + Math.sin(Math.toRadians(parent.getDirection() + 90)) * getLocalX());
    }
    
    public abstract float getLocalX();
    public abstract float getLocalY();
    public abstract double getLocalDirection();
    public abstract void setLocalX(float x);
    public abstract void setLocalY(float y);
    
    public void setParent(Anchor p, boolean retainPosition) {
        if(p != null) {
            if(retainPosition) {
                float newX = getX() - p.getX();
                float newY = getY() - p.getY();
                setLocalX(newX);
                setLocalY(newY);
            }
            parent = p;
        }
    }
    
    public void clearParent(boolean retainPosition) {
        if(retainPosition) {
            float newX = getX(), newY = getY();
            setLocalX(newX);
            setLocalY(newY);
        }
        parent = new Empty();
    }
}