package se.urmo.game.entities;

import lombok.Setter;

abstract public class BaseAnimated implements Animated {
    private final int animationSpeed;
    private final int maxSpriteFrames;
    @Setter
    protected boolean paused = true;
    private int aniTick = 0;
    protected int aniIndex = 0;

    protected BaseAnimated(int animationSpeed, int maxSpriteFrames) {
        this.animationSpeed = animationSpeed;
        this.maxSpriteFrames = maxSpriteFrames;
    }


    public void updateAnimationTick() {
        if (!paused) {
            aniTick++;
            if (aniTick >= animationSpeed) {
                aniTick = 0;
                aniIndex++;
                if (aniIndex >= maxSpriteFrames) {
                    aniIndex = 0;
                }
            }
        }
    }

    @Override
    public int getAnimationSpeed() {
        return animationSpeed;
    }

    @Override
    public boolean isPaused() {
        return paused;
    }
}
