| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277 |
- const PlayerStateStatic = require('PlayerState');
- const GameStatesStatic = require('GameStates');
- const MOVE_RIGHT = 2;
- cc.macro.ENABLE_TILEDMAP_CULLING = false;
- cc.Class({
- extends: cc.Component,
- properties: {
- InitialPositionY: 0,
- PlayerStateScript: null,
- jumps: 2,
- acceleration: 2500,
- jumpSpeed: 600,
- drag: 600,
- CharactorScript: null,
- javelinTag: false,
- PerfectGrade: 0,
- isPlayingBoos: false,
- CameraNode: {
- default: null,
- type: cc.Node
- },
- Cushion30AndBunker1M: {//标枪起跳
- default: null,
- type: cc.Prefab
- },
- javetemp_Hero: {//标枪起跳
- default: null,
- type: cc.Prefab
- },
- javetemp_Rivel: {//标枪起跳
- default: null,
- type: cc.Prefab
- },
- sendFrameDataTag: false,
- longJumpCount: 0,//跳远加的距离
- takeOffDistance: 0,//跳远开始的距离。
- isChangeSpeed: false,//是否正在改变速度
- timer: 0.3,//计时时间
- HeroIsStop:false,//hero是否停止状态
- },
- onEnable: function () {
- cc.director.getPhysicsManager().attachDebugDrawToCamera(this);
- },
- onDisable: function () {
- cc.director.getPhysicsManager().detachDebugDrawFromCamera(this);
- },
- onLoad: function () {
- this.init = cc.find("init");
- this.fadeTag = false;
- this.javeCount = 0;// parseInt(Math.random()*10+30);
- this.node.setLocalZOrder(1000);
- this.body = this.getComponent(cc.RigidBody);
- this.speed = cc.p(0, 0);
- this._moveFlags = -1;
- this.PlayerStateScript = this.node.getComponent("PlayerState");
- var Player = this.node.getChildByName('Player');
- this.CharactorScript = Player.getComponent("Charactor");
- this.PlayerStateScript.CurrentSpeed = this.PlayerStateScript.InitialSpeed;
- //踉跄 被拽过去的tag 如果是 true 就不重置速度 如果是 如果是 false 就充值速度
- this.CameraNode = cc.find('CamerarMennager');
- },
- SetCurrentSpeed: function (SpeedValue) {
- if (SpeedValue > this.PlayerStateScript.MaxSpeed) return;
- if (SpeedValue < 0) return;
- this.PlayerStateScript.CurrentSpeed = SpeedValue;
- return SpeedValue;
- },
- SetCurrentSpeed_noRestrictions: function (SpeedValue) {
- this.PlayerStateScript.CurrentSpeed = SpeedValue;
- },
- SetCurrentSpeed_max: function (SpeedValue) {
- var seed = (SpeedValue * 420) / this.PlayerStateScript.MaxSpeed;
- this.PlayerStateScript.CurrentSpeed = seed + 1800;
- return this.PlayerStateScript.CurrentSpeed * (SpeedValue / this.PlayerStateScript.MaxSpeed);
- },
- SetCurrentSpeed_max_jumpLong: function (SpeedValue) {
- var seed = (SpeedValue * 200) / this.PlayerStateScript.MaxSpeed;
- this.PlayerStateScript.CurrentSpeed = seed + 800;
- return this.PlayerStateScript.CurrentSpeed * (SpeedValue / this.PlayerStateScript.MaxSpeed);
- },
- SetCurrentSpeedInitialSpeed: function () {
- this.PlayerStateScript.CurrentSpeed = this.PlayerStateScript.InitialSpeed;
- },
- SetSpeedToZeroAndIdle: function () {
- this.HeroIsStop = true;//玩家停止
- this.SetCurrentSpeed(0);
- this.idle();
- },
- SetCurrentSpeedAndAnimation: function (SpeedValue) {
- this.CharactorScript.setType();
- var CurrentSpeed = this.SetCurrentSpeed(SpeedValue);
- var state = PlayerStateStatic.SpeedRangeForAnimation;
- if (CurrentSpeed >= state.SlowSpeed[0] && CurrentSpeed <= state.SlowSpeed[1]) {
- this.CharactorScript.SetCurrentAnimationIdx(0);
- }
- if (CurrentSpeed >= state.MiddleSpeed[0] && CurrentSpeed <= state.MiddleSpeed[1]) {
- this.CharactorScript.SetCurrentAnimationIdx(1);
- }
- if (CurrentSpeed >= state.HightSpeed[0] && CurrentSpeed <= state.HightSpeed[1]) {
- this.CharactorScript.SetCurrentAnimationIdx(2);
- }
- },
- SetCurrentSpeed_set: function (SpeedValue) {
- this.CharactorScript.setType();
- if (SpeedValue > this.PlayerStateScript.MaxSpeed) return;
- if (SpeedValue < 0) return;
- this.SetCurrentSpeed(SpeedValue);
- var CurrentSpeed = this.PlayerStateScript.CurrentSpeed;
- // cc.log("设置 速度",CurrentSpeed ,cc.find('Canvas').getComponent('GameStates').bServer);
- var state = PlayerStateStatic.SpeedRangeForAnimation;
- if (CurrentSpeed >= state.SlowSpeed[0] && CurrentSpeed <= state.SlowSpeed[1]) {
- this.CharactorScript.SetCurrentAnimationIdx_set(0);
- }
- if (CurrentSpeed >= state.MiddleSpeed[0] && CurrentSpeed <= state.MiddleSpeed[1]) {
- this.CharactorScript.SetCurrentAnimationIdx_set(1);
- }
- if (CurrentSpeed >= state.HightSpeed[0] && CurrentSpeed <= state.HightSpeed[1]) {
- this.CharactorScript.SetCurrentAnimationIdx_set(2);
- }
- },
- //就是跑步 加上速度
- SetCurrentSpeed_noType: function (SpeedValue) {
- if (SpeedValue > this.PlayerStateScript.MaxSpeed) return;
- if (SpeedValue < 0) return;
- this.SetCurrentSpeed(SpeedValue);
- this.CharactorScript.type = 0;
- this.CharactorScript.SetCurrentAnimationIdx_set(0);
- },
- SpeedUp: function (SpeedUpValue) {
- if (cc.find('Canvas').getComponent('GameStates').bStopAllAnimationAndSchedule) return;
- // return;
- var ToSpeed = this.PlayerStateScript.CurrentSpeed + SpeedUpValue;
- this.SetCurrentSpeedAndAnimation(ToSpeed);
- var data = { FunctionName: 'SetCurrentSpeedAndAnimation', Speed: ToSpeed, "CurrentPositionX": this.node.position.x };
- cc.find('Canvas').getComponent('GameMode').SynchronizationFun(data);
- },
- ResetSpeed: function () {
- if (cc.find('Canvas').getComponent('GameStates').bStopAllAnimationAndSchedule) return;
- var ASpeed = this.PlayerStateScript.InitialSpeed;
- this.SetCurrentSpeedAndAnimation(ASpeed);
- },
- ResetSpeed_noType_lerp: function (dt) {
- if (this.isChangeSpeed) {
- var ASpeed = this.PlayerStateScript.InitialSpeed;
- var CSpeed = this.PlayerStateScript.CurrentSpeed;
- var speedFactor = (ASpeed - CSpeed) * 0.4;
- this.timer -= dt;//timer =0.3
- if (this.timer <= 0) {
- this.timer = 0.3;
- CSpeed += speedFactor;
- if (CSpeed <= ASpeed) {
- this.unschedule(this.resetSpeedCallBack);
- CSpeed = ASpeed;
- this.isChangeSpeed = false;
- }
- console.log("ResetSpeed_noType", CSpeed);
- this.SetCurrentSpeed_noType(CSpeed);
- }
- }
- },
- ResetSpeed_noType_lerp_Stop: function () {
- this.isChangeSpeed = false;
- },
- ResetSpeed_noType: function () {
- if(this.HeroIsStop){
- console.log('当前玩家是停止状态,不能设置ResetSpeed_noType!');
- return;
- }
- var ASpeed = this.PlayerStateScript.InitialSpeed;
- this.SetCurrentSpeed_noType(ASpeed);
- },
- ResetSpeed_set: function () {
- this.SetCurrentSpeed_set(this.PlayerStateScript.InitialSpeed);
- },
- //todo 根据当前 速度设置 动作
- SetCurrentSpeedAction: function () {
- // if(!bDebug) return;
- if (!cc.find('Canvas').getComponent('GameStates').bServer) return;
- this.SetCurrentSpeedAndAnimation(this.PlayerStateScript.CurrentSpeed);
- },
- HeroJump: function (callBack) {
- if ("camera_ai" == cc.director.getScene().name) {
- this.HeroJumpAnimation(callBack);
- return;
- }
- var Hero = cc.find("Hero");
- var NetworkSocket = Hero.getComponent('NetworkSocket');
- var data = {};
- if (this.node.name === 'Hero') {
- data = { FunctionName: 'HeroJumpHeroAnimation' };
- NetworkSocket.sendSyncData(JSON.stringify(data));
- }
- this.HeroJumpAnimation(callBack);
- },
- HeroJumpAnimation: function (callBack) {
- var Player = this.node.getChildByName('Player');
- Player.getComponent("Charactor").setOnHurdlingListener(callBack);
- this.playAudioByName("Hei");
- },
- EnableHeroMoving: function (bMoving) {
- if (bMoving) {
- this._moveFlags = MOVE_RIGHT;
- this.PlayerStateScript.CurrentSpeed= this.PlayerStateScript.InitialSpeed;
- }
- else {
- this._moveFlags = -1;
- }
- },
- WriggleControl: function (dt) {
- if (this.WriggleTag) {
- // cc.log("减速",this.PlayerStateScript.CurrentSpeed);
- if (this.PlayerStateScript.CurrentSpeed >= this.PlayerStateScript.InitialSpeed) {
- this.PlayerStateScript.CurrentSpeed -= dt * 300;
- } else {
- this.WriggleTag = false;
- this.SetCurrentSpeed_set(this.PlayerStateScript.CurrentSpeed);
- }
- }
- },
- //todo 开启加速
- addSeendTempControl: function () {
- if (this.addSeendTempTag) {
- return;
- }
- if (this.PlayerStateScript.CurrentSpeed <= 400) {
- this.addSeendCurrentSpeed = this.PlayerStateScript.CurrentSpeed;
- this.PlayerStateScript.CurrentSpeed += 400;
- // cc.log("加速了吗",this.PlayerStateScript.CurrentSpeed);
- this.addSeendTempTag = true;
- }
- },
- addSeendTemp: function (dt) {
- if (this.addSeendTempTag) {
- // cc.log("减速",this.PlayerStateScript.CurrentSpeed);
- if (this.addSeendCurrentSpeed <= this.PlayerStateScript.CurrentSpeed) {
- this.PlayerStateScript.CurrentSpeed -= dt * 200;
- // cc.log("加速了吗-",dt);
- } else {
- this.addSeendTempTag = false;
- }
- }
- },
- HeroLongJump: function (name) {
- // console.log("HeroLongJump==", this.longJumpCount);
- // var Hero = cc.find("Hero");
- // var NetworkSocket = Hero.getComponent('NetworkSocket');
- // var data = {};
- var longJumpData = {
- name: "Hero",
- longJumpCount: this.longJumpCount,//跳的距离
- takeOffDistance: this.takeOffDistance,//蓝区域跳的距离范围
- }
- // if (this.node.name === 'Hero') {
- // data = { FunctionName: 'HeroLongJumpHeroAnimation', netData: longJumpData };
- // NetworkSocket.sendSyncData(JSON.stringify(data));
- // }
- this.HeroLongJumpAnimation(longJumpData);
- this.playAudioByName("Hei");
- },
- HeroLongJumpAnimation: function (tempData) {
- var Player = this.node.getChildByName('Player');
- var Hero = cc.find(tempData.name);
- //扔标枪 计数算法 todo
- var UIControl = cc.find("UIControl").getComponent("UIControl");
- // var Hero = cc.find('Hero');
- var PlayerStateScript = Hero.getComponent("PlayerState");
- PlayerStateScript.TouchControlEnableTouch = false;
- this.SetCurrentSpeed(0);
- this.javelinTag = true;
- var jumpDistance = 3 + tempData.longJumpCount; //跳了多少米
- var jumpPixelSpeed = jumpDistance > 4 ? 900 : 600;
- var jumpDistancePixel = jumpDistance * 240 + tempData.takeOffDistance;//1m约等于 240像素,并且加上 开始的距离
- var jumpTimer = jumpDistancePixel / jumpPixelSpeed;//跳远的时间
- var actionMoveBy = cc.moveBy(jumpTimer, cc.p(jumpDistancePixel, 0));
- this.node.runAction(actionMoveBy);
- var jumpHeight = (jumpDistance - 3) * 10 + 100;//100是固定高度
- var actionBy = cc.jumpBy(jumpTimer, 0, 0, jumpHeight, 1);
- console.log("跳远的距离====:", jumpDistance, this.takeOffDistance);
- // console.log("跳远的距离:",jumpDistance);
- PlayerStateScript.EndDistance = jumpDistance;//记录位置信息
- PlayerStateScript.JumpTimer = jumpTimer;
- Player.getComponent("Charactor").node.runAction(actionBy);
- //跳远开始
- Player.getComponent("Charactor").setOnLongJumpListener(jumpTimer);
- // if (Hero.name == "Hero") {
- // UIControl.startDistance_Hero(0, Hero, true);
- // }
- if (Hero.name == "Hero") {
- UIControl.startDistance_Hero(0, Hero, true);
- }
- this.SetCurrentSpeed(0);
- //跳远结束
- Player.getComponent("Charactor").setTimeOutLongJumpListener(function () {
- this.SetCurrentSpeed(0);
- // CustomLog("当前 玩家", Hero.name, "跳远结束");
- // if (Hero.name == "Hero") {
- // UIControl.startDistance_Hero(0, Hero, false);
- // }
- setTimeout(function () {
- if (!this.javelinTag) {
- return;
- }
- // Player.getComponent("Charactor").setAnimation(0, Player.getComponent("Charactor").statusArr_longjump[6], false);
- Player.getComponent("Charactor").spine.timeScale = 1;//跳远落地后动画的播放速度,timeScale越大,速度越快
- }.bind(this), 500);
- setTimeout(function () {
- if (!this.javelinTag) {
- return;
- }
- this.ResetSpeed();
- }.bind(this), 1000);
- this.playAudioByName("JumpDown");
- this.resetPerfectGrade();//踉跄则重置perfect等级
- }.bind(this));
- },
- StopPlayerAllSchedule: function () {
- // var GameMode = cc.find('Canvas').getComponent('GameMode');
- var GameStates = cc.find('Canvas').getComponent('GameStates');
- var Hero = cc.find('Hero');
- var Rivel = cc.find('Rivel');
- var HeroControl = Hero.getComponent('HeroControl');
- var RivelControl = Rivel.getComponent('HeroControl');
- var HeroCharactor = Hero.getChildByName('Player').getComponent('Charactor');
- var RivelCharactor = Rivel.getChildByName('Player').getComponent('Charactor');
- HeroCharactor.unscheduleAllCallbacks();
- RivelCharactor.unscheduleAllCallbacks();
- Hero.stopAllActions();
- Rivel.stopAllActions();
- HeroControl.javelinTag = false;
- RivelControl.javelinTag = false;
- HeroControl.CameraNode.parent = Hero;
- GameStates.bStopAllAnimationAndSchedule = true;
- HeroControl.SetSpeedToZeroAndIdle();
- RivelControl.SetSpeedToZeroAndIdle();
- this.schedule(function () {
- GameStates.bStopAllAnimationAndSchedule = false;
- }, 1, 0);
- },
- //踉跄 摔倒
- Stagger: function () {
- this.StaggerAnimation();
- // cc.log("踉跄 本地",this.node);
- // var data = { FunctionName: 'StaggerAnimation', PositionX: this.node.convertToWorldSpaceAR(cc.Vec2.ZERO).x };
- // cc.find('Canvas').getComponent('GameMode').SynchronizationFun(data);
- this.playAudioByName("Boos");
- this.resetPerfectGrade();
- this.resetLv();
- },
- resetLv : function () {
- cc.find("Shade").getComponent('Shade').FadeInAndOut(function ()
- {
- cc.log("黑屏");
- this.init.getComponent("init").initGame();
- }.
- bind(this),function ()
- {
- cc.log("亮屏");
- }.bind(this));
- },
- StaggerAnimation: function () {
- if (cc.find('Canvas').getComponent('GameStates').bStopAllAnimationAndSchedule) return;
- if (this.PlayerStateScript.BStagger) return;
- this.PlayerStateScript.BStagger = !this.PlayerStateScript.BStagger;
- //踉跄+减速
- var Player = this.node.getChildByName('Player');
- Player.getComponent("Charactor").setOnTripListener();
- this.SetCurrentSpeedAndAnimation(0);
- // this.ResetSpeed();
- // this.schedule(this.StaggerAnimationSchedule, 0.5, 0);
- },
- StaggerAnimationSchedule: function () {
- if (cc.find('Canvas').getComponent('GameStates').bStopAllAnimationAndSchedule) return;
- this.PlayerStateScript.BStagger = !this.PlayerStateScript.BStagger;
- if (this.PlayerStateScript.BStagger) {
- return;
- }
- // this.ResetSpeed();
- },
- unSchedules: function () {
- this.unschedule(this.StaggerAnimationSchedule);
- },
- StaggerAnimationUnch: function () {
- this.unschedule(this.StaggerAnimationSchedule);
- },
- SendSyncHeroPosition: function () {
- var Hero = cc.find("Hero");
- var PositionStr = Hero.position.x.toString();
- var data = { FunctionName: 'Hero', PositionX: PositionStr, Speed: Hero.getComponent('PlayerState').CurrentSpeed };
- cc.find('Canvas').getComponent('GameMode').SynchronizationFun(data);
- },
- SendSyncRivelPosition: function () {
- var Rivel = cc.find("Rivel");
- var PositionStr = Rivel.position.x.toString();
- var Hero = cc.find("Hero");
- var data = { FunctionName: 'Rivel', PositionX: PositionStr, Speed: Hero.getComponent('PlayerState').CurrentSpeed };
- cc.find('Canvas').getComponent('GameMode').SynchronizationFun(data);
- },
- // called every frame, uncomment this function to activate update callback
- update: function (dt) {
- var PlayerCollisionLine = this.node.getChildByName('Player').getChildByName('PlayerCollisionLine');
- if (PlayerCollisionLine) {
- if (!PlayerCollisionLine.active) {
- if (this.node.position.x - this.node.getComponent('PlayerState').AtStartLinePositionX > 100) {
- PlayerCollisionLine.active = true;
- }
- }
- }
- var Hero = cc.find("Hero");
- // var DistanceBetweenMeAndRival = Hero.x;
- // var absDistanceBetweenMeAndRival = Math.abs(Math.floor(DistanceBetweenMeAndRival));
- //
- //
- // // cc.log("这是多少",dt);
- // //这里注释一下,屏幕宽720,一半为360,人物宽65,相加为425,也就是说对手与自己距离425像素外则需显示头像
- // if (DistanceBetweenMeAndRival > 425) {//大于425,则头像在右边
- // cc.find('UIControl').getComponent('GameUI').displayRivalHead(false);
- // }
- // if (DistanceBetweenMeAndRival < -425) {//小于425,则头像在左边
- // cc.find('UIControl').getComponent('GameUI').displayRivalHead(true);
- // }
- // if (DistanceBetweenMeAndRival > -425 && DistanceBetweenMeAndRival < 425) {
- // cc.find('UIControl').getComponent('GameUI').hideRivalHead();
- // }
- // this.speed = this.body.linearVelocity;
- // this.speed = cc.p(-50,0);
- // cc.log("刚体X",this.speed);
- var Level = cc.find("Level");
- Level.getComponent('LevelControl').SetDistance(this.node.getPosition().x);
- if (this._moveFlags === MOVE_RIGHT) {
- if (this.node.scaleX < 0) {
- this.node.scaleX *= -1;
- }
- var PlayerPositionX = this.node.getPositionX();
- PlayerPositionX += 1 * dt * this.PlayerStateScript.CurrentSpeed;
- this.node.setPositionX(PlayerPositionX);
- }
- if (this.jumps > 0 && this._up) {
- this.speed.y = this.jumpSpeed;
- this.jumps--;
- }
- //Stop at start line
- var PlayerState = this.node.getComponent('PlayerState');
- // var StartLineStopPositionArray = PlayerState.StartLineStopPositionArray;
- // if (StartLineStopPositionArray.length != 0) {
- // var StartLineStopPositionOriginalX = PlayerState.StartLineStopPositionArray[0];
- // var StartLineStopPositionX = PlayerState.StartLineStopPositionArray[0];
- // if (this.node.name == 'Hero') {
- // StartLineStopPositionX -= 30;
- // }
- // if ((this.node.position.x - StartLineStopPositionX) >-10) {
- //
- // if (this.node.name == 'Hero') {
- // // console.log("Hero 停!!");
- // this.SetSpeedToZeroAndIdle();
- // this.node.setPositionX(StartLineStopPositionX);
- // PlayerState.StartLineStopPositionArray.shift();
- //
- // var GameStates = cc.find('Canvas').getComponent('GameStates');
- // var GameMode = cc.find('Canvas').getComponent('GameMode');
- // var CurrentPlayerNode = this.node;
- // GameStates.StartLinePositionX = StartLineStopPositionOriginalX;
- // var data = { FunctionName: 'SetStartLinePositionX', StartLinePositionX: StartLineStopPositionOriginalX };
- // GameMode.SynchronizationFun(data);
- // if (GameStates.bServer) {
- // GameStates.EnterStartLinePlayersArray.push(CurrentPlayerNode);
- // GameMode.CheckPlayersDistance(true);
- // }
- // else {
- // var data = { FunctionName: 'CheckPlayersDistance', StartLinePositionX: StartLineStopPositionOriginalX };
- // GameMode.SynchronizationFun(data);
- // }
- // // if (GameStates.bServer) {
- // // GameStates.EnterStartLinePlayersArray.push(CurrentPlayerNode);
- // // var data = { FunctionName: 'SetStartLinePositionX', StartLinePositionX: StartLineStopPositionOriginalX };
- // // GameMode.SynchronizationFun(data);
- // // GameMode.CheckPlayersDistance(true);
- //
- // // console.log("this.node.name GameStates.bServer ", this.node.name);
- // // }
- // // else {
- // // var data = { FunctionName: 'CheckPlayersDistance', StartLinePositionX: StartLineStopPositionOriginalX };
- // // GameMode.SynchronizationFun(data);
- //
- // // console.log("this.node.name GameStates.bClient", this.node.name);
- // // }
- // }
- // }
- // }
- //Reduce speed at Finish line
- var FinishLineReduceSpeedPositionArray = PlayerState.FinishLineReduceSpeedPositionArray;
- if (FinishLineReduceSpeedPositionArray.length != 0) {
- var FinishLineStopPositionX = PlayerState.FinishLineReduceSpeedPositionArray[0];
- if ((this.node.position.x - FinishLineStopPositionX) >-10) {
- if(!this.HeroIsStop){//当前玩家是停止状态,不能设置ResetSpeed_noType
- this.ResetSpeed_noType();
- if (this.node.name == 'Hero') {
- var NetworkSocket = cc.find('Hero').getComponent('NetworkSocket');
- var data = {};
- data = { FunctionName: 'FinishLineReduceSpeedPositionArray' };
- // console.log("hero 减速!!!");
- NetworkSocket.sendSyncData(JSON.stringify(data));
- }
- }
- // console.log("Name:",this.node.name);
- // this.isChangeSpeed = true;//开启减速
- PlayerState.FinishLineReduceSpeedPositionArray.shift();
- }
- }
- // this.ResetSpeed_noType_lerp(dt);
- // this.javelinUpDate();
- // var da = {
- // p : this.node.getPositionX()
- // };
- // this.sendFrameDatas(da);
- this._up = false;
- this.body.linearVelocity = this.speed;
- this.WriggleControl(dt);
- this.addSeendTemp(dt);
- if (!cc.find('Canvas').getComponent('GameStates').BStartGame) return;
- if (this.node.name != 'Rivel') return;
- var SyschroAtionArray = this.PlayerStateScript.SyschroAtionArray;
- if (SyschroAtionArray.length > 0) {
- CustomLog("现在里面有设么没处理的", SyschroAtionArray);
- if (SyschroAtionArray[0].FunctionName === 'StaggerAnimation') {
- this.StaggerAnimation();
- // cc.log("踉跄 网络",this.node);
- SyschroAtionArray.shift();
- }
- else if (SyschroAtionArray[0].FunctionName === 'SetCurrentSpeedAndAnimation') {
- this.SetCurrentSpeedAndAnimation(SyschroAtionArray[0].Speed);
- SyschroAtionArray.shift();
- }
- else if ('ResetSpeed' === SyschroAtionArray[0].FunctionName) {
- this.ResetSpeed_noType();
- SyschroAtionArray.shift();
- }
- else if ('SetSpeedToZeroAndIdle' === SyschroAtionArray[0].FunctionName) {
- this.SetSpeedToZeroAndIdle();
- SyschroAtionArray.shift();
- }
- else if (SyschroAtionArray[0].FunctionName === 'HeroLongJumpHeroAnimation') {//todo 跳远
- var Hero = cc.find('Rivel');
- var HeroControl = Hero.getComponent("HeroControl");
- var tempData = SyschroAtionArray[0].netData;
- var longJumpData = {
- name: "Rivel",
- longJumpCount: tempData.longJumpCount,//跳的距离
- takeOffDistance: tempData.takeOffDistance,//蓝区域跳的距离范围
- }
- HeroControl.HeroLongJumpAnimation(longJumpData);
- // console.log("我现在 处理 跳远 2 ", SyschroAtionArray[0].FunctionName, tempData);
- // CustomLog("我现在 处理 跳远 2 ", SyschroAtionArray[0].FunctionName);
- SyschroAtionArray.shift();
- }
- else if (SyschroAtionArray[0].FunctionName === 'SetCurrentSpeed_max_jumpLong') {
- // CustomLog("跳远设置速度");
- //todo 标记2
- this.seend = this.PlayerStateScript.CurrentSpeed;
- this.SetCurrentSpeed_max_jumpLong(this.seend);
- SyschroAtionArray.shift();
- }
- else if (SyschroAtionArray[0].FunctionName === 'HeroJumpHeroAnimation') {
- this.HeroJumpAnimation();
- SyschroAtionArray.shift();
- }
- else if (SyschroAtionArray[0].FunctionName === 'PerfectHurdleBandRailing') {
- // CustomLog("跨栏 撞倒","PerfectHurdleBandRailing");
- var data = SyschroAtionArray[0];
- var Hero = cc.find("Hero");
- var NetworkSocket = Hero.getComponent('NetworkSocket');
- CustomLog("跨栏 撞倒", data);
- var Obj = NetworkSocket.GetSyncObj(data.ParentName, data.ObjName, data.PositionX);
- SyschroAtionArray.shift();
- if (Obj == null) {
- return;
- }
- Obj.getComponent("Barrier").FallingDown();
- }
- else if (SyschroAtionArray[0].FunctionName === 'PerfectHurdleBandBarrier') {
- // CustomLog("跨栏 撞倒","PerfectHurdleBandBarrier");
- var data = SyschroAtionArray[0];
- var Hero = cc.find("Hero");
- var NetworkSocket = Hero.getComponent('NetworkSocket');
- // CustomLog("跨栏 撞倒",data);
- var Obj = NetworkSocket.GetSyncObj(data.ParentName, data.ObjName, data.PositionX);
- SyschroAtionArray.shift();
- if (Obj == null) {
- return;
- }
- Obj.getComponent("Barrier").FallingDown();
- }
- else if (SyschroAtionArray[0].FunctionName === 'ShakeBarrier') {
- // CustomLog("跨栏 撞倒","PerfectHurdleBandBarrier");
- var data = SyschroAtionArray[0];
- var Hero = cc.find("Hero");
- var NetworkSocket = Hero.getComponent('NetworkSocket');
- // CustomLog("跨栏 晃",data);
- var Obj = NetworkSocket.GetSyncObj(data.ParentName, data.ObjName, data.PositionX);
- SyschroAtionArray.shift();
- if (Obj == null) {
- return;
- }
- Obj.getComponent("Barrier").Shake();
- }
- else if (SyschroAtionArray[0].FunctionName === 'upBike') {
- // CustomLog("跨栏 撞倒","PerfectHurdleBandBarrier");
- // cc.log("上车 网络", this.node);
- this.SetCurrentSpeed(0);
- this.upBike();
- var Charactor = this.node.getChildByName('Player');
- var CharactorScript = Charactor.getComponent("Charactor");
- setTimeout(function () {
- CharactorScript.spine.timeScale = 1;
- cc.find('Canvas').getComponent('GameStates').CurrentProgress = GameStatesStatic.GameProgress.RideBike;
- this.SetCurrentSpeed(PlayerStateStatic.SpeedRangeForAnimation.SlowSpeed[1]);
- }.bind(this), 600);
- SyschroAtionArray.shift();
- }
- else if (SyschroAtionArray[0].FunctionName === 'downBikeHero') {
- // CustomLog("跨栏 撞倒","PerfectHurdleBandBarrier");
- SyschroAtionArray.shift();
- }
- else if (SyschroAtionArray[0].FunctionName === 'upJavelinHeroAnimation') {
- var data = SyschroAtionArray[0];
- var NetworkSocket = Hero.getComponent('NetworkSocket');
- CustomLog("捡起来标枪");
- var Obj = NetworkSocket.GetSyncObj(data.ParentName, data.ObjName, data.PositionX);
- this.upJavelin();
- this.SetCurrentSpeed(PlayerStateStatic.SpeedRangeForAnimation.SlowSpeed[1]);
- if (Obj != null) {
- Obj.active = false;
- }
- cc.find('Canvas').getComponent('GameStates').CurrentProgress = GameStatesStatic.GameProgress.Javelin;
- SyschroAtionArray.shift();
- }
- else if (SyschroAtionArray[0].FunctionName === 'Herojavelin') {
- // this.javelinRivel("Rivel");
- SyschroAtionArray.shift();
- }
- else if (SyschroAtionArray[0].FunctionName === 'Restrictions') {
- this.SetCurrentSpeed_noRestrictions(600);
- SyschroAtionArray.shift();
- }
- else if (SyschroAtionArray[0].FunctionName === 'upJavelinend') {
- this.SetCurrentSpeed_noRestrictions(SyschroAtionArray[0].Speed);
- SyschroAtionArray.shift();
- }
- else if (SyschroAtionArray[0].FunctionName === 'JavelinData') {
- this.javelinRivel("Rivel" ,SyschroAtionArray[0].JavelinData,SyschroAtionArray[0].JaveCount);
- SyschroAtionArray.shift();
- }
- }
- },
- upJavelin: function () {
- var Charactor = this.node.getChildByName('Player');
- var CharactorScript = Charactor.getComponent("Charactor");
- CharactorScript.upJavelin();
- this.SetCurrentSpeedAction();
- },
- javelinUpDate: function () {
- // var PlayerState = this.node.getComponent('PlayerState');
- // // cc.log("",this.node.name);
- // cc.log("创建出来的标枪 333 Rivel",PlayerState.JavePositionArray_Rivel);
- // if (this.node.name=="Rivel") {
- // var Rivelarr = PlayerState.JavePositionArray_Rivel;
- // if (Rivelarr.length != 0) {
- // cc.log("局标枪",this.node.name,(this.node.position.x - Rivelarr[0].px));
- // if (Math.abs(this.node.position.x - Rivelarr[0].px) < 10)
- // {
- // if (Rivelarr[0].node != null) {
- // Rivelarr[0].node.active = false;
- // }
- // // this.upJavelin();
- //
- // PlayerState.JavePositionArray_Rivel.shift();
- // }
- // }
- //
- // }
- // else if (this.node.name=="Hero") {
- // var Heroarr = PlayerState.JavePositionArray_Hero;
- // if (Heroarr.length != 0) {
- // if (Math.abs(this.node.position.x - Heroarr[0].px) < 10)
- // {
- //
- // PlayerState.JavePositionArray_Rivel.shift();
- // }
- // }
- // }
- // var FinishLineReduceSpeedPositionArray = PlayerState.FinishLineReduceSpeedPositionArray;
- // if (FinishLineReduceSpeedPositionArray.length != 0)
- // {
- // var FinishLineStopPositionX = PlayerState.FinishLineReduceSpeedPositionArray[0];
- //
- // if (Math.abs(this.node.position.x - FinishLineStopPositionX.px) < 10)
- // {当前jave
- // this.node.getComponent('HeroControl').ResetSpeed_noType();
- // PlayerState.FinishLineReduceSpeedPositionArray.shift();
- // }
- // }
- },
- upBike: function () {
- var Charactor = this.node.getChildByName('Player');
- var CharactorScript = Charactor.getComponent("Charactor");
- CharactorScript.upBike();
- this.SetCurrentSpeedAction();
- },
- upJavelin_go: function (callBack) {
- var Charactor = this.node.getChildByName('Player');
- var CharactorScript = Charactor.getComponent("Charactor");
- CharactorScript.upJavelin_go(callBack);
- this.playAudioByName("Hei");
- },
- idle: function (callBack) {
- var Charactor = this.node.getChildByName('Player');
- var CharactorScript = Charactor.getComponent("Charactor");
- CharactorScript.idle(callBack);
- },
- readyRun: function (callBack) {
- var Charactor = this.node.getChildByName('Player');
- var CharactorScript = Charactor.getComponent("Charactor");
- CharactorScript.readyRun(callBack);
- },
- addidle: function (callBack) {
- var Charactor = this.node.getChildByName('Player');
- var CharactorScript = Charactor.getComponent("Charactor");
- CharactorScript.addidle(callBack);
- },
- idleadd: function (callBack) {
- var Charactor = this.node.getChildByName('Player');
- var CharactorScript = Charactor.getComponent("Charactor");
- CharactorScript.idleadd(callBack);
- },
- playAudioByName: function (AudioName) {
- var AudioSource = this.getAudioSourceByName(AudioName);
- if (AudioSource != null) {
- if (AudioName == "Boos") {//踉跄时的音效:若正在播放此音效则不能播放;
- if (this.isPlayingBoos == false) {
- this.isPlayingBoos = true;
- AudioSource.play();
- this.scheduleOnce(function () {
- this.isPlayingBoos = false;
- }, AudioSource.getDuration());
- }
- } else {
- AudioSource.play();
- }
- }
- },
- stopAudioByName: function (AudioName) {
- var AudioSource = this.getAudioSourceByName(AudioName);
- if (AudioSource != null) {
- AudioSource.stop();
- }
- },
- getAudioSourceByName: function (AudioName) {
- var HeroPlayer = null;
- // cc.log(AudioName);
- if (this.node.name == "Hero") {
- if (cc.find('Hero').getChildByName('Player') != null) {
- HeroPlayer = cc.find('Hero').getChildByName('Player');
- if (HeroPlayer.getChildByName("MyAudio") != null) {
- var AudioControlScript = HeroPlayer.getChildByName('MyAudio').getComponent("AudioControl");
- if (AudioControlScript.getAudioSourceByName(AudioName) != null) {
- var AudioSource = AudioControlScript.getAudioSourceByName(AudioName);
- return AudioSource;
- }
- }
- }
- }
- },
- addPerfectGradeAndPlay: function () {
- if (this.PerfectGrade < 10) {
- this.PerfectGrade += 1;
- }
- this.playAudioByName("Perfect" + this.PerfectGrade);
- },
- resetPerfectGrade: function () {
- this.PerfectGrade = 0;
- },
- javelin: function () {
- //获取场景
- var scene = cc.director.getScene();
- // cc.log("父亲",scene);
- var charactor = scene.getChildByName("Hero").getChildByName("Player").getComponent("Charactor");
- // cc.log("有么",charactor);
- var HeroControl = scene.getChildByName("Hero").getComponent("HeroControl");
- // console.log("javelin");
- if (HeroControl != null) {
- var Player = scene.getChildByName("Hero").getChildByName("Player");
- //扔标枪
- HeroControl.upJavelin_go();
- this.seend = HeroControl.PlayerStateScript.CurrentSpeed;
- setTimeout(function () {
- // cc.log("标枪预制 1",this.javelin_prefab);
- var tPrefab = this.tPrefabs = cc.instantiate(this.javelin_prefab);
- // cc.log("标枪预制 2",tPrefab);
- var Level = cc.find("Level");
- var Hero = cc.find("Hero");
- //扔标枪 计数算法 todo
- var UIControl = cc.find("UIControl").getComponent("UIControl");
- UIControl.startDistance(1, Hero, true);
- tPrefab.parent = Hero;
- tPrefab.zIndex = 999;
- tPrefab.setPosition(100, -50);
- var HeroControl = scene.getChildByName("Hero").getComponent("HeroControl");
- var data = {
- duration: 3.5,
- position: 0,
- y: -70,
- height: 500,
- jumps: 1
- };
- tPrefab.getComponent("Charactor_javeLin").javelin(data, function () {
- var datas = {
- duration: 1,
- position: -1000,
- y: 0
- };
- this.javelinmoveHero(datas, Player);
- HeroControl.SetCurrentSpeed(this.seend + 1000);
- console.log("Start Javelin;")
- }.bind(this), function () {
- console.log("End Javelin;")
- var Level = cc.find("Level");
- HeroControl.SetCurrentSpeed(0);
- var datas = {
- duration: 2,
- position: 1000,
- y: 0
- };
- charactor.readyRun();
- //人物进场
- this.javelinmoveHero(datas, Player, null, function () {
- var p = tPrefab.getBoundingBoxToWorld();
- tPrefab.parent = Level;
- tPrefab.setPosition(p.x - 360, p.y - 640);
- // CustomLog("现在坐标 父类",p,p1,tPrefab.getBoundingBoxToWorld());
- HeroControl.SetCurrentSpeed(500);
- UIControl.startDistance(1, Hero, false);
- }.bind(this));
- }.bind(this));
- this.node.destroy();
- }.bind(this), 500);
- }
- },
- javelinmove: 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);
- },
- javelinRivel: function (name, javalinData, JaveCount) {
- // console.log("javelin rivel;");
- //获取场景
- var scene = cc.director.getScene();
- // cc.log("父亲",scene);
- var charactor = scene.getChildByName(name).getChildByName("Player").getComponent("Charactor");
- // cc.log("有么",charactor);
- var HeroControl = scene.getChildByName(name).getComponent("HeroControl");
- HeroControl.javelinTag = true;
- console.log("javelin rivel;");
- if (HeroControl != null) {
- var Hero = scene.getChildByName(name);
- //扔标枪
- HeroControl.upJavelin_go();
- HeroControl.idleadd();
- HeroControl.SetCurrentSpeed(0);
- // return;
- setTimeout(function () {
- HeroControl = scene.getChildByName(name).getComponent("HeroControl");
- if (!HeroControl.javelinTag) {
- return;
- }
- var tPrefab = cc.instantiate(this.javetemp_Rivel);
- tPrefab.parent = cc.director.getScene();//中部PK积分显示后隐藏
- this.addCamera(tPrefab);
- tPrefab.active = true;
- tPrefab.isTag = true;
- tPrefab.zIndex = 999;
- tPrefab.setPosition(Hero.x, Hero.y + 100);
- var HeroControl = scene.getChildByName(name).getComponent("HeroControl");
- var x = 1440 + JaveCount * 72;
- var data = javalinData;
- tPrefab.javeTime = data.duration;
- var datas = {
- duration: data.duration,
- position: x,
- y: 0
- };
- tPrefab.getChildByName("jave").getComponent("Charactor_javeLin").javelin(data, function () {
- if (!HeroControl.javelinTag) {
- tPrefab.isTag = null;
- return;
- }
- HeroControl.javelinmoveHero(datas, tPrefab);
- }.bind(this), function () {
- tPrefab.isTag = null;
- if (!HeroControl.javelinTag) {
- tPrefab.isTag = null;
- return;
- }
- HeroControl.javelinmoveHero_act(datas);
- if (tPrefab.x - this.node.x > 3000) {
- this.node.x = tPrefab.x-720;
- }
- charactor.readyRun();
- }.bind(this));
- }.bind(this), 150);
- }
- },
- //计算height,和duration
- javelinData: function (x) {
- var MiddleX = x / 2;
- var highest = Math.sqrt(x * x - MiddleX * MiddleX) - x;
- highest = highest < 0 ? -highest : highest;
- highest += 120;
- // console.log("标枪的x值=", x, "this.javeCount=", this.javeCount, "highest==", highest);
- var tempDuration = x > 5000 ? 4 : 2;
- var data = {
- duration: tempDuration,
- position: 0,
- y: -70,
- height: highest,//600
- jumps: 1
- };
- return data;
- },
- javelinHero: function (name) {
- //获取场景
- var scene = cc.director.getScene();
- // cc.log("父亲",scene);
- var charactor = scene.getChildByName(name).getChildByName("Player").getComponent("Charactor");
- // cc.log("有么",charactor);
- var HeroControl = scene.getChildByName(name).getComponent("HeroControl");
- var Hero = cc.find(name);
- var NetworkSocket = Hero.getComponent('NetworkSocket');
- // cc.log("有没有",HeroControl.javelinTag);
- HeroControl.javelinTag = true;
- if (HeroControl != null) {
- var Hero = scene.getChildByName(name);
- //扔标枪
- HeroControl.upJavelin_go();
- var UIControl = cc.find("UIControl").getComponent("UIControl");
- HeroControl.idleadd();
- HeroControl.SetCurrentSpeed(0);
- var x = 1440 + this.javeCount * 72;
- var data = this.javelinData(x);
- //同步数据给rivel
- // var NetData = { FunctionName: 'JavelinData', JavelinData: data, JaveCount: this.javeCount };
- // NetworkSocket.sendSyncData(JSON.stringify(NetData));
- // return;
- setTimeout(function () {
- cc.log('看一下走到哪了');
- HeroControl = scene.getChildByName(name).getComponent("HeroControl");
- // cc.log("到终点",HeroControl.javelinTag);
- if (!HeroControl.javelinTag) {
- return;
- }
- var tPrefab = cc.instantiate(this.javetemp_Hero);
- tPrefab.parent = cc.director.getScene();//中部PK积分显示后隐藏
- tPrefab.active = true;
- tPrefab.isTag = true;
- cc.log(HeroControl.CameraNode+'**************');
- HeroControl.CameraNode.parent = tPrefab;
- this.addCamera(tPrefab);
- tPrefab.zIndex = 999;
- tPrefab.setPosition(Hero.x, Hero.y);
- var HeroControl = scene.getChildByName(name).getComponent("HeroControl");
- var datas = {
- duration: data.duration,
- position: x,
- y: 0
- };
- tPrefab.getChildByName("jave").getComponent("Charactor_javeLin").javelin(data, function () {
- if (!HeroControl.javelinTag) {
- tPrefab.isTag = null;
- return;
- }
- tPrefab.javeTime = data.duration;
- UIControl.startDistance_Hero(1, tPrefab, true);
- HeroControl.javelinmoveHero(datas, tPrefab);
- cc.log("变速 扔标枪1", HeroControl.PlayerStateScript.CurrentSpeed);
- }.bind(this), function () {
- if (!HeroControl.javelinTag) {
- tPrefab.isTag = null;
- return;
- }
- //
- cc.log("标枪和人的距离", tPrefab.x,this.node.x);
- HeroControl.javelinmoveHero_act(datas);
- if (tPrefab.x - this.node.x > 3000) {
- this.node.x = tPrefab.x-720;
- }
- tPrefab.isTag = null;
- tPrefab.getComponent("CollideHurdleBand_javelinemove").cameraNodeTag = true;
- // cc.log("标枪结束",tPrefab.x);
- this.stopAudioByName("JavelinFlying");//停止标枪飞的声音
- this.playAudioByName("JavelinDown");//播放标枪落地的声音
- // UIControl.startDistance_Hero(1, tPrefab, false);
- UIControl.setCallBack_Hero(function (m) {
- }.bind(this));
- charactor.readyRun();
- // cc.log("到终点",HeroControl.javelinTag);
- var p1 = tPrefab.getPosition();
- }.bind(this));
- }.bind(this), 150);
- }
- },
- 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) {
- // console.log("javelinMoveHero = ", data);
- 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_act: function (data) {
- var speed = data.position / (data.duration + 1);
- // cc.log("速度是",speed);
- this.SetCurrentSpeed_noRestrictions(speed);
- },
- downBikeHero: function (name) {
- var charactor = cc.find(name).getChildByName("Player").getComponent("Charactor");
- if (charactor != null) {
- charactor.downBike(function () {
- charactor.readyRun();
- }.bind(this));
- // charactor.readyRun();
- // charactor.idleadd();
- // cc.find(name).getComponent('HeroControl').SetCurrentSpeed(0);
- cc.find(name).getComponent("PlayerState").enableTouch = false;
- }
- },
- downBikeRivel: function (name) {
- var charactor = cc.find(name).getChildByName("Player").getComponent("Charactor");
- if (charactor != null) {
- charactor.downBike(function () {
- }.bind(this));
- charactor.idleadd();
- cc.find(name).getComponent('HeroControl').SetCurrentSpeed(0);
- cc.find(name).getComponent("PlayerState").enableTouch = false;
- }
- },
- addCamera: function (node) {
- if(cc.find("CamerarMennager")!=null){
- var CamerarMennager = cc.find("CamerarMennager").getComponent('CamerarMennager');
- CamerarMennager.addTargets(node);
- }else{
- cc.log('******************');
- }
- // var CameraNode = cc.find("Hero").getChildByName("CameraNode");
- var Hero;
- var CameraNode;
- var javetemp_Hero;
- if (cc.find("Hero").getChildByName("CameraNode") != null) {
- Hero = cc.find("Hero").getChildByName("CameraNode").getComponent("cc.Camera")
- }
- if (cc.find("CameraNode") != null) {
- CameraNode = cc.find("CameraNode").getComponent("cc.Camera");
- }
- if (cc.find("javetemp_Hero") != null) {
- if (cc.find("javetemp_Hero").getChildByName("CameraNode") != null) {
- javetemp_Hero = cc.find("javetemp_Hero").getChildByName("CameraNode").getComponent("cc.Camera");
- }
- }
- cc.log('node name ',node.name,"现在检查","Hero",Hero,"CameraNode",CameraNode,"javetemp_Hero",javetemp_Hero);
- if (Hero != null) {
- var Camera = cc.find("Hero").getChildByName("CameraNode").getComponent("cc.Camera");
- Camera.addTarget(node);
- cc.log('11111****');
- }
- else if (CameraNode != null) {
- var Camera = cc.find("CameraNode").getComponent("cc.Camera");
- Camera.addTarget(node);
- cc.log('22222****');
- }
- else if (javetemp_Hero != null) {
- var Camera = cc.find("javetemp_Hero").getChildByName("CameraNode").getComponent("cc.Camera");
- Camera.addTarget(node);
- cc.log('33333****');
- }
- },
- //发送帧同步
- sendFrameDatas: function (data) {
- var Rivel = cc.find("Rivel");
- var Hero = cc.find("Hero");
- var NetworkSocket = Hero.getComponent('NetworkSocket');
- if (!cc.find('Canvas').getComponent('GameStates').bServer) {
- data.PlayerStates = 'Server';
- }
- if (cc.find('Canvas').getComponent('GameStates').bServer) {
- data.PlayerStates = 'Client';
- }
- NetworkSocket.sendFrameData(JSON.stringify(data));
- }
- });
|