123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741 |
- import { ui } from "../ui/layaMaxUI";
- import { GameTools } from "../Tool/GameTools";
- import { SC } from "./ViewManager";
- import { EventManager, PropEffecf,StageMode } from "../Tool/EventManager";
- import { AccountManager } from "../Net/AccountManager";
- import Ball from "../Main/Ball";
- import { GameManager } from "../Main/GameManager";
- import { DropRule } from "../Tool/DropRule";
- import { ServerManager, BlastToMerge } from "../Net/ServerManager";
- import { GamePool } from "../Tool/GamePool";
- import Gift from "../Main/Gift";
- export default class InGameView extends ui.InGameSceneUI implements SC{
- private static ins:InGameView;
- //本关卡
- public STAGE:number;
- //是否弹出失败界面
- public LoseView = false;
- //是否弹出成功界面
- public WinView = false;
- //球是否溢出
- public OverRun = false;
- //0.25时是否掉落礼盒
- public lingdianerwu = false;
- //0.50时是否掉落礼盒
- public lingdianwu = false;
- //0.75时是否掉落礼盒
- public lingdianqiwu = false;
- constructor(){
- super();
- InGameView.ins = this;
- EventManager.StageOn(StageMode.Clone,this,this.AddPrefab);
- EventManager.StageOn(StageMode.Win,this,this.Win);
- EventManager.StageOn(StageMode.Lose,this,this.Lose);
- EventManager.StageOn(StageMode.ReStart,this,this.ReStart);
- EventManager.StageOn(StageMode.Over,this,this.Over);
- EventManager.StageOn(StageMode.Revive,this,this.Revive);
- EventManager.StageOn(StageMode.Check,this,this.Check);
- // EventManager.StageOn(StageMode.GetReward,this,this)
- }
- public static get Instance():InGameView{
- if(InGameView.ins){
- return InGameView.ins
- }
- else{
- return new InGameView();
- }
- }
- Show(){
- let stage = AccountManager.Instance.curplayerData.GainAccount("stage");
- this.STAGE = Number(stage);
- Laya.timer.loop(AccountManager.Instance.curplayerData.Save * 1000,this,this.Save);
- Laya.timer.once(200,this,this.SkillRefresh);
- Laya.timer.frameLoop(2,this,this.CheckHeight);
- Laya.timer.frameLoop(1,this,this.Progress);
- Laya.timer.once(AccountManager.Instance.curplayerData.CheckLose * 1000,this,this.CheckLose);
- Laya.timer.frameLoop(500,this,this.SkillAnimation);
- this.ScoreRefresh();
- this.SkillNumRefresh();
- this.arrowbtn.clickHandler = new Laya.Handler(this,this.ClickArrow);
- this.zhunxin1btn.clickHandler = new Laya.Handler(this,this.ClickZhunXin1);
- this.zhunxin2btn.clickHandler = new Laya.Handler(this,this.ClickZhunXin2);
- this.doublebtn.clickHandler = new Laya.Handler(this,this.ClickDouble);
- this.hammerbtn.clickHandler = new Laya.Handler(this,this.ClickHammer);
- this.height = Laya.stage.height;
- this.BG.height = Laya.stage.height;
- Laya.stage.on(Laya.Event.RESIZE,this,()=>
- {
- this.height = Laya.stage.height;
- this.BG.height = Laya.stage.height;
- })
- }
- //失败检测
- Check(){
- Laya.timer.clear(this,this.CheckLose);
- Laya.timer.once(AccountManager.Instance.curplayerData.CheckLose * 1000,this,this.CheckLose);
- }
- //添加预设
- AddPrefab(ball){
- this.prefabbox.addChild(ball);
- }
- //检测高度
- CheckHeight(){
- if(GameManager.Instance.CheckHeight){
- let down = false;
- this.OverRun = false;
- for (let i = 0; i < this.prefabbox.numChildren; i++) {
- let child = this.prefabbox.getChildAt(i) as Laya.Image;
- if(child.y < DropRule.Instance.DropHeight){
- down = true;
- }
- if(child.y < AccountManager.Instance.curplayerData.OverRun){
- this.OverRun = true;
- }
- }
- if(!down){
- DropRule.Instance.FallDown();
- }
- }
-
- }
- //检测是否游戏失败
- CheckLose(){
- if(!this.LoseView){
- let lose = true;
- for (let i = 0; i < this.prefabbox.numChildren; i++) {
- let ball = this.prefabbox.getChildAt(i) as Laya.Image;
- if(ball.name == "Gift" || ball.name == "TimeGift"){
- continue;
- }
- let light = ball.getChildByName("light") as Laya.Image;
- if(light.visible){
- lose = false;
- }
- }
- if(lose){
- this.LoseView = true;
- Laya.timer.clear(this,this.Save);
- this.Save(true);
- EventManager.StageTrigger(StageMode.Lose);
- }
- }
- }
- //开局刷新一下过关要求
- ScoreRefresh(){
- // let level = AccountManager.Instance.curplayerData.GainCollocation("level");
- let score = DropRule.Instance.GoalScore;
- this.NowLv.value = DropRule.Instance.STAGE.toString();
- this.NextLv.value = (DropRule.Instance.STAGE+1).toString();
- this.NowScore.text = GameManager.Instance.ScoreProgress.toString();
- this.RequireScore.text = score.toString();
- // let stage = level[GameManager.Instance.STAGE];
- // score = Number(stage.goal);
- // let id =Number(stage.id) ;
- // this.NowLv.value = id.toString();
- // this.NextLv.value = (id+1).toString();
- // this.NowScore.text = GameManager.Instance.ScoreProgress.toString();
- // this.RequireScore.text = score.toString();
- }
- //进入游戏时刷新一下道具数量
- SkillNumRefresh(){
- this.Func1num.text = AccountManager.Instance.curplayerData.GetPropNum(1).toString();
- this.Func2num.text = AccountManager.Instance.curplayerData.GetPropNum(2).toString();
- this.Func3num.text = AccountManager.Instance.curplayerData.GetPropNum(3).toString();
- this.Func4num.text = AccountManager.Instance.curplayerData.GetPropNum(4).toString();
- this.Func5num.text = AccountManager.Instance.curplayerData.GetPropNum(5).toString();
- }
- //进入游戏时刷新一下技能icon
- SkillRefresh(){
- this.ani1.play(null,false);
- this.ani2.play(null,false);
- this.ani3.play(null,false);
- this.ani4.play(null,false);
- this.ani5.play(null,false);
- }
- //技能图标动画效果
- SkillAnimation() {
- let random = GameTools.RandomANumber(1, 6);
- switch (random) {
- case 1:
- this.ani1.play(null, false);
- break;
- case 2:
- this.ani2.play(null, false);
- break;
- case 3:
- this.ani3.play(null, false);
- break;
- case 4:
- this.ani4.play(null, false);
- break;
- case 5:
- this.ani5.play(null, false);
- break;
- }
- }
- //比例
- private get Ratio():number{
- let score = DropRule.Instance.GoalScore;
- let value = GameManager.Instance.ScoreProgress/score;
-
- return value;
- }
- //进度条
- Progress(){
- if(!this.WinView){
- this.LevelProgress.value = this.Ratio;
- if(GameManager.Instance.ScoreProgress>=Number(this.RequireScore.text)){
- GameManager.Instance.ScoreProgress = Number(this.RequireScore.text);
- this.NowScore.text = GameManager.Instance.ScoreProgress.toString();
- Laya.timer.clear(this,this.Save);
- Laya.timer.clear(this,this.CheckLose);
- this.Save(true);
- EventManager.StageTrigger(StageMode.Win);
- this.WinView = true;
- }
- this.NowScore.text = GameManager.Instance.ScoreProgress.toString();
- }
- if(DropRule.Instance.STAGE >= 7){
- let X = GameTools.RandomANumber(100,500);
- let pos = new Laya.Vector2(X, 10);
- if(this.Ratio >= 0.25 && this.Ratio < 0.5 && !this.lingdianerwu){
- DropRule.Instance.CreateGift(1,pos,DropRule.Instance.JudgePropNum(),1);
- this.lingdianerwu = true;
- }
- if(this.Ratio >= 0.5 && this.Ratio < 0.75 && !this.lingdianwu){
- DropRule.Instance.CreateGift(1,pos,DropRule.Instance.JudgePropNum(),1);
- this.lingdianwu = true;
- }
- if(this.Ratio >= 0.75 && this.Ratio < 1 && !this.lingdianqiwu){
- DropRule.Instance.CreateGift(1,pos,DropRule.Instance.JudgePropNum(),1);
- this.lingdianqiwu =true;
- }
- }
-
- }
- //推球道具
- ClickArrow(){
- console.log("点到了推球道具--");
- // var agrs = [{ "t": AccountManager.Instance.ServerTime.toString() }];
- // ServerManager.Instance.SendHttp(BlastToMerge.KaiShi,agrs,Laya.Handler.create(this, this.StartNextLevel), null);
- if(Number(this.Func5num.text)>0){
- let args = [{"t":AccountManager.Instance.ServerTime.toString()},{"play_id":GameManager.Instance.play_id},{"fid":"5"}]
- ServerManager.Instance.SendHttp(BlastToMerge.Use,args,Laya.Handler.create(this,(res)=>{
- for (let i = 0; i < this.prefabbox.numChildren; i++) {
- let ball = this.prefabbox.getChildAt(i) as Laya.Image;
- if(ball.destroyed){
- continue
- }
- else{
- let _rig = ball.getComponent(Laya.RigidBody) as Laya.RigidBody;
- _rig.applyLinearImpulseToCenter({x:0,y:-AccountManager.Instance.curplayerData.AddForce});
- }
- }
- this.SkillNumRefresh();
- }),Laya.Handler.create(this,(res)=>{
- console.log(res);
- }))
- }
- }
- //双倍道具
- ClickDouble(){
- if(Number(this.Func1num.text)>0){
- if(EventManager.PropState == PropEffecf.NONE){
- this.EffectMode(true,PropEffecf.DOUBLE);
- }
- else{
- this.EffectMode(false);
- }
- }
- // if(EventManager.PropState == PropEffecf.DOUBLE){
- // EventManager.EventTrigger(PropEffecf.NONE);
- // console.log("切换为普通模式");
- // return;
- // }
- // if(EventManager.PropState != PropEffecf.NONE){
- // this.EffectMode(false);
- // return;
- // }
- // if(Number(this.Func1num.text)>0){
- // EventManager.EventTrigger(PropEffecf.DOUBLE);
- // console.log("切换为双倍模式");
- // }
- }
- //消除最小的球道具
- ClickZhunXin1(){
- console.log("点到了准心1道具--");
-
- if(Number(this.Func2num.text)>0){
- if(EventManager.PropState == PropEffecf.NONE){
- this.EffectMode(true,PropEffecf.CLEARLAST);
- }
- else{
- this.EffectMode(false);
- }
- }
- }
- //消除次小的球道具
- ClickZhunXin2(){
- console.log("点到了准心2道具--");
-
- if(Number(this.Func3num.text)>0){
- if(EventManager.PropState == PropEffecf.NONE){
- this.EffectMode(true,PropEffecf.CLEARTWO);
- }
- else{
- this.EffectMode(false);
- }
- }
- }
- //锤子道具
- ClickHammer(){
- console.log("点到了锤子道具--");
- if(Number(this.Func4num.text)>0){
- if(EventManager.PropState == PropEffecf.NONE){
- this.EffectMode(true,PropEffecf.HAMMER);
- }
- else{
- this.EffectMode(false);
- }
- }
- }
- //使用道具
- EffectMode(_open:boolean,_type:PropEffecf = null){
- this.Effect.visible = _open;
- if (_open) {
- EventManager.PropState = _type;
- let describe3 = this.Effect.getChildByName("describe3") as Laya.Text;
- let describe2 = this.Effect.getChildByName("describe2") as Laya.Text;
- let describe = this.Effect.getChildByName("describe") as Laya.Text;
- let icon = this.Effect.getChildByName("ICON") as Laya.Image;
- switch (_type) {
- case PropEffecf.CLEARLAST:
- this.EffectBtn.visible = true;
- describe.visible = true;
- describe2.visible = false;
- describe3.visible = false;
- icon.visible = true;
- icon.skin = this.GetIcon(DropRule.Instance.MinBall);
- this.ClearNum.text = DropRule.Instance.MinBall.toString();
- this.EffectBtn.clickHandler = Laya.Handler.create(this, this.ClearLast);
- break;
- case PropEffecf.CLEARTWO:
- this.EffectBtn.visible = true;
- describe.visible = true;
- describe2.visible = false;
- describe3.visible = false;
- icon.visible = true;
- icon.skin = this.GetIcon(DropRule.Instance.MinNextBall);
- this.ClearNum.text = DropRule.Instance.MinNextBall.toString();
- this.EffectBtn.clickHandler = Laya.Handler.create(this, this.ClearTwo);
- break;
- case PropEffecf.HAMMER:
- this.EffectBtn.visible = false;
- describe.visible = false;
- describe2.visible = true;
- describe3.visible = false;
- icon.visible = false;
- EventManager.EventTrigger(PropEffecf.HAMMER);
- break;
- case PropEffecf.DOUBLE:
- this.EffectBtn.visible = false;
- describe.visible = false;
- describe2.visible = false;
- describe3.visible = true;
- icon.visible = false;
- EventManager.EventTrigger(PropEffecf.DOUBLE);
- break;
- }
- }
- else{
- EventManager.PropState = PropEffecf.NONE;
- this.EffectBtn.clickHandler = null;
- }
- }
- //清除场景中最小的球
- ClearLast(){
- var args = [{"t":AccountManager.Instance.ServerTime.toString()},{"play_id":GameManager.Instance.play_id},{"fid":"2"}]
- ServerManager.Instance.SendHttp(BlastToMerge.Use,args,Laya.Handler.create(this,()=>{
- for (let i = this.prefabbox.numChildren-1; i >-1 ; i--) {
- let prefab = this.prefabbox.getChildAt(i) as Laya.Image;
- if(prefab.name == "Gift" || prefab.name == "TimeGift"){
- continue;
- }
- let ball = prefab.getComponent(Ball) as Ball;
- if(ball.score == DropRule.Instance.MinBall){
- GameManager.Instance.ScoreProgress += ball.score;
- DropRule.Instance.CreateEffect(ball.score,new Laya.Vector2(prefab.x,prefab.y));
- let _rig = prefab.getComponent(Laya.RigidBody) as Laya.RigidBody;
- let _collider = prefab.getComponent(Laya.CircleCollider) as Laya.CircleCollider;
- _collider.enabled = false;
- _rig.enabled = false;
- // _collider.destroy();
- // _rig.destroy();
- Laya.timer.clearAll(prefab);
- prefab.removeSelf();
- // prefab.destroy();
- let _index = DropRule.Instance.GetBallIndex(ball.score);
- GamePool.Instance.RecoverModel(prefab,_index.toString());
- // Laya.Pool.recover("img"+_index.toString,ball);
- }
- }
- this.SkillNumRefresh();
- this.Effect.visible = false;
- this.EffectBtn.clickHandler = null;
- EventManager.PropState = PropEffecf.NONE;
- }),Laya.Handler.create(this,()=>{
- console.log("道具使用失败");
- }))
- }
- //清除场景中第二小的球
- ClearTwo(){
- var args = [{"t":AccountManager.Instance.ServerTime.toString()},{"play_id":GameManager.Instance.play_id},{"fid":"3"}]
- ServerManager.Instance.SendHttp(BlastToMerge.Use,args,Laya.Handler.create(this,()=>{
- for (let i = this.prefabbox.numChildren-1; i >-1 ; i--) {
- let prefab = this.prefabbox.getChildAt(i) as Laya.Image;
- if(prefab.name == "Gift" || prefab.name == "TimeGift"){
- continue;
- }
- let ball = prefab.getComponent(Ball) as Ball;
- if(ball.score == DropRule.Instance.MinNextBall){
- GameManager.Instance.ScoreProgress += ball.score;
- DropRule.Instance.CreateEffect(ball.score,new Laya.Vector2(prefab.x,prefab.y));
- let _rig = prefab.getComponent(Laya.RigidBody) as Laya.RigidBody;
- let _collider = prefab.getComponent(Laya.CircleCollider) as Laya.CircleCollider;
- _collider.enabled = false;
- _rig.enabled = false;
- // _collider.destroy();
- // _rig.destroy();
- Laya.timer.clearAll(prefab);
- prefab.removeSelf();
- // prefab.destroy();
- let _index = DropRule.Instance.GetBallIndex(ball.score);
- GamePool.Instance.RecoverModel(prefab,_index.toString());
- // Laya.Pool.recover("img"+_index.toString,ball);
- // ball.destroy();
- }
- }
- this.SkillNumRefresh();
- this.Effect.visible = false;
- this.EffectBtn.clickHandler = null;
- EventManager.PropState = PropEffecf.NONE;
- }),null)
- }
- /**传入分数 获取球的icon */
- GetIcon(_score:number):string{
- let index;
- for (let i = 0; i < DropRule.Instance.PrefabName.length; i++) {
- if(_score == Number(DropRule.Instance.PrefabName[i])){
- index = i.toString();
- }
- }
- return "Game/res/Ball/blast"+ index + ".png"
- }
- //清除舞台上的球
- ClearStage(){
- if(!this.prefabbox.destroyed){
- for (let i = this.prefabbox.numChildren-1; i > -1; i--) {
- let prefab = this.prefabbox.getChildAt(i) as Laya.Image;
- if(prefab.name == "Gift" || prefab.name == "TimeGift"){
- let giftscript = prefab.getComponent(Gift) as Gift;
- let _rig = prefab.getComponent(Laya.RigidBody) as Laya.RigidBody;
- let _collider = prefab.getComponent(Laya.CircleCollider) as Laya.CircleCollider;
- _collider.enabled = false;
- _rig.enabled = false;
- _collider.destroy();
- _rig.destroy();
- Laya.timer.clearAll(prefab);
- prefab.removeSelf();
- let name = giftscript.type == 0?"Gift":"TimeGift";
- GamePool.Instance.RecoverModel(prefab,name);
- continue;
- }
- let ball = prefab.getComponent(Ball) as Ball;
- let _rig = prefab.getComponent(Laya.RigidBody) as Laya.RigidBody;
- let _collider = prefab.getComponent(Laya.CircleCollider) as Laya.CircleCollider;
- _collider.enabled = false;
- _rig.enabled = false;
- _collider.destroy();
- _rig.destroy();
- Laya.timer.clearAll(prefab);
- prefab.removeSelf();
- let _index = DropRule.Instance.GetBallIndex(ball.score);
- GamePool.Instance.RecoverModel(prefab,_index.toString());
- // Laya.Pool.recover("img"+_index.toString,ball);
- }
- }
- }
- //游戏结束
- Over(){
- this.ClearStage();
- EventManager.StageOff(StageMode.Clone,this,this.AddPrefab);
- EventManager.StageOff(StageMode.Win,this,this.Win);
- EventManager.StageOff(StageMode.Lose,this,this.Lose);
- EventManager.StageOff(StageMode.ReStart,this,this.ReStart);
- EventManager.StageOff(StageMode.Over,this,this.Over);
- EventManager.StageOff(StageMode.Revive,this,this.Revive);
- EventManager.StageOff(StageMode.Check,this,this.Check);
- //清除碰撞器
- this.ClearCollider(this.BottomCollider);
- this.ClearCollider(this.RightCollider);
- this.ClearCollider(this.LeftCollider);
- }
- //复活
- Revive(){
- for (let i = this.prefabbox.numChildren-1; i >-1 ; i--) {
- let prefab = this.prefabbox.getChildAt(i) as Laya.Image;
- if(prefab.name == "Gift" || prefab.name == "TimeGift"){
- continue;
- }
- let ball = prefab.getComponent(Ball) as Ball;
- for (let j = 0; j < DropRule.Instance.BallNum.length; j++) {
- let Score = DropRule.Instance.GetBallIndex(ball.score);
- if(Score+1 ==Number(DropRule.Instance.BallNum[j]) ){
- DropRule.Instance.CreateEffect(ball.score,new Laya.Vector2(prefab.x,prefab.y));
- let _rig = prefab.getComponent(Laya.RigidBody) as Laya.RigidBody;
- let _collider = prefab.getComponent(Laya.CircleCollider) as Laya.CircleCollider;
- _collider.enabled = false;
- _rig.enabled = false;
- // _collider.destroy();
- // _rig.destroy();
- Laya.timer.clearAll(prefab);
- prefab.removeSelf();
- // prefab.destroy();
- let _index = DropRule.Instance.GetBallIndex(ball.score);
- GamePool.Instance.RecoverModel(prefab,_index.toString());
- // Laya.Pool.recover("img"+_index.toString,prefab);
- }
- }
- }
- Laya.timer.frameLoop(2,this,this.CheckHeight);
- Laya.timer.once(500,this,()=>{
- this.LoseView = false;
- })
- }
- //游戏胜利
- Win(){
- Laya.timer.clear(this,this.CheckHeight);
- }
- //游戏失败
- Lose(){
- Laya.timer.clear(this,this.CheckHeight);
- }
- //再来一局
- ReStart(_data?){
- if(_data){
- for (let i = this.prefabbox.numChildren-1; i >-1 ; i--) {
- let prefab = this.prefabbox.getChildAt(i) as Laya.Image;
- if(prefab.name == "Gift" || prefab.name == "TimeGift"){
- continue;
- }
- let ball = prefab.getComponent(Ball) as Ball;
- for (let j = 0; j < DropRule.Instance.BallNum.length; j++) {
- let Score = DropRule.Instance.GetBallIndex(ball.score);
- if(Score+1 == Number(DropRule.Instance.BallNum[j]) ){
- DropRule.Instance.CreateEffect(ball.score,new Laya.Vector2(prefab.x,prefab.y));
- let _rig = prefab.getComponent(Laya.RigidBody) as Laya.RigidBody;
- let _collider = prefab.getComponent(Laya.CircleCollider) as Laya.CircleCollider;
- _collider.enabled = false;
- _rig.enabled = false;
- // _collider.destroy();
- // _rig.destroy();
- Laya.timer.clearAll(prefab);
- prefab.removeSelf();
- // prefab.destroy();
- let _index = DropRule.Instance.GetBallIndex(ball.score);
- GamePool.Instance.RecoverModel(prefab,_index.toString());
- // Laya.Pool.recover("img"+_index.toString,prefab);
- }
- }
- }
- //过关时消除本关 前四位之后的球
- let ballarray = this.PassDeal;
- if(ballarray.length > 4){
- let ballarray2 = [];
- for (let m = 0; m < 4; m++) {
- ballarray2.push(ballarray[m]);
- }
- for (let k = this.prefabbox.numChildren-1; k > -1; k--) {
- let prefab = this.prefabbox.getChildAt(k) as Laya.Image;
- if(prefab.name == "Gift" || prefab.name == "TimeGift"){
- continue;
- }
- let ball = prefab.getComponent(Ball) as Ball;
- let dispear = true;
- for (let l = 0; l < ballarray2.length; l++) {
- if(ball.score == ballarray2[l]){
- dispear = false;
- }
- }
- if(dispear){
- DropRule.Instance.CreateEffect(ball.score,new Laya.Vector2(prefab.x,prefab.y));
- let _rig = prefab.getComponent(Laya.RigidBody) as Laya.RigidBody;
- let _collider = prefab.getComponent(Laya.CircleCollider) as Laya.CircleCollider;
- _collider.enabled = false;
- _rig.enabled = false;
- // _collider.destroy();
- // _rig.destroy();
- Laya.timer.clearAll(prefab);
- prefab.removeSelf();
- // prefab.destroy();
- let _index = DropRule.Instance.GetBallIndex(ball.score);
- GamePool.Instance.RecoverModel(prefab,_index.toString());
- // Laya.Pool.recover("img"+_index.toString,prefab);
- }
- }
- }
- Laya.timer.loop(5000,this,this.Save);
- this.WinView = false;
- this.lingdianerwu = false;
- this.lingdianwu = false;
- this.lingdianqiwu = false;
- this.ScoreRefresh();
- this.Progress();
- DropRule.Instance.FallDown(DropRule.Instance.StartNum);
- Laya.timer.frameLoop(2,this,this.CheckHeight);
- }
- else{
- this.ClearStage();
- this.LoseView = false;
- this.WinView = false;
- this.lingdianerwu = false;
- this.lingdianwu = false;
- this.lingdianqiwu = false;
- this.ScoreRefresh();
- this.Progress();
- if(DropRule.Instance.STAGE == 1){
- this.Guide.visible = false;
- GameManager.Instance.Wave = 1;
- DropRule.Instance.GuideFallDown();
- GameManager.Instance.CheckHeight = false;
- }
- else{
- DropRule.Instance.FallDown(DropRule.Instance.StartNum);
- }
- Laya.timer.frameLoop(2,this,this.CheckHeight);
- }
- }
- //清除碰撞器
- ClearCollider(_node:Laya.Image){
- let collier = _node.getComponent(Laya.ChainCollider) as Laya.ChainCollider;
- let rig = _node.getComponent(Laya.RigidBody) as Laya.RigidBody;
- if(collier){
- collier.enabled = false;
- }
- if(rig){
- rig.enabled = false;
- }
- if(_node){
- _node.removeSelf();
- _node.destroy();
- }
- }
- Close(){
- Laya.timer.clearAll(this);
- }
- //过关时消除 除了本关排名前四的球
- public get PassDeal():number[]{
- let array = [];
- let array2 = [];
- for (let i = 0; i < this.prefabbox.numChildren; i++) {
- let prefab = this.prefabbox.getChildAt(i) as Laya.Image;
- if(prefab.name == "Gift" || prefab.name == "TimeGift"){
- continue;
- }
- let ball = prefab.getComponent(Ball) as Ball;
- if(array.length == 0){
- array.push(ball.score);
- }
- if(i>0){
- let add = true;
- for (let j = 0; j < array.length; j++) {
- if(ball.score == array[j]){
- add = false;
- }
- }
- if(add){
- array.push(ball.score);
- }
- }
- }
- if(array.length>4){
- for (let k = 0; k < array.length; k++) {
- for (let l = 0; l < array.length - k -1; l++) {
- if(array[l] < array[l+1]){
- let temp = array[l];
- array[l] = array[l+1];
- array[l+1] = temp;
- }
- }
- }
- }
- return array;
- }
- //保存关卡进度
- Save(_data?){
- let type;
- let proptype;
- let propnum;
-
- let str = "";
- let ball;
- let score;
- let size;
- let index;
- let point;
- let obj = {};
- let objarray = [];
- if(!_data){
- for (let i = 0; i < this.prefabbox.numChildren; i++) {
- let prefab = this.prefabbox.getChildAt(i) as Laya.Image;
- if(prefab.name == "ball"){
- ball = prefab.getComponent(Ball) as Ball;
- //分数
- score = ball.score;
- index =(DropRule.Instance.GetBallIndex(score) + 1).toString();
- //尺寸
- size = prefab.width.toString();
- //坐标
- point = new Laya.Vector2(prefab.x,prefab.y);
- obj = {"index":index,"size":size,"pos":point,"itemtype":0};//itemtype 0为球 1为礼盒
- }
- else if(prefab.name == "Gift"){
- let giftscript = prefab.getComponent(Gift) as Gift;
- type = giftscript.type;
- proptype = giftscript.GiftIndex;
- propnum = giftscript.GiftNum;
- point = new Laya.Vector2(prefab.x,prefab.y);
- obj = {"type":type,"proptype":proptype,"propnum":propnum,"pos":point,"itemtype":1};//itemtype 0为球 1为礼盒
- }
- objarray.push(obj);
- }
- let jindutiao = {"jindu":GameManager.Instance.ScoreProgress.toString()};
- let sizeindex = {"sizeindex":DropRule.Instance.SizeIndex};
- let edgeindex = {"edgeindex":DropRule.Instance.EdgeIndex};
- objarray.push(edgeindex);
- objarray.push(jindutiao);
- objarray.push(sizeindex);
- var progress = JSON.stringify(objarray);
- var args =[{"stage":DropRule.Instance.STAGE.toString()},{"progress":progress}]
- }
- else{
- obj = {"0":"0"};
- objarray.push(obj);
- var progress = JSON.stringify(objarray);
- var args =[{"stage":DropRule.Instance.STAGE.toString()},{"progress":progress}]
- }
- ServerManager.Instance.SendHttp(BlastToMerge.Save,args,Laya.Handler.create(this,(res)=>{
- }),Laya.Handler.create(this,()=>{
- console.log("保存进度失败++");
- }))
- }
- }
|