package ir.codeandroid.game;

/**
 * Created by ARM on 5/27/2018.
 */


import android.graphics.Rect;
import java.util.ArrayList;

public class Robot {
    //
    final int JUMPSPEED = -15;
    final int MOVESPEED = 5;

    private int centerX = 100;
    private int centerY = 377;
    private boolean jumped = false;
    private boolean movingLeft = false;
    private boolean movingRight = false;
    private boolean ducked = false;
    private boolean readyToFire = true;
    private  Background bg1 = GameScreen.getBg1();
    private  Background bg2 = GameScreen.getBg2();
    private int speedX = 0;
    private int speedY = 0;
    public static Rect rect = new Rect(0, 0, 0, 0);
    public static Rect rect2 = new Rect(0, 0, 0, 0);
    public static Rect rect3 = new Rect(0, 0, 0, 0);
    public static Rect rect4 = new Rect(0, 0, 0, 0);
    public static Rect bozorg = new Rect(0, 0, 0, 0);
    public static Rect payeChap = new Rect(0,0,0,0);
    public static Rect payeRast = new Rect(0,0,0,0);


    private ArrayList<Golole> gololeha = new ArrayList<Golole>();

    public void update() {
        //
        if (speedX < 0) {
            centerX += speedX;

        }
        if (speedX == 0 || speedX < 0) {
            bg1.setSpeedX(0);
            bg2.setSpeedX(0);
        }
        if (centerX <= 200 && speedX > 0) {
            centerX += speedX;
        }
        if (speedX > 0 && centerX > 200) {
            bg1.setSpeedX(-MOVESPEED / 5);
            bg2.setSpeedX(-MOVESPEED / 5);
        }

        //
        centerY += speedY;

        //

        speedY += 1;
        if (speedY > 3){
            jumped = true;
        }
        //
        if (centerX + speedX <= 60) {
            centerX = 61;
        }

        rect.set(centerX - 34, centerY - 63, centerX + 34, centerY);
        rect2.set(rect.left, rect.top + 63, rect.left+68, rect.top + 128);
        rect3.set(rect.left - 26, rect.top+32, rect.left, rect.top+52);
        rect4.set(rect.left + 68, rect.top+32, rect.left+94, rect.top+52);
        bozorg.set(centerX - 110, centerY - 110, centerX + 70, centerY + 70);
        payeChap.set(centerX - 50, centerY + 20, centerX, centerY + 35);
        payeRast.set(centerX, centerY + 20, centerX+50, centerY+35);


    }

    public void moveRight() {
        if (ducked == false) {
            speedX = MOVESPEED;
        }
    }

    public void moveLeft() {
        if (ducked == false) {
            speedX = -MOVESPEED;
        }
    }

    public void stopRight() {
        setMovingRight(false);
        stop();
    }

    public void stopLeft() {
        setMovingLeft(false);
        stop();
    }

    private void stop() {
        if (isMovingRight() == false && isMovingLeft() == false) {
            speedX = 0;
        }
        if (isMovingRight() == false && isMovingLeft() == true) {
            moveLeft();
        }
        if (isMovingRight() == true && isMovingLeft() == false) {
            moveRight();
        }
    }

    public void jump() {
        if (jumped == false) {
            speedY = JUMPSPEED;
            jumped = true;
        }
    }

    public void shoot() {
        if (readyToFire) {
            Golole g = new Golole(centerX + 50, centerY - 25);
            gololeha.add(g);
        }
    }

    public ArrayList getGololeha() {
        return gololeha;
    }

    public int getCenterX() {
        return centerX;
    }

    public int getCenterY() {
        return centerY;
    }

    public boolean isJumped() {
        return jumped;
    }

    public int getSpeedX() {
        return speedX;
    }

    public int getSpeedY() {
        return speedY;
    }

    public void setCenterX(int centerX) {
        this.centerX = centerX;
    }

    public void setCenterY(int centerY) {
        this.centerY = centerY;
    }

    public void setJumped(boolean jumped) {
        this.jumped = jumped;
    }

    public void setSpeedX(int speedX) {
        this.speedX = speedX;
    }

    public void setSpeedY(int speedY) {
        this.speedY = speedY;
    }

    public boolean isDucked() {
        return ducked;
    }

    public void setDucked(boolean ducked) {
        this.ducked = ducked;
    }

    public boolean isMovingRight() {
        return movingRight;
    }

    public void setMovingRight(boolean movingRight) {
        this.movingRight = movingRight;
    }

    public boolean isMovingLeft() {
        return movingLeft;
    }

    public void setMovingLeft(boolean movingLeft) {
        this.movingLeft = movingLeft;
    }

    public boolean isReadyToFire() {
        return readyToFire;
    }

    public void setReadyToFire(boolean readyToFire) {
        this.readyToFire = readyToFire;
    }

}
