const { ccclass, property } = cc._decorator;

@ccclass
export default class LimitBar extends cc.Component {
  @property(cc.Sprite) barSprite: cc.Sprite = null;
  @property(cc.SpriteFrame) limitBarSprite1: cc.SpriteFrame = null;
  @property(cc.SpriteFrame) limitBarSprite2: cc.SpriteFrame = null;

  static instance: LimitBar;
  winStar: number = 3;
  progress: number;

  protected onLoad(): void {
    LimitBar.instance = this;
    this.progress = 1;
    this.barSprite.fillRange = this.progress;
  }

  fillTheBar() {
    this.progress -= 0.005;
    this.barSprite.fillRange = this.progress;
    if (this.progress <= 0.6) {
      this.winStar = 2;
      this.getComponent(cc.Sprite).spriteFrame = this.limitBarSprite1;
    }
    if (this.progress <= 0.3) {
      this.winStar = 1;
      this.getComponent(cc.Sprite).spriteFrame = this.limitBarSprite2;
    }
  }
}
