123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import { _decorator, director, Label, } from 'cc';
- import { ModulerBase } from '../../GameFrameWork/ModulerBase';
- import { resMgr } from '../../../Frames/ResourcesMgr';
- import { GameInfo } from '../../../GameInfo';
- const { ccclass, property } = _decorator;
- @ccclass('GameOver')
- export class GameOver extends ModulerBase {
- //击杀奖励
- KillRewardConfig = [
- { min: 0, max: 5, reward: 100 },
- { min: 6, max: 10, reward: 200 },
- { min: 11, max: 15, reward: 300 },
- { min: 16, max: 20, reward: 400 },
- { min: 21, max: 25, reward: 500 },
- { min: 26, max: 30, reward: 600 },
- { min: 31, max: Infinity, reward: 700 },
- ]
- //生命奖励
- LifeRewardConfig = [
- { min: 0, max: 20, reward: 100 },
- { min: 21, max: 40, reward: 200 },
- { min: 41, max: 60, reward: 300 },
- { min: 61, max: 80, reward: 400 },
- { min: 81, max: 100, reward: 500 },
- ]
- //通关奖励
- newresultRewardConfig = [
- { min: 1, max: 5, reward: 100 },
- { min: 6, max: 10, reward: 150 },
- { min: 11, max: 15, reward: 200 },
- { min: 16, max: 20, reward: 250 },
- { min: 21, max: 25, reward: 300 },
- { min: 26, max: Infinity, reward: 350 },
- ]
- protected onEnable(): void {
- this.config();
- }
- protected onStart(): void {
- this.onBtnClick("_btnLeft", this._onBtnBack, this);
- this.onBtnClick("_btnRight", this._onBtnRight, this);
- }
- config() {
- this.getSprite("_gameOverUITitle").spriteFrame =
- GameInfo.Instance.getOverWin() ?
- resMgr.getSpriteFrame("GameWin") :
- resMgr.getSpriteFrame("GameOver");
- this.getNode("_btnRight").getComponentInChildren(Label).string =
- GameInfo.Instance.getOverWin() ? "下一关" : "重新开始";
- this.getLabel("_lifePercent").string = `${GameInfo.Instance.getLifePecent()}%`;
- this.getLabel("_killCount").string = `${GameInfo.Instance.getKillCount()}`;
- const kill: number = this.calculateReward(GameInfo.Instance.getKillCount(), this.KillRewardConfig);
- const life: number = this.calculateReward(GameInfo.Instance.getLifePecent(), this.LifeRewardConfig);
- const stageClear: number = this.calculateReward(GameInfo.Instance.getCurlv(), this.newresultRewardConfig);
- const xp: number = GameInfo.Instance.getCurlv() * 30;
- const lifeDia: number = Math.floor(life * 0.08);
- const stageClearDia: number = Math.floor(stageClear * 0.07)
- this.getLabel("_kill").string = `${kill}`;
- this.getLabel("_life").string = `${life}`;
- this.getLabel("_stageClear").string = `${stageClear}`;
- this.getLabel("_total").string = `${kill + life + stageClear}`;
- this.getLabel("_xp").string = `${xp}`;
- this.getLabel("_lifeDia").string = `${lifeDia}`;
- this.getLabel("_stageClearDia").string = `${stageClearDia}`;
- this.getLabel("_totalDia").string = `${lifeDia + stageClearDia}`;
- }
- private _onBtnBack() {
- this.clearDt();
- this.hide(false);
- director.loadScene("StartScene");
- }
- private _onBtnRight() {
- if(GameInfo.Instance.getOverWin()){
- console.log("下一关")
- } else {
- console.log("重新开始")
- }
- }
- //计算奖励
- private calculateReward(lifeReward: number, rewardConfig: any) {
- const matchRule = rewardConfig.find(rule =>
- lifeReward >= rule.min && lifeReward <= rule.max
- )
- return matchRule ? matchRule.reward : 0;
- }
- private clearDt() {
- GameInfo.Instance.setKillCount(0);
- GameInfo.Instance.setLifePecent(0);
- GameInfo.Instance.setOverWin(false)
- }
- }
|