import Game, { GAME_STATE } from "./tool/Game_TXZS_G_006";

const { ccclass, property } = cc._decorator;
@ccclass
export default class CardItem extends cc.Component {
    @property(cc.Node)
    group_1: cc.Node = null;
    @property(cc.Node)
    group_2: cc.Node = null;
    @property(cc.Node)
    group_3: cc.Node = null;
    @property(cc.Node)
    group_4: cc.Node = null;
    @property(cc.Node)
    group_5: cc.Node = null;
    @property(cc.Node)
    group_6: cc.Node = null;
    private speed: number;
    private width: number;//背景图宽度
    private orgX: number;//原始x点
    public onEnable() {

    }
    protected onDestroy(): void {
    }
    protected onLoad(): void {
        this.speed = 2;
        let size = cc.view.getCanvasSize();
        let scale = (size.width / size.height) / (1920 / 1080);
        if (scale > 1) {
            Math.floor(this.group_1.width *= scale);
            Math.floor(this.group_2.width *= scale);
            Math.floor(this.group_2.width *= scale);
        }
        this.width = this.group_1.width;
        this.orgX = this.group_1.x;

    }

    protected update(dt) {
        if (Game.getIns().state != GAME_STATE.RUNNING) return;
        let speed = 0;
        this.group_1.x -= this.speed;
        this.group_2.x -= this.speed;
        this.group_3.x -= this.speed;
        if (this.group_1.x < -this.width - 200)
            this.group_1.x = this.group_3.x + this.width;
        if (this.group_2.x < -this.width - 200)
            this.group_2.x = this.group_1.x + this.width;
        if (this.group_3.x < -this.width - 200)
            this.group_3.x = this.group_2.x + this.width;
        this.group_4.x -= this.speed;
        this.group_5.x -= this.speed;
        this.group_6.x -= this.speed;
        if (this.group_4.x < -this.width - 200)
            this.group_4.x = this.group_3.x + this.width;
        if (this.group_5.x < -this.width - 200)
            this.group_5.x = this.group_1.x + this.width;
        if (this.group_6.x < -this.width - 200)
            this.group_6.x = this.group_2.x + this.width;
    }

}