| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- const constants = require('Constants');
- cc.Class({
- extends: cc.Component,
- properties: {
- YellowBG: {
- default: null,
- type: cc.Prefab
- },
- SpawnPoint: {
- default: null,
- type: cc.Node
- },
- GameOverUI: {
- default: null,
- type: cc.Node
- },
- },
- onLoad() {
- GlobalData.gameMode = this;
- this.timer = 0.3;//计时时间
- this.IsPlayingAudio = false;
- },
- start() {
- },
- //每一个项目结束。重置需要重置的属性
- afterTheEndOfSports() {
- //音效重置
- var heroControl = GlobalData.game.getHeroControl();
- heroControl.resetPerfectGrade();
- //标枪的叠加距离
- GlobalData.game.javeCount = 0;
- //标枪的距离
- // GlobalData.game.javelinDistance = 0;
- //跳远的叠加距离
- GlobalData.game.longJumpCount = 0;
- //跳远的距离
- // GlobalData.game.longJumpDistance = 0;
- //项目结束时减速一次
- heroControl.PlayerAnimControl.IsSlowingDownSpeed = false;
- },
- //添加当前的速度值
- AddGameSpeed(Value) {
- GlobalData.game.GameSpeed += Value;
- if (GlobalData.game.GameSpeed >= constants.configGameSpeedMax) {
- GlobalData.game.GameSpeed = constants.configGameSpeedMax;
- }
- },
- //减速
- DecelerationGameSpeed(value) {
- },
- //缓慢减速
- DecelerationGameSpeed_lerp(dt) {
- var ASpeed = constants.configGameSpeedMin;
- var CSpeed = GlobalData.game.GameSpeed;
- var speedFactor = (ASpeed - CSpeed) * 0.06;
- CSpeed += speedFactor;
- this.timer -= dt;//timer =0.3
- // console.log(this.timer);
- if (this.timer <= 0) {
- this.timer = 0.3;
- if (CSpeed <= ASpeed) {
- CSpeed = ASpeed;
- }
- }
- GlobalData.game.GameSpeed = CSpeed;
- GlobalData.game.getHeroControl().PlayerAnimControl.JudgeBeforeSpeedChange();
- },
- //长加速带按下
- StartTouchLongAcceleration() {
- var self = this;
- GlobalData.game.isMustTouch = true;//点了就设置为true
- self.FillLongAccelerationArea();
- },
- //长加速带停止
- StopTouchLongAcceleration() {
- if (this.YellowLinePrefab != null) {
- this.YellowLinePrefab.getComponent('LongAcceleration').isStop = true;
- this.YellowLinePrefab = null;
- this.IsPlayingAudio = false;
- GlobalData.game.getHeroControl().stopAudioByName("LongAccelerationStart");
- // GlobalData.game.getHeroControl().Stagger();
- }
- },
- FillLongAccelerationArea() {
- if (this.IsPlayingAudio == false) {
- this.IsPlayingAudio = true;
- GlobalData.game.getHeroControl().playAudioByName("LongAccelerationStart");
- }
- var HeroControlScript = GlobalData.game.getHeroControl();
- var YellowLinePosition = cc.p(HeroControlScript.node.x + 390, HeroControlScript.node.y - 32);
- this.YellowLinePrefab = cc.instantiate(this.YellowBG);
- this.YellowLinePrefab.parent = this.SpawnPoint;//GlobalData.game.getHeroControl().node;//- 641 - 32
- this.YellowLinePrefab.setPosition(YellowLinePosition);
- },
- //游戏结束调用
- GameOver() {
- console.log('游戏结束,是否是无敌状态:', GlobalData.game.isInvincible);
- if (GlobalData.game.isInvincible) return;
- //处理人物摔倒动画 todo.....
- GlobalData.game.isCanTouch = false;
- GlobalData.game.getHeroControl().PlayerAnimControl.Stagger();
- GlobalData.game.getHeroControl().PlayerStatesScript.strPlayerStates = 'Over';
- //并且会暂停游戏
- GlobalData.game.PlayerState = GlobalData.GameManager.PlayerState.Stop;
- setTimeout(function () {
- GlobalData.game.State = GlobalData.GameManager.State.Over;
- //游戏状态结束时候,显示结束UI
- this.GameOverUI.active = true;
- this.WatchTheAdFinish(false);
- // this.GameOverUI.getChildByName('Ad').active = true;
- //sdk
- //是否可以播放广告
- if (GlobalData.currentSdk.isCanPlayAd()) {
- this.GameOverUI.getChildByName('Ad').active = true;
- }
- }.bind(this), 1000)
- },
- //观看完广告
- WatchTheAdFinish(isWatch){
- console.log(this.GameOverUI.getChildByName('Ad').getChildByName('continueGame').name);
- this.GameOverUI.getChildByName('Ad').getChildByName('continueGame').getComponent(cc.Button).interactable = isWatch;
- },
- //游戏加分
- // AddScore(){
- // GlobalData.game.GameScore =0;
- // }
- //游戏失败后,重新续命,继续游戏。
- ContinueTheGame() {
- GlobalData.game.getHeroControl().PlayerAnimControl.Idle();
- // console.log(GlobalData.game.PlayerRunState);
- switch (GlobalData.game.PlayerRunState) {
- case GlobalData.GameManager.PlayerRunState.NormalRun:
- GlobalData.game.getHeroControl().PlayerStatesScript.strPlayerStates = 'NormalRun';
- break;
- case GlobalData.GameManager.PlayerRunState.HoldJavelinRun:
- GlobalData.game.getHeroControl().PlayerStatesScript.strPlayerStates = 'HoldJavelinRun';
- break;
- case GlobalData.GameManager.PlayerRunState.RideElephantRun:
- GlobalData.game.getHeroControl().PlayerStatesScript.strPlayerStates = 'RideElephantRun';
- break;
- }
- GlobalData.game.getHeroControl().PlayerAnimControl.SpeedChange();
- //无敌时间
- GlobalData.game.isInvincible = true;
- GlobalData.game.getHeroControl().PlayerAnimControl.PlayPlayerFlashingAnim();//无敌时间人物闪烁
- setTimeout(function () {
- GlobalData.game.isInvincible = false;
- GlobalData.game.getHeroControl().PlayerAnimControl.StopPlayerFlashingAnim();//停止闪烁
- }, GlobalData.game.invincibleTime*1000);
- GlobalData.game.isCanTouch = true;
- GlobalData.game.State = GlobalData.GameManager.State.Run;
- //并且会暂停游戏
- GlobalData.game.PlayerState = GlobalData.GameManager.PlayerState.Run;
- this.GameOverUI.active = false;
- }
- });
|