import GameMgr, { Sound } from "../GameMgr"; import GamePage from "./GamePage"; import GameConfig from "../GameConfig"; const {ccclass, property} = cc._decorator; @ccclass export default class SettlePage extends cc.Component { @property({type: cc.Label}) score_label: cc.Label = null; @property({type: cc.Label}) score_max_label: cc.Label = null; @property({type: cc.Label}) hit_label: cc.Label = null; @property({type: cc.Label}) miss_label: cc.Label = null; @property({type: cc.Label}) calorie_label: cc.Label = null; @property({type: cc.Label}) sequence_label: cc.Label = null; @property({type: cc.Label}) song_labels: cc.Label[] = []; @property({type: cc.Node}) stars_node: cc.Node = null; @property({type: cc.Sprite}) photo_sprite: cc.Sprite = null; @property({type: cc.Node}) titles: cc.Node = null; score: number = 0; score_max: number = 0; hit: number = 0; miss: number = 0; calorie: number = 0; score_target: number = 0; score_max_target: number = 0; hit_target: number = 0; miss_target: number = 0; calorie_target: number = 0; onLoad() { let song_info = GameConfig.getSongInfo(GameMgr.instance.song_id); this.sequence_label.string = (GameConfig.getSongInfoIndex(song_info.id) + 1).toString(); for (let label of this.song_labels) { label.string = song_info.name; } for (let i = 0; i < this.stars_node.childrenCount; i++) { if (i < song_info.stars) { this.stars_node.children[i].active = true; } else { this.stars_node.children[i].active = false; } } let imgUrl = GameConfig.remote_res + song_info.id + ".jpg?v=" + GameConfig.song_res_version; cc.loader.load({url: imgUrl, type: "jpg"}, (err, texture) => { if (!err) { let photo_size = this.photo_sprite.node.getContentSize(); this.photo_sprite.spriteFrame = new cc.SpriteFrame(texture); this.photo_sprite.node.setContentSize(photo_size); } }); this.score_target = Math.floor(GamePage.instance.hitBeat / GamePage.instance.overBeat * 100); if (this.score_target < GameConfig.song_unlock_need_score) { this.titles.children[1].active = true; } else { this.titles.children[0].active = true; } let score_max_storage = GameMgr.getStorageScore(GameMgr.instance.song_id); if (this.score_target > score_max_storage) { this.score_max_target = this.score_target; GameMgr.setStorageScore(GameMgr.instance.song_id, this.score_max_target); } else { this.score_max_target = score_max_storage; } this.hit_target = GamePage.instance.hitBeat; this.miss_target = GamePage.instance.overBeat - GamePage.instance.hitBeat; this.calorie_target = GamePage.instance.checkHit_count * window.calorieUnit; this.calorie_target = parseFloat(this.calorie_target.toFixed(2)); cc.tween(this).to(1, { score: this.score_target, score_max: this.score_max_target, hit: this.hit_target, miss: this.miss_target, calorie: this.calorie_target } as any).start(); //app接口变量,计算得分 if (window.total_score === undefined) { window.total_score = 1; } else { window.total_score += 1; } //app接口变量,计算卡路里 if (window.total_calorie === undefined) { window.total_calorie = this.calorie_target; } else { window.total_calorie += this.calorie_target; } } update() { this.score_label.string = (this.score << 0).toString(); this.score_max_label.string = (this.score_max << 0).toString(); this.hit_label.string = (this.hit << 0).toString(); this.miss_label.string = (this.miss << 0).toString(); this.calorie_label.string = this.calorie.toFixed(2); } back() { if (GameMgr.instance.debug) { alert("如需重复测试,请关闭网页重新打开!") return; } cc.find("Canvas/game_page").destroy(); cc.find("Canvas/settle_page").destroy(); GameMgr.instance.playEffect(Sound.button_effect); GameMgr.instance.addPage(GameMgr.instance.main_page); } }