GameOver.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { _decorator, director, Label, } from 'cc';
  2. import { ModulerBase } from '../../GameFrameWork/ModulerBase';
  3. import { resMgr } from '../../../Frames/ResourcesMgr';
  4. import { GameInfo } from '../../../GameInfo';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('GameOver')
  7. export class GameOver extends ModulerBase {
  8. //击杀奖励
  9. KillRewardConfig = [
  10. { min: 0, max: 5, reward: 100 },
  11. { min: 6, max: 10, reward: 200 },
  12. { min: 11, max: 15, reward: 300 },
  13. { min: 16, max: 20, reward: 400 },
  14. { min: 21, max: 25, reward: 500 },
  15. { min: 26, max: 30, reward: 600 },
  16. { min: 31, max: Infinity, reward: 700 },
  17. ]
  18. //生命奖励
  19. LifeRewardConfig = [
  20. { min: 0, max: 20, reward: 100 },
  21. { min: 21, max: 40, reward: 200 },
  22. { min: 41, max: 60, reward: 300 },
  23. { min: 61, max: 80, reward: 400 },
  24. { min: 81, max: 100, reward: 500 },
  25. ]
  26. //通关奖励
  27. newresultRewardConfig = [
  28. { min: 1, max: 5, reward: 100 },
  29. { min: 6, max: 10, reward: 150 },
  30. { min: 11, max: 15, reward: 200 },
  31. { min: 16, max: 20, reward: 250 },
  32. { min: 21, max: 25, reward: 300 },
  33. { min: 26, max: Infinity, reward: 350 },
  34. ]
  35. protected onEnable(): void {
  36. this.config();
  37. }
  38. protected onStart(): void {
  39. this.onBtnClick("_btnLeft", this._onBtnBack, this);
  40. this.onBtnClick("_btnRight", this._onBtnRight, this);
  41. }
  42. config() {
  43. this.getSprite("_gameOverUITitle").spriteFrame =
  44. GameInfo.Instance.getOverWin() ?
  45. resMgr.getSpriteFrame("GameWin") :
  46. resMgr.getSpriteFrame("GameOver");
  47. this.getNode("_btnRight").getComponentInChildren(Label).string =
  48. GameInfo.Instance.getOverWin() ? "下一关" : "重新开始";
  49. this.getLabel("_lifePercent").string = `${GameInfo.Instance.getLifePecent()}%`;
  50. this.getLabel("_killCount").string = `${GameInfo.Instance.getKillCount()}`;
  51. const kill: number = this.calculateReward(GameInfo.Instance.getKillCount(), this.KillRewardConfig);
  52. const life: number = this.calculateReward(GameInfo.Instance.getLifePecent(), this.LifeRewardConfig);
  53. const stageClear: number = this.calculateReward(GameInfo.Instance.getCurlv(), this.newresultRewardConfig);
  54. const xp: number = GameInfo.Instance.getCurlv() * 30;
  55. const lifeDia: number = Math.floor(life * 0.08);
  56. const stageClearDia: number = Math.floor(stageClear * 0.07)
  57. this.getLabel("_kill").string = `${kill}`;
  58. this.getLabel("_life").string = `${life}`;
  59. this.getLabel("_stageClear").string = `${stageClear}`;
  60. this.getLabel("_total").string = `${kill + life + stageClear}`;
  61. this.getLabel("_xp").string = `${xp}`;
  62. this.getLabel("_lifeDia").string = `${lifeDia}`;
  63. this.getLabel("_stageClearDia").string = `${stageClearDia}`;
  64. this.getLabel("_totalDia").string = `${lifeDia + stageClearDia}`;
  65. }
  66. private _onBtnBack() {
  67. this.clearDt();
  68. this.hide(false);
  69. director.loadScene("StartScene");
  70. }
  71. private _onBtnRight() {
  72. if(GameInfo.Instance.getOverWin()){
  73. console.log("下一关")
  74. } else {
  75. console.log("重新开始")
  76. }
  77. }
  78. //计算奖励
  79. private calculateReward(lifeReward: number, rewardConfig: any) {
  80. const matchRule = rewardConfig.find(rule =>
  81. lifeReward >= rule.min && lifeReward <= rule.max
  82. )
  83. return matchRule ? matchRule.reward : 0;
  84. }
  85. private clearDt() {
  86. GameInfo.Instance.setKillCount(0);
  87. GameInfo.Instance.setLifePecent(0);
  88. GameInfo.Instance.setOverWin(false)
  89. }
  90. }