| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- let library = require("../Library");
- cc.Class({
- extends: cc.Component,
- properties: {
- gameStates: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- totalTime: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- playButton: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- kCal: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- resultPlanNode: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- },
- start () {
- //init node
- this.gameStatesScpt = this.gameStates.getComponent('GameStates');
- this.totalTimeLabel = this.totalTime.getComponent(cc.Label);
- this.resultScpt = this.resultPlanNode.getComponent('Result');
- this.countingToShowKcal = 0;
- },
- fireTick()
- {
- this.schedule(this.tick, 1);
- },
- tick()
- {
- //total time
- this.gameStatesScpt.currentTime++;
- this.totalTimeLabel.string = library.formatSeconds(this.gameStatesScpt.currentTime);
- //kcal
- this.gameStatesScpt.kCal+=300/3600;
- this.countingToShowKcal++;
- if(this.countingToShowKcal>10)
- {
- this.countingToShowKcal = 0;
- this.kCal.getComponent(cc.Label).string = this.gameStatesScpt.kCal.toFixed(2).toString();
- }
- },
- untick()
- {
- this.unschedule(this.tick);
- },
- //结束
- playOver(){
- this.resultPlanNode.active = true;
- this.resultScpt.onEnd({
- hit:this.gameStatesScpt.hitCount,
- miss:this.gameStatesScpt.missCount,
- time: Math.round((this.gameStatesScpt.currentTime/60)*100)/100,
- kCal: Math.round(this.gameStatesScpt.kCal*100)/100
- });
- },
- onPlay()
- {
- if(this.bPaused)
- {
- this.playButton.getChildByName('Pause').active = true;
- this.playButton.getChildByName('Play').active = false;
- this.resume();
- }
- else
- {
- this.playButton.getChildByName('Pause').active = false;
- this.playButton.getChildByName('Play').active = true;
- this.pause();
- }
- this.bPaused = !this.bPaused;
- },
- pause()
- {
- cc.director.pause()
- },
- resume()
- {
- cc.director.resume();
- },
- onReplay()
- {
- cc.director.loadScene('Game');
- }
- });
|