package com.darkdimension.ritle_run;

public class DiAnimation
{
    //Counter for frames
    private int[] counter = new int[2];
    private boolean positive = false;

    public DiAnimation(int frameTime)
    {
        //Count Frames
        counter[0] = frameTime;
        counter[1] = 0;
    }

    public boolean update()
    {
        //Positive Animation
        if (positive && counter[1] < counter[0])
        {
            //Advance Animation
            counter[1]++;

            //Return that animation is updated
            return true;
        }
        else
            //Negative Animation
            if (!positive && counter[1] > 0)
            {
                //Advance Animation
                counter[1]--;

                //Return that animation is updated
                return true;
            }

        //Return that animation is not updated
        return false;
    }

    //Commands
    public void startFromBeginning() {counter[1] = 0         ; positive = true ;}
    public void startFromEnd      () {counter[1] = counter[0]; positive = false;}
    public void start() {positive = !positive;}

    public void start(int frameTime)
    {
        //Count Frames
        counter[0] = frameTime;
        counter[1] = 0;

        //Start Animation
        positive = true;
    }

    //Isers
    public boolean isPositive() {return positive;}
    public boolean isAtStart()  {return counter[1] == 0 && !positive;}
    public boolean isAtEnd()    {return counter[1] == counter[0] &&  positive;}
    public boolean isRunning()
    {
        return
			counter[1] > 0 && !positive
         || counter[1] < counter[0] &&  positive;
    }

    //Getters
    public int getCounter() {return counter[1];}
    public int getMax()	 {return counter[0];}
    public int getDistance(int amount)
    {
        return amount *counter[1] /counter[0];
    }

    //Setters
    public void setMax    (int amount) {counter[0] = amount;}
    public void setCounter(int amount) {counter[1] = amount;}
}