| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399 |
- 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是否停止状态
- isJumpOver: false,//如果是黑屏瞬移过去的,加上这个限制
-
- getGameStates:null,
- },
- onEnable: function () {
- cc.director.getPhysicsManager().attachDebugDrawToCamera(this);
- },
- onDisable: function () {
- cc.director.getPhysicsManager().detachDebugDrawFromCamera(this);
- },
- onLoad: function () {
- 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");
- //踉跄 被拽过去的tag 如果是 true 就不重置速度 如果是 如果是 false 就充值速度
- this.getGameStates = cc.find('Canvas').getComponent('GameStates');
-
- },
- SetCurrentSpeed: function (SpeedValue) {
- var GameMode = cc.find('Canvas').getComponent('GameMode');
- if (GameMode.isEndGame)
- return;
- 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);
- },
- SpeedDown: function (SpeedUpValue) {
- if (cc.find('Canvas').getComponent('GameStates').bStopAllAnimationAndSchedule) return;
- var ToSpeed = this.PlayerStateScript.CurrentSpeed - SpeedUpValue;
- if (ToSpeed <= this.PlayerStateScript.InitialSpeed) {
- ToSpeed = this.PlayerStateScript.InitialSpeed;
- }
- // return;
- this.SetCurrentSpeedAndAnimation(ToSpeed);
- // cc.log("当前速度是 踉跄",this.PlayerStateScript.CurrentSpeed);
- },
- 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;
- }
- 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,//蓝区域跳的距离范围
- }
- // cc.log("当前玩家是 跳远发送",cc.find('Canvas').getComponent('GameStates').bServer);
- 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);
- this.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));
- var data = {
- duration: jumpTimer,
- position: jumpDistancePixel,
- y: 0
- };
- // if (!this.javelinTag) {
- // return;
- // }
- this.javelinmove(data, this.node, function () {
- }.bind(this), function () {
- // if (!this.javelinTag) {
- // return;
- // }
- this.SetCurrentSpeed(200);
- }.bind(this));
- // this.node.runAction(actionMoveBy);
- var jumpHeight = (jumpDistance - 3) * 10 + 100;//100是固定高度
- var actionBy = cc.jumpBy(jumpTimer, 0, 0, jumpHeight, 1);
- // console.log("跳远的距离====:", tempData.name, jumpDistance, this.takeOffDistance);
- // console.log("跳远的距离:",jumpDistance);
- this.PlayerStateScript.EndDistance = jumpDistance;//记录位置信息
- this.PlayerStateScript.JumpTimer = jumpTimer;
- // if (!this.javelinTag) {
- // return;
- // }
- Player.getComponent("Charactor").node.runAction(actionBy);
- //跳远开始
- Player.getComponent("Charactor").setOnLongJumpListener(jumpTimer);
- if (Hero.name == "Hero") {
- //扔标枪 计数算法 todo
- var UIControl = cc.find("UIControl").getComponent("UIControl");
- UIControl.startDistance_Hero(0, Hero, true);
- }
- // if (!this.javelinTag) {
- // return;
- // }
- //跳远结束
- Player.getComponent("Charactor").setTimeOutLongJumpListener(function () {
- // return;
- // console.log('跳远结束了,我是来自hero的setTimeOutLongJumpListener,tag是 '+this.javelinTag);
- // if (!this.javelinTag) {
- // return;
- // }
- setTimeout(function () {
- if (this.isJumpOver) {
- return;
- }
- Player.getComponent("Charactor").spine.setAnimation(0, Player.getComponent("Charactor").statusArr_longjump[6], false);
- Player.getComponent("Charactor").spine.timeScale = 1;
- // this.SetCurrentSpeed(0);
- setTimeout(function () {
- // this.SetSpeedToZeroAndIdle();
- this.ResetSpeed_noType();
- }.bind(this), 300);
- }.bind(this), jumpTimer + 300);
- setTimeout(function () {
- if (this.isJumpOver || this.node.name == 'Rivel') {
- return;
- }
- //加分
- // this.GameMode = cc.find('Canvas').getComponent('GameMode');
- // this.GameMode.addScore(cc.find('Hero'));
- if (!cc.find('Canvas').getComponent('GameStates').bServer) {
- var data = { FunctionName: 'addScore', PlayerName: 'Hero', value: jumpDistance };
- cc.find('Canvas').getComponent('GameMode').SynchronizationFun(data);
- // cc.log("--我是client,我发送给server请求加分--longJump当前项目是"+cc.find('Canvas').getComponent('GameStates').strCureentLevel);
- }
- else {
- cc.find('Canvas').getComponent('GameMode').addScore(cc.find('Hero'), jumpDistance, true);
- }
- CustomLog("跳远 加分");
- }.bind(this), 700);
- //
- this.playAudioByName("JumpDown");
- // this.resetPerfectGrade();//踉跄则重置perfect等级
- }.bind(this));
- },
- FromLongJumpToHurdle: function () {
- setTimeout(function () {
- var GameMode = cc.find('Canvas').getComponent('GameMode');
- var GameStates = cc.find('Canvas').getComponent('GameStates');
- CustomLog("跳远 黑屏 进入", cc.find("Shade").getComponent('Shade').FadeTag);
- //跳远结束
- var data = {
- gameLv: 1,
- startPositionX: 50000
- }
- // console.log('跳远结束了,准备初始化跨栏项目setStart');
- cc.find("Level").getComponent("LevelControl").setStart(data);
- GameStates.StartLinePositionX = cc.find("Level").getComponent("LevelControl").tempStartNode.x + 720;
- GameMode.CheckPlayersDistance();
- var data = { FunctionName: 'CheckPlayersDistance', StartLinePositionX: GameStates.StartLinePositionX };
- GameMode.SynchronizationFun(data);
- }.bind(this), 500);
- },
- 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');
- var HeroPlayerState = Hero.getComponent('PlayerState');
- var RivelPlayerState = Rivel.getComponent('PlayerState');
- HeroCharactor.unscheduleAllCallbacks();
- RivelCharactor.unscheduleAllCallbacks();
- HeroPlayerState.unscheduleAllCallbacks();
- RivelPlayerState.unscheduleAllCallbacks();
- Hero.stopAllActions();
- Rivel.stopAllActions();
- //cc.log("!!!!!!!!!!!!rival明明停止了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 () {
- // return;
- 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();
- },
- StaggerAnimation: function () {
- //console.log("进来 踉跄",this.PlayerStateScript.BStagger,cc.find('Canvas').getComponent('GameStates').bStopAllAnimationAndSchedule);
- if (cc.find('Canvas').getComponent('GameStates').bStopAllAnimationAndSchedule) return;
- if (this.PlayerStateScript.BStagger) return;
- this.PlayerStateScript.BStagger = true;
- //踉跄+减速
- var Player = this.node.getChildByName('Player');
- Player.getComponent("Charactor").setOnTripListener();
- this.PlayerStateScript.LastSpeed = this.PlayerStateScript.CurrentSpeed;
- this.ResetSpeed();
- this.schedule(this.StaggerAnimationSchedule, 0.7, 0);
- },
- StaggerAnimationSchedule: function () {
- if (cc.find('Canvas').getComponent('GameStates').bStopAllAnimationAndSchedule) return;
- this.PlayerStateScript.BStagger = !this.PlayerStateScript.BStagger;
- // cc.log("this.LastSpeed is "+this.PlayerStateScript.LastSpeed+" this.CurrentSpeed is "+this.PlayerStateScript.CurrentSpeed);
- if (this.PlayerStateScript.CurrentSpeed != 0) {
- this.SpeedDown(this.PlayerStateScript.DownSpeed);
- }
- // this.CurrentSpeed = this.LastSpeed;
- if (this.PlayerStateScript.BStagger) {
- return;
- }
- var ToSpeed = this.PlayerStateScript.LastSpeed;//-this.PlayerStateScript.CurrentSpeed;
- this.SetCurrentSpeedAndAnimation(ToSpeed);
- },
- 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 = this.getGameStates.getHero;
- var Rivel = this.getGameStates.getRivel;
- var HeroControl = this.getGameStates.getHeroControl;
- var RivelControl = this.getGameStates.getRivelControl;
- var DistanceBetweenMeAndRival = Rivel.x - Hero.x;
- // var absDistanceBetweenMeAndRival = Math.abs(Math.floor(DistanceBetweenMeAndRival));
- // if (cc.find('LeftRivalHead') != null) {
- // cc.find('LeftRivalHead').getChildByName("RivalDistance").getComponent('RivalDistance').setRivalDistanceNum(absDistanceBetweenMeAndRival.toString());
- // }
- // if (cc.find('RightRivalHead') != null) {
- // cc.find('RightRivalHead').getChildByName("RivalDistance").getComponent('RivalDistance').setRivalDistanceNum(absDistanceBetweenMeAndRival.toString());
- // }
- // cc.log("这是多少",dt);
- //这里注释一下,屏幕宽720,一半为360,人物宽65,相加为425,也就是说对手与自己距离425像素外则需显示头像
- if (DistanceBetweenMeAndRival > 425) {//大于425,则头像在右边
- if (!cc.find('LeftRivalHead')) {
- cc.find('UIControl').getComponent('GameUI').displayRivalHead(false);
- }
- }
- if (DistanceBetweenMeAndRival < -425) {//小于-425,则头像在左边
- if (!cc.find('RightRivalHead')) {
- cc.find('UIControl').getComponent('GameUI').displayRivalHead(true);
- }
- }
- if (DistanceBetweenMeAndRival >= -425 && DistanceBetweenMeAndRival <= 425) {
- if (cc.find('RightRivalHead') || cc.find('LeftRivalHead')) {
- 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");
- if(this.getGameStates.getLevelControl)
- this.getGameStates.getLevelControl.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].x;
- var StartLineStopPositionX = PlayerState.StartLineStopPositionArray[0].x;
- if (this.node.name == 'Hero') {
- StartLineStopPositionX -= 30;
- }
- if ((this.node.position.x - StartLineStopPositionX) > -10) {
- if (this.node.name == 'Hero') {
- // console.log("Hero 停!!");
- this.node.setPositionX(StartLineStopPositionX);
- cc.find('Rivel').setPositionX(StartLineStopPositionX + 30);
- if (PlayerState.StartLineStopPositionArray[0].type == 2) {
- //设置 重要的 当前项目是什么
- cc.find('Canvas').getComponent('GameStates').CurrentProgress = PlayerState.StartLineStopPositionArray[0].type;
- }
- PlayerState.StartLineStopPositionArray.shift();
- }
- }
- }
- //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 (cc.find('Canvas').getComponent('GameStates').strCureentLevel == "RideBike") {
- // console.log('自行车部分')
- return;
- }
- 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._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') {
- // cc.log("踉跄 通知",this.PlayerStateScript.CurrentSpeed);
- if (this.PlayerStateScript.CurrentSpeed != 0) {
- 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 跳远
- // cc.log("当前玩家是 跳远接收",cc.find('Canvas').getComponent('GameStates').bServer);
- // cc.log('这里执行了几次。。。。。。。。。');
- var tempData = SyschroAtionArray[0].netData;
- var longJumpData = {
- name: "Rivel",
- longJumpCount: tempData.longJumpCount,//跳的距离
- takeOffDistance: tempData.takeOffDistance,//蓝区域跳的距离范围
- }
- RivelControl.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 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 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 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 === 'Restrictions') {
- this.SetCurrentSpeed_noRestrictions(600);
- SyschroAtionArray.shift();
- }
- else if (SyschroAtionArray[0].FunctionName === 'FinishLineReduceSpeedPositionArray') {
- this.ResetSpeed_noType();
- SyschroAtionArray.shift();
- }
- else if (SyschroAtionArray[0].FunctionName === 'PlayersStartToRun') {
- // console.log("PlayersStartToRun!!!");
- Hero.getComponent('HeroControl').playAudioByName('StartGun');//项目开始时哨声
- //项目开始时,UI比分淡出
- if (cc.find('UIPKScore')) {
- cc.find('UIControl').getComponent('GameUI').hideMiddlePKScore();
- }
- this.PlayerStateScript.TouchControlEnableTouch = false;
- HeroControl.HeroIsStop = false;
- RivelControl.HeroIsStop = false;
- HeroControl.ResetSpeed_noType();
- RivelControl.ResetSpeed_noType();
- // cc.log("被拉过来的起点位置",cc.find('Canvas').getComponent('GameStates').StartLinePositionX);
- SyschroAtionArray.shift();
- }
- else if (SyschroAtionArray[0].FunctionName === 'StopPlayerAllSchedule') {
- HeroControl.StopPlayerAllSchedule();
- RivelControl.StopPlayerAllSchedule();
- 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();
- }
- else if (SyschroAtionArray[0].FunctionName === 'resetHero') {
- this.resetHero();
- SyschroAtionArray.shift();
- }
- else if (SyschroAtionArray[0].FunctionName === 'resetHerojavelin') {
- this.stopAudioByName("JavelinFlying");//停止标枪飞的声音
- // this.resets();
- this.SetSpeedToZeroAndIdle();
- SyschroAtionArray.shift();
- }
- else if (SyschroAtionArray[0].FunctionName === 'endGame') {
- var HeroControl = Hero.getComponent("HeroControl");
- var NetworkSocket = Hero.getComponent("NetworkSocket");
- NetworkSocket.endGameAll(2);
- //console.log('退出游戏时候的数据上报 ==',NetworkSocket.isReported);
- if (!NetworkSocket.isReported) {
- if(SyschroAtionArray[0].showText){
- NetworkSocket.setToast(SyschroAtionArray[0].showText);
- }
- var data = {
- isSelf: SyschroAtionArray[0].num
- }
- NetworkSocket.quitGame(data);
- }
- SyschroAtionArray.shift();
- }
- }
- },
- upJavelin: function () {
- var Charactor = this.node.getChildByName('Player');
- var CharactorScript = Charactor.getComponent("Charactor");
- CharactorScript.upJavelin();
- this.SetCurrentSpeedAction();
- },
- 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) {
- // cc.log("我明明stop了啊!!!!!!"+AudioName);
- var AudioSource = this.getAudioSourceByName(AudioName);
- if (AudioSource != null) {
- AudioSource.stop();
- // cc.log("我明明stop了啊!!!!!!222222");
- }
- },
- 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积分显示后隐藏
- cc.find("Level").getComponent("LevelControl").addJaveLin(tPrefab);
- 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;
- if (cc.find('Canvas').getComponent('GameStates').bServer) {//如果是服务器,扔标枪后记录在自己的GameMode上面
- var TempGameMode = cc.find('Canvas').getComponent('GameMode');
- TempGameMode.isClientJaveDis = x;
- }
- 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 () {
- // return;
- // 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 += 0.2;
- // console.log("标枪的x值=", x, "this.javeCount=", this.javeCount, "highest==", highest);
- // console.log("扔多高",highest);
- var tempDuration = x > 5000 ? 4 : 2;
- var data = {
- duration: tempDuration,
- position: 0,
- y: -70,
- height: 600,//600
- jumps: 1
- };
- return data;
- },
- javelinHero: function (name) {
- //获取场景
- // var scene = cc.director.getScene();
- // cc.log("父亲",scene);
- var charactor = this.CharactorScript;//scene.getChildByName(name).getChildByName("Player").getComponent("Charactor");
- // cc.log("有么",charactor);
- var HeroControl = this;//scene.getChildByName(name).getComponent("HeroControl");
- var Hero = this.node;//cc.find(name);
- var NetworkSocket = Hero.getComponent('NetworkSocket');
- // cc.log("有没有",HeroControl.javelinTag);
- HeroControl.javelinTag = true;
- if (HeroControl != null) {
- //扔标枪
- HeroControl.upJavelin_go();
- var UIControl = cc.find("UIControl").getComponent("UIControl");
- HeroControl.idleadd();
- HeroControl.SetCurrentSpeed(0);
- // HeroControl.HeroIsStop = true;//玩家停止
- var x = 1440 + this.javeCount * 72;
- var data = this.javelinData(x);
- //同步数据给rivel
- var NetData = { FunctionName: 'JavelinData', JavelinData: data, JaveCount: this.javeCount, HeroPosition: Hero.position.x };
- NetworkSocket.sendSyncData(JSON.stringify(NetData));
- if (cc.find('Canvas').getComponent('GameStates').bServer) {//如果是服务器,扔标枪后记录在自己的GameMode上面
- var TempGameMode = cc.find('Canvas').getComponent('GameMode');
- TempGameMode.isSeverJaveDis = x;
- }
- // return;
- setTimeout(function () {
- // 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积分显示后隐藏
- cc.find("Level").getComponent("LevelControl").addJaveLin(tPrefab);
- tPrefab.active = true;
- tPrefab.isTag = true;
- 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 () {
- this.stopAudioByName("JavelinFlying");//停止标枪飞的声音
- this.playAudioByName("JavelinDown");//播放标枪落地的声音
- if (!HeroControl.javelinTag) {
- tPrefab.isTag = null;
- return;
- }
- //加分
- setTimeout(function () {
- UIControl.setCallBack_Hero(function (m) {
- }.bind(this));
- // if (!cc.find('Canvas').getComponent('GameStates').bServer) {
- // var data = { FunctionName: 'reqAddScore'};
- // cc.find('Canvas').getComponent('GameMode').SynchronizationFun(data);
- // }
- // else {
- // cc.find('Canvas').getComponent('GameMode').SyncJaveEndAddScore();
- // }
- //加分
- if (!cc.find('Canvas').getComponent('GameStates').bServer) {
- var data = { FunctionName: 'addScore', PlayerName: 'Hero', value: x };
- cc.find('Canvas').getComponent('GameMode').SynchronizationFun(data);
- }
- else {
- cc.find('Canvas').getComponent('GameMode').addScore(cc.find('Hero'), x, true);
- }
- tPrefab.isTag = null;
- charactor.readyRun();
- // var p1 = tPrefab.getPosition();
- }.bind(this), 1000);
- }.bind(this));
- }.bind(this), 150);
- }
- },
- resets: function () {//这个是加分后执行的
- setTimeout(function () {
- var GameMode = cc.find('Canvas').getComponent('GameMode');
- var GameStates = cc.find('Canvas').getComponent('GameStates');
- this.SetSpeedToZeroAndIdle();
- //标枪结束
- var data = {
- gameLv: 2,
- startPositionX: 150000
- }
- cc.find("Level").getComponent("LevelControl").setStart(data);
- GameStates.StartLinePositionX = cc.find("Level").getComponent("LevelControl").tempStartNode.x + 720;
- GameMode.CheckPlayersDistance();
- var data = { FunctionName: 'CheckPlayersDistance', StartLinePositionX: GameStates.StartLinePositionX };
- GameMode.SynchronizationFun(data);
- }.bind(this), 1000);
- },
- 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);
- },
- stopBikeHero: function (name) {
- var charactor = cc.find(name).getChildByName("Player").getComponent("Charactor");
- if (charactor != null) {
- // charactor.stop();
- cc.find(name).getComponent('HeroControl').SetCurrentSpeed(0);
- cc.find(name).getComponent("PlayerState").enableTouch = false;
- }
- },
- downBikeHero: function (name) {
- var charactor = cc.find(name).getChildByName("Player").getComponent("Charactor");
- // console.log(name, ":当前目标1");
- if (charactor != null) {
- charactor.downBike(function () {
- //todo
- }.bind(this));
- charactor.idleadd();
- cc.find(name).getComponent('HeroControl').SetCurrentSpeed(0);
- cc.find(name).getComponent("PlayerState").enableTouch = false;
- // console.log(name, ":当前目标2");
- }
- },
- 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) {
- // 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");
- }
- }
- if (Hero != null) {
- var Camera = cc.find("Hero").getChildByName("CameraNode").getComponent("cc.Camera");
- Camera.addTarget(node);
- }
- else if (CameraNode != null) {
- var Camera = cc.find("CameraNode").getComponent("cc.Camera");
- Camera.addTarget(node);
- }
- else if (javetemp_Hero != null) {
- var Camera = cc.find("javetemp_Hero").getChildByName("CameraNode").getComponent("cc.Camera");
- Camera.addTarget(node);
- }
- },
-
- resetHero: function (data) {
- var Hero = cc.find('Hero');
- var Rivel = cc.find('Rivel');
- var HeroHeroControl = Hero.getComponent("HeroControl");
- var RivelHeroControl = Rivel.getComponent("HeroControl");
- HeroHeroControl.SetSpeedToZeroAndIdle();
- RivelHeroControl.SetSpeedToZeroAndIdle();
- HeroHeroControl.javelinTag = false;
- RivelHeroControl.javelinTag = false;
- Hero.getChildByName('Player').stopAllActions();
- Rivel.getChildByName('Player').stopAllActions();
- Hero.getChildByName('Player').setPositionY(-132);
- Rivel.getChildByName('Player').setPositionY(-37);
- HeroHeroControl.CameraNode.parent = Hero;
- RivelHeroControl.isJumpOver = true;
- HeroHeroControl.isJumpOver = true;
- //重置人物踉跄判定
- var PlayerStateScript = Rivel.getComponent("PlayerState");
- PlayerStateScript.CurrentInZoneType = PlayerStateStatic.ZoneType.None;
- PlayerStateScript.BTouchedScreenInTheZone = false;
- PlayerStateScript.BStagger = false;
- if (data != null) {
- Hero.setPositionX(data.node.x + 700);
- Rivel.setPositionX(data.node.x + 730);
- }
- },
- });
|