package com.mygdx.game.Character;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.mygdx.game.Restrictions;

import static com.mygdx.game.Main.cam;

public class InputController implements Restrictions {

    int i = 0;


    public void handleInput() {
        i++;

        if (Gdx.input.isKeyPressed(Input.Keys.A)) {
            cam.zoom += 5;
        }
        if (Gdx.input.isKeyPressed(Input.Keys.Q)) {
            cam.zoom -= 5;
        }

        if (Gdx.input.isKeyPressed(Input.Keys.UP) && Gdx.input.isKeyPressed(Input.Keys.LEFT) && i > KEY_DELAY) {
            i = 0;
            directionAnimation("UpLeft");
            Player.addX(-MOVEMENT_SPEED);
            Player.addY(MOVEMENT_SPEED);
            cam.translate(-MOVEMENT_SPEED,MOVEMENT_SPEED);
        }
        else if (Gdx.input.isKeyPressed(Input.Keys.UP)&& Gdx.input.isKeyPressed(Input.Keys.RIGHT) &&i > KEY_DELAY) {
            i = 0;
            directionAnimation("UpRight");
            Player.addX(MOVEMENT_SPEED);
            Player.addY(MOVEMENT_SPEED);
            cam.translate(MOVEMENT_SPEED,MOVEMENT_SPEED);
        }
        else if (Gdx.input.isKeyPressed(Input.Keys.DOWN)&& Gdx.input.isKeyPressed(Input.Keys.LEFT) && i > KEY_DELAY) {
            i = 0;
            directionAnimation("DownLeft");
            Player.addX(-MOVEMENT_SPEED);
            Player.addY(-MOVEMENT_SPEED);
            cam.translate(-MOVEMENT_SPEED,-MOVEMENT_SPEED);
        }
        else if (Gdx.input.isKeyPressed(Input.Keys.DOWN)&& Gdx.input.isKeyPressed(Input.Keys.RIGHT) && i > KEY_DELAY) {
            i = 0;
            directionAnimation("DownRight");
            Player.addX(MOVEMENT_SPEED);
            Player.addY(-MOVEMENT_SPEED);

            cam.translate(MOVEMENT_SPEED,-MOVEMENT_SPEED);
        }

        else if (Gdx.input.isKeyPressed(Input.Keys.LEFT) && i > KEY_DELAY) {
            i = 0;
            directionAnimation("Left");
            Player.addX(-MOVEMENT_SPEED);
            cam.translate(-MOVEMENT_SPEED,0);
        }
        else if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)&& i > KEY_DELAY) {
            i = 0;
            directionAnimation("Right");
            Player.addX(MOVEMENT_SPEED);
            cam.translate(MOVEMENT_SPEED,0);
        }
        else if (Gdx.input.isKeyPressed(Input.Keys.DOWN)&& i > KEY_DELAY) {
            i = 0;
            directionAnimation("Down");
            Player.addY(-MOVEMENT_SPEED);
            cam.translate(0,-MOVEMENT_SPEED);
        }
        if (Gdx.input.isKeyPressed(Input.Keys.UP)&& i > KEY_DELAY) {
            i = 0;
            directionAnimation("Up");
            Player.addY(MOVEMENT_SPEED);

            cam.translate(0,MOVEMENT_SPEED);
        }

        cam.update();
    }


    public void directionAnimation(String direction) {
        Player.setAnimation(new Animation<>(1 / 4f, Player.textureAtlas.findRegions(Player.getSpriteName() + "_" + direction)));
    }
}
