package de.frajul.endlessroll.entities.tools;

import de.frajul.endlessroll.data.Vector;
import de.frajul.endlessroll.entities.Player;
import de.frajul.endlessroll.entities.collision.geometry.Geometry;
import de.frajul.endlessroll.entities.collision.geometry.Quad;
import de.frajul.endlessroll.main.game.Timer;

/**
 * Created by Julian on 04.01.2016.
 */
public class Spring extends Tool {

    private boolean hasYetCollided = false;

    public Spring(Vector position) {
        super(ToolType.SPRING, position, .3f, .35f, true, true);
        animation.setIndexSequence(new int[]{1, 0, 0, 3, 3, 3, 1});
        animation.setRequiredDelta(80);
    }

    @Override
    public void update(Timer timer) {
        if (hasYetCollided)
            super.update(timer);
    }

    @Override
    public void onPlayerCollision(Player player, Timer timer) {
        if (!hasYetCollided) {
            hasYetCollided = true;

            player.clearAllForces();
            player.getMovement().setY(0);
            player.addForce(.0022f);
        }
    }

    @Override
    protected Geometry createWorldCollisionBounds() {
        return this;
    }

    @Override
    protected Geometry createPlayerCollisionBounds() {
        return new Quad(super.getPosition(), .2f, .1f);
    }
}
