package com.mygdx.game.Character;

import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.Array;
import com.mygdx.game.Main;
import com.mygdx.game.Restrictions;

public class Player implements Restrictions {
    private static int x,y;
    private static String spriteName;
    public static TextureAtlas textureAtlas;
    private static Animation<TextureAtlas.AtlasRegion> animation;

    public static void create(int x, int y) {
        Player.x = x<<TILE_SHIFT;
        Player.y = y<<TILE_SHIFT;
        Main.cam.translate(Player.x, Player.y);

        spriteName = "man";
        textureAtlas = new TextureAtlas("core/assets/" + spriteName + ".atlas");
        Array<TextureAtlas.AtlasRegion> keyFrames = textureAtlas.findRegions(spriteName + "_Down");
        float frameDuration = 1 / 4f;
        animation = new Animation<>(frameDuration, keyFrames);
    }

    public static void teleport(int x, int y){
        Player.x = x<<TILE_SHIFT;
        Player.y = y<<TILE_SHIFT;
        Main.cam.translate(x,y);
    }

    public static void render(Batch batch, float timeSinceLastUpdate){
        batch.draw(getAnimation().getKeyFrame(timeSinceLastUpdate, true), getX(), getY(),TILE_SIZE,TILE_SIZE);
    }

    public static int getX() {
        return x;
    }

    public static int getY() {
        return y;
    }

    public static void addX(int x){
        Player.x += x;
    }

    public static void addY(int y){
        Player.y += y;
    }

    static String getSpriteName() {
        return spriteName;
    }

    public static Animation<TextureAtlas.AtlasRegion> getAnimation() {
        return animation;
    }

    static void setAnimation(Animation<TextureAtlas.AtlasRegion> animationTemp) {
        animation = animationTemp;
    }

}
