| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- const PlayerState = require('PlayerState');
- //todo 上车没时间解释了
- var BarrierSuperClass = require("BarrierSuper");
- cc.Class({
- extends:BarrierSuperClass,
- properties: {
- inTag1 : false,
- inTag2 : false,
- HAHANum:0,
- bHasCompared:false,
- },
- start: function () {
- this.finshPlayers = [];
- this.bHasCompared = false;
- cc.find('Canvas').getComponent('GameStates').EnterFinishLinePlayersArray = [];
- cc.find('Canvas').getComponent('GameMode').bHasAddScore = false;
- },
- onLoad : function () {
- this.finshPlayers = [];
- this.bHasCompared = false;
- cc.find('Canvas').getComponent('GameStates').EnterFinishLinePlayersArray = [];
- cc.find('Canvas').getComponent('GameMode').bHasAddScore = false;
- },
- onCollisionEnter: function (other)
- {
- if(other.node.name === 'PlayerCollisionLine') {
- if (other.node.parent.parent.name == "Hero") {
- var GmaeStates = cc.find('Canvas').getComponent('GameStates');
- var GameMode = cc.find('Canvas').getComponent('GameMode');
- if(!GmaeStates.bServer){
- var data = { FunctionName: 'addScore',PlayerName:'Hero'};
- GameMode.SynchronizationFun(data);
- }
- else{
- GameMode.addScore(cc.find('Hero'))
- }
- // this.TimerWinOrLose();
- var Hero = cc.find("Hero");
- var HeroControl = Hero.getComponent("HeroControl");
- HeroControl.downBikeHero("Hero");
- var data = {FunctionName:'downBikeHero',EndPositionX: Hero.x};
- GameMode.SynchronizationFun(data);
- }
- }
- },
- TimerWinOrLose:function(){
- this.callback = function () {
- var MyScore = cc.find('Hero').getComponent("PlayerState").TerminalPoint;
- var RivalScore = cc.find('Rivel').getComponent("PlayerState").TerminalPoint;
- if (MyScore+RivalScore == 5) {
- this.unschedule(this.callback);
- this.PlayWinAudio(MyScore,RivalScore);
- cc.log("==========55555555=========");
- }
- else{
- cc.log("+++++++++++++++++++MyScore is "+MyScore+" and RivalScore is "+RivalScore);
- }
- }
- this.schedule(this.callback, 1);
- },
- PlayWinAudio:function(MyScore,RivalScore){
- this.scheduleOnce(function() {
- var NetworkSocket = cc.find('Hero').getComponent("NetworkSocket");
- MyScore = cc.find('Hero').getComponent("PlayerState").TerminalPoint;
- RivalScore = cc.find('Rivel').getComponent("PlayerState").TerminalPoint;
- cc.find('UIControl').getComponent('GameUI').hideTimerMiddlePKScore(MyScore,RivalScore,0);
- if(MyScore > RivalScore){
- cc.find('UIControl').getComponent('GameUI').displayUIWin();
- cc.find('UIControl').getComponent('GameUI').playFireworks();
- cc.find('Hero').getComponent('HeroControl').playAudioByName("Cheers");
- var data = {
- isSelf : 2
- }
- NetworkSocket.quitGame(data);
- }else {
- cc.find('UIControl').getComponent('GameUI').displayUILose();
- cc.find('Hero').getComponent('HeroControl').playAudioByName("Boos");
- var data = {
- isSelf : 1
- }
- NetworkSocket.quitGame(data);
- }
- }, 0.1);
- if (!this.inTag1) {
- this.inTag1 = true;
- } else {
- return;
- }
- },
- onCollisionEnter2: function (other) {//旧的
- // cc.log("进来的是什么",other.node.name);
- if(other.node.name === 'PlayerCollisionLine'||other.node.name == "PlayerCollisionLine_end") {
- if (other.node.parent.parent.name == "Hero") {
- this.scheduleOnce(function() {
- var MyScore = cc.find('Hero').getComponent("PlayerState").TerminalPoint;
- var RivalScore = cc.find('Rivel').getComponent("PlayerState").TerminalPoint;
- cc.log("MyScore is "+MyScore+" And RivalScore is "+RivalScore);
- cc.find('UIControl').getComponent('GameUI').hideTimerMiddlePKScore(MyScore,RivalScore,0);
- if(MyScore > RivalScore){
- cc.find('UIControl').getComponent('GameUI').displayUIWin();
- cc.find('UIControl').getComponent('GameUI').playFireworks();
- cc.find('Hero').getComponent('HeroControl').playAudioByName("Cheers");
- }else {
- cc.find('UIControl').getComponent('GameUI').displayUILose();
- cc.find('Hero').getComponent('HeroControl').playAudioByName("Boos");
- }
- }, 0.1);
- if (!this.inTag1) {
- this.inTag1 = true;
- } else {
- return;
- }
- var Hero = cc.find("Hero");
- var NetworkSocket = Hero.getComponent('NetworkSocket');
- var HeroControl = Hero.getComponent("HeroControl");
- HeroControl.downBikeHero("Hero");
- var data = {FunctionName:'downBikeHero'};
- NetworkSocket.sendSyncData(JSON.stringify(data));
- this.finshPlayers.push(other.node.parent.parent);
- cc.log("**********hero*******");
- }
- if (other.node.parent.parent.name == "Rivel") {
- if (!this.inTag2) {
- this.inTag2 = true;
- } else {
- return;
- }
- var Hero = cc.find("Hero");
- var NetworkSocket = Hero.getComponent('NetworkSocket');
- var HeroControl = Hero.getComponent("HeroControl");
- HeroControl.downBikeRivel("Rivel",other);
- this.finshPlayers.push(other.node.parent.parent);
- cc.log("**********Rivel*******");
- }
- if (this.finshPlayers.length == 1) {
- cc.find('Canvas').getComponent('GameMode').addScore(other.node.parent.parent);
- cc.log("addScore*****finshPlayers0*"+this.finshPlayers[0].name);
- }
- }
- },
- javelinmoveRivel : function (data,view,starListener,endListener) {
- var actionBy = cc.moveBy(data.duration, data.position, data.y);
- var start = cc.callFunc(function () {
- if (starListener!=null) {
- starListener();
- }
- }.bind(this), this);
- var stop = cc.callFunc(function () {
- if (endListener!=null) {
- endListener();
- }
- }.bind(this), this);
- var myAction = cc.sequence(start,actionBy,stop);
- view.runAction(myAction);
- },
- javelinmoveHero : function (data,view,starListener,endListener) {
- var actionBy = cc.moveBy(data.duration, data.position, data.y);
- var start = cc.callFunc(function () {
- if (starListener!=null) {
- starListener();
- }
- }.bind(this), this);
- var stop = cc.callFunc(function () {
- if (endListener!=null) {
- endListener();
- }
- }.bind(this), this);
- var myAction = cc.sequence(start,actionBy,stop);
- view.runAction(myAction);
- },
- });
|