package nl.joozey.games.asmallworld;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;

/**
 * Created by mint on 23-4-17.
 */

public class DrillBearSprite {

    private Texture[] drill1Tex;

    private Texture drillbearTex;

    private Sprite drillBearSprite;
    private Sprite itemInHandSprite;
    private Texture[] itemInHandAnim;

    private float animFrame;
    private boolean drilling;

    public DrillBearSprite() {
        drillbearTex = new Texture("drillbear.png");
        drillBearSprite = new Sprite(drillbearTex);

        drill1Tex = new Texture[2];
        drill1Tex[0] = new Texture("drill1a.png");
        drill1Tex[1] = new Texture("drill1b.png");

        itemInHandSprite = new Sprite(drill1Tex[0]);
        itemInHandAnim = drill1Tex;
    }

    public void draw(Batch batch) {
        drillBearSprite.draw(batch);

        animFrame += Gdx.graphics.getDeltaTime() * (5f + (drilling ? 15f : 0f));
        itemInHandSprite.setTexture(itemInHandAnim[(int)animFrame % itemInHandAnim.length]);
        itemInHandSprite.setPosition(drillBearSprite.getX(), drillBearSprite.getY());
        itemInHandSprite.draw(batch);
    }

    public void dispose() {
        drillbearTex.dispose();
    }

    public Sprite getSprite() {
        return drillBearSprite;
    }

    public void drill(boolean drill) {
        drilling = drill;
    }
}
