package ir.codeandroid.game;

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



import android.graphics.Rect;

public class Enemy {
    private int power, speedX, centerX, centerY;
    private Background bg = GameScreen.getBg1();
    public Rect r = new Rect(0, 0, 0, 0);
    public int salamati = 5;
    private int sorateHarekat;
    private Robot robot = GameScreen.getRobot();

    public void update() {
        centerX += speedX;
        taghib();

        speedX = bg.getSpeedX() * 5 + sorateHarekat;
        r.set(centerX - 25, centerY - 25, centerX + 25, centerY + 35);
        if (Rect.intersects(r, Robot.bozorg)) {
            barresiBarkhord();
        }
    }

    private void barresiBarkhord() {
        if (Rect.intersects(r, Robot.rect) || Rect.intersects(r, Robot.rect2) || Rect.intersects(r, Robot.rect3)
                || Rect.intersects(r, Robot.rect4)) {
            System.out.println("Barkhord");
        }
    }

    public void taghib() {
        if (centerX < -95 || centerX > 810) {
            sorateHarekat = 0;
        } else if (Math.abs(robot.getCenterX() - centerX) < 5) {
            sorateHarekat = 0;
        } else {
            if (robot.getCenterX() >= centerX) {
                sorateHarekat = 1;
            } else {
                sorateHarekat = -1;
            }
        }
    }

    public void die() {
    }

    public void attack() {
    }

    public int getPower() {
        return power;
    }

    public int getSpeedX() {
        return speedX;
    }

    public int getCenterX() {
        return centerX;
    }

    public int getCenterY() {
        return centerY;
    }

    public Background getBg() {
        return bg;
    }

    public void setPower(int power) {
        this.power = power;
    }

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

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

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

    public void setBg(Background bg) {
        this.bg = bg;
    }

}
