SettlePage.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import GameMgr, { Sound } from "../GameMgr";
  2. import GamePage from "./GamePage";
  3. import GameConfig from "../GameConfig";
  4. const {ccclass, property} = cc._decorator;
  5. @ccclass
  6. export default class SettlePage extends cc.Component {
  7. @property({type: cc.Label})
  8. score_label: cc.Label = null;
  9. @property({type: cc.Label})
  10. score_max_label: cc.Label = null;
  11. @property({type: cc.Label})
  12. hit_label: cc.Label = null;
  13. @property({type: cc.Label})
  14. miss_label: cc.Label = null;
  15. @property({type: cc.Label})
  16. calorie_label: cc.Label = null;
  17. @property({type: cc.Label})
  18. sequence_label: cc.Label = null;
  19. @property({type: cc.Label})
  20. song_labels: cc.Label[] = [];
  21. @property({type: cc.Node})
  22. stars_node: cc.Node = null;
  23. @property({type: cc.Sprite})
  24. photo_sprite: cc.Sprite = null;
  25. @property({type: cc.Node})
  26. titles: cc.Node = null;
  27. score: number = 0;
  28. score_max: number = 0;
  29. hit: number = 0;
  30. miss: number = 0;
  31. calorie: number = 0;
  32. score_target: number = 0;
  33. score_max_target: number = 0;
  34. hit_target: number = 0;
  35. miss_target: number = 0;
  36. calorie_target: number = 0;
  37. onLoad() {
  38. let song_info = GameConfig.getSongInfo(GameMgr.instance.song_id);
  39. this.sequence_label.string = (GameConfig.getSongInfoIndex(song_info.id) + 1).toString();
  40. for (let label of this.song_labels) {
  41. label.string = song_info.name;
  42. }
  43. for (let i = 0; i < this.stars_node.childrenCount; i++) {
  44. if (i < song_info.stars) {
  45. this.stars_node.children[i].active = true;
  46. } else {
  47. this.stars_node.children[i].active = false;
  48. }
  49. }
  50. let imgUrl = GameConfig.remote_res + song_info.id + ".jpg?v=" + GameConfig.song_res_version;
  51. cc.loader.load({url: imgUrl, type: "jpg"}, (err, texture) => {
  52. if (!err) {
  53. let photo_size = this.photo_sprite.node.getContentSize();
  54. this.photo_sprite.spriteFrame = new cc.SpriteFrame(texture);
  55. this.photo_sprite.node.setContentSize(photo_size);
  56. }
  57. });
  58. this.score_target = Math.floor(GamePage.instance.hitBeat / GamePage.instance.overBeat * 100);
  59. if (this.score_target < GameConfig.song_unlock_need_score) {
  60. this.titles.children[1].active = true;
  61. } else {
  62. this.titles.children[0].active = true;
  63. }
  64. let score_max_storage = GameMgr.getStorageScore(GameMgr.instance.song_id);
  65. if (this.score_target > score_max_storage) {
  66. this.score_max_target = this.score_target;
  67. GameMgr.setStorageScore(GameMgr.instance.song_id, this.score_max_target);
  68. } else {
  69. this.score_max_target = score_max_storage;
  70. }
  71. this.hit_target = GamePage.instance.hitBeat;
  72. this.miss_target = GamePage.instance.overBeat - GamePage.instance.hitBeat;
  73. this.calorie_target = GamePage.instance.checkHit_count * window.calorieUnit;
  74. this.calorie_target = parseFloat(this.calorie_target.toFixed(2));
  75. cc.tween(this).to(1, {
  76. score: this.score_target,
  77. score_max: this.score_max_target,
  78. hit: this.hit_target,
  79. miss: this.miss_target,
  80. calorie: this.calorie_target
  81. } as any).start();
  82. //app接口变量,计算得分
  83. if (window.total_score === undefined) {
  84. window.total_score = 1;
  85. } else {
  86. window.total_score += 1;
  87. }
  88. //app接口变量,计算卡路里
  89. if (window.total_calorie === undefined) {
  90. window.total_calorie = this.calorie_target;
  91. } else {
  92. window.total_calorie += this.calorie_target;
  93. }
  94. }
  95. update() {
  96. this.score_label.string = (this.score << 0).toString();
  97. this.score_max_label.string = (this.score_max << 0).toString();
  98. this.hit_label.string = (this.hit << 0).toString();
  99. this.miss_label.string = (this.miss << 0).toString();
  100. this.calorie_label.string = this.calorie.toFixed(2);
  101. }
  102. back() {
  103. if (GameMgr.instance.debug) {
  104. alert("如需重复测试,请关闭网页重新打开!")
  105. return;
  106. }
  107. cc.find("Canvas/game_page").destroy();
  108. cc.find("Canvas/settle_page").destroy();
  109. GameMgr.instance.playEffect(Sound.button_effect);
  110. GameMgr.instance.addPage(GameMgr.instance.main_page);
  111. }
  112. }