package ir.codeandroid.game;

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


import ir.codeandroid.framework.Image;

import android.graphics.Rect;

public class Ajorkari {
    private int ajorX, ajorY, speedX;
    public int type;
    public Image aksAjor;
    private Robot robot = GameScreen.getRobot();
    private Background bg = GameScreen.getBg1();
    private Rect r;

    public Ajorkari(int x, int y, int typeInt) {
        ajorX = x * 40;
        ajorY = y * 40;
        type = typeInt;
        r = new Rect();
        if (type == 5) {
            aksAjor = Assets.ajore_khoski;
        } else if (type == 8) {
            aksAjor = Assets.ajor_chaman_bala;
        } else if (type == 4) {
            aksAjor = Assets.ajor_chaman_chap;

        } else if (type == 6) {
            aksAjor = Assets.ajor_chaman_rast;

        } else if (type == 2) {
            aksAjor = Assets.ajor_chaman_paein;
        } else {
            type = 0;
        }

    }

    public void update() {
        speedX = bg.getSpeedX() * 5;
        ajorX += speedX;
        r.set(ajorX, ajorY, ajorX+40, ajorY+40);

        if (Rect.intersects(r, Robot.bozorg) && type != 0) {
            baresiBarkhordOfoghi(Robot.rect, Robot.rect2);
            baresiBarkhordAmodi(Robot.rect3, Robot.rect4, Robot.payeChap, Robot.payeRast);
        }
    }

    public void baresiBarkhordOfoghi(Rect rtop, Rect rbot) {
        if (Rect.intersects(r, rtop)) {

        }

        if (Rect.intersects(r, rbot) && type == 8) {
            robot.setJumped(false);
            robot.setSpeedY(0);
            robot.setCenterY(ajorY - 63);
        }
    }
    public void baresiBarkhordAmodi(Rect rChap, Rect rRast, Rect payeChap, Rect payeRast) {
        if (type != 5 && type != 2 && type != 0){
            if (Rect.intersects(r, rChap)) {
                robot.setCenterX(ajorX + 102);

                robot.setSpeedX(0);

            }else if (Rect.intersects(r, payeChap)) {
                robot.setCenterX(ajorX + 85);
                robot.setSpeedX(0);
            }

            if (Rect.intersects(r, rRast)) {
                robot.setCenterX(ajorX - 62);

                robot.setSpeedX(0);
            }

            else if (Rect.intersects(r, payeRast)) {
                robot.setCenterX(ajorX - 45);
                robot.setSpeedX(0);
            }
        }
    }



    public int getAjorX() {
        return ajorX;
    }

    public int getAjorY() {
        return ajorY;
    }

    public int getSpeedX() {
        return speedX;
    }

    public int getType() {
        return type;
    }

    public Image getAksAjor() {
        return aksAjor;
    }

    public Background getBg() {
        return bg;
    }

    public void setAjorX(int ajorX) {
        this.ajorX = ajorX;
    }

    public void setAjorY(int ajorY) {
        this.ajorY = ajorY;
    }

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

    public void setType(int type) {
        this.type = type;
    }

    public void setAksAjor(Image aksAjor) {
        this.aksAjor = aksAjor;
    }

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

}
