فهرست منبع

增加球球之间可消除的距离功能

zhaochengyang 5 سال پیش
والد
کامیت
007abb619a

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 16
.rpt2_cache/rpt2_cf2924d0eb4f747a182343e97cccc0e2a0448a4b/code/cache/0264d5bb4bd2c2e151b87f758b9d4130947b4ec8


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 13
.rpt2_cache/rpt2_cf2924d0eb4f747a182343e97cccc0e2a0448a4b/code/cache/628f73df3ce19389f129eaa40b09a3ba18311711


+ 28 - 98
bin/js/bundle.js

@@ -1492,7 +1492,7 @@ var laya = (function (exports) {
             ball.width = size;
             let collider = ball.addComponent(Laya.CircleCollider);
             collider.restitution = AccountManager.Instance.curplayerData.Restitution;
-            collider.radius = size / 2 + 1.5;
+            collider.radius = size / 2;
             console.log("碰撞器半径--", collider.radius, size);
             let rig = ball.addComponent(Laya.RigidBody);
             rig.gravityScale = 3;
@@ -1537,7 +1537,7 @@ var laya = (function (exports) {
             if (this.STAGE == 1 && GameManager.Instance.Wave < 3) {
                 collider.restitution = 0;
             }
-            collider.radius = size / 2 + 1.5;
+            collider.radius = size / 2;
             let rig = ball.addComponent(Laya.RigidBody);
             rig.allowRotation = true;
             rig.gravityScale = 3;
@@ -1748,7 +1748,6 @@ var laya = (function (exports) {
     class Ball extends Laya.Script {
         constructor() {
             super();
-            this.TargetArray = [];
             this.moved = false;
             this.mark = false;
             this.clear = false;
@@ -1775,7 +1774,7 @@ var laya = (function (exports) {
         }
         onUpdate() {
             this.CheckLight();
-            if (this.clear) {
+            if (this.mark) {
                 let _rig = this.owner.getComponent(Laya.RigidBody);
                 let _collider = this.owner.getComponent(Laya.CircleCollider);
                 _collider.isSensor = true;
@@ -1786,24 +1785,21 @@ var laya = (function (exports) {
             }
         }
         CheckLight() {
-            if (this.TargetArray.length > 0) {
-                let num = 0;
-                for (let i = 0; i < this.TargetArray.length; i++) {
-                    let ball = this.TargetArray[i];
-                    if (ball.destroyed) {
-                        num++;
-                    }
-                }
-                if (num == this.TargetArray.length) {
-                    this.Light.visible = false;
+            let _node = this.owner;
+            for (let i = 0; i < InGameView.Instance.prefabbox.numChildren; i++) {
+                let other = InGameView.Instance.prefabbox.getChildAt(i);
+                let ball = other.getComponent(Ball);
+                if (other.x == _node.x && other.y == _node.y) {
+                    continue;
                 }
-                else {
-                    this.Light.visible = true;
+                let distan = Laya.Vector3.distance(new Laya.Vector3(other.x, other.y, 0), new Laya.Vector3(_node.x, _node.y, 0));
+                let dis = _node.width / 2 + other.width / 2;
+                if (Math.abs(distan - dis) <= 3 || Math.abs(distan - dis) <= 3) {
+                    if (ball.score == this.score) {
+                        this.Light.visible = true;
+                    }
                 }
             }
-            else {
-                this.Light.visible = false;
-            }
         }
         ClickNone() {
             this.owner.off(Laya.Event.CLICK, this, this.Hammer);
@@ -1867,49 +1863,6 @@ var laya = (function (exports) {
             EventManager.EventOff(PropEffecf.NONE, this, this.ClickNone);
             EventManager.EventOff(PropEffecf.HAMMER, this, this.ClickHammer);
         }
-        onTriggerEnter(other) {
-            let targetparent = other.owner;
-            if (DropRule.Instance.STAGE == 1 && GameManager.Instance.Wave < 3) {
-                if (targetparent.name == "BottomCollider" && this.Light.visible == true) {
-                    if (DropRule.Instance.STAGE == 1 && GameManager.Instance.Wave < 3) {
-                        if (!InGameView.Instance.guide.isPlaying && !GameManager.Instance.played) {
-                            InGameView.Instance.guide.play(null, false);
-                            GameManager.Instance.played = true;
-                        }
-                        InGameView.Instance.Guide.visible = true;
-                    }
-                }
-            }
-            if (targetparent.name != "RightCollider" && targetparent.name != "LeftCollider" && targetparent.name != "BottomCollider") {
-                let num = targetparent.getChildByName("num");
-                let ownernum = this.owner.getChildByName("num");
-                if (Number(num.value) == Number(ownernum.value)) {
-                    this.TargetArray.push(targetparent);
-                }
-            }
-        }
-        onTriggerStay(other) {
-            let targetparent = other.owner;
-            if (targetparent.name != "RightCollider" && targetparent.name != "LeftCollider" && targetparent.name != "BottomCollider") {
-                let num = targetparent.getChildByName("num");
-                let ownernum = this.owner.getChildByName("num");
-                if (Number(num.value) == Number(ownernum.value)) {
-                    this.TargetArray.push(targetparent);
-                }
-            }
-        }
-        onTriggerExit(other) {
-            let targetparent = other.owner;
-            if (targetparent && !targetparent.destroyed) {
-                if (targetparent.name != "RightCollider" && targetparent.name != "LeftCollider" && targetparent.name != "BottomCollider") {
-                    for (let i = this.TargetArray.length - 1; i > -1; i--) {
-                        if (this.TargetArray[i] == targetparent) {
-                            this.TargetArray.splice(i, 1);
-                        }
-                    }
-                }
-            }
-        }
         Move(_position) {
             if (!this.moved) {
                 let owner = this.owner;
@@ -1952,54 +1905,31 @@ var laya = (function (exports) {
         }
         ClickBall() {
             let owner = this.owner;
-            for (let j = this.TargetArray.length - 1; j > -1; j--) {
-                if (this.TargetArray[j].destroyed || this.TargetArray[j] == null) {
-                    this.TargetArray.splice(j, 1);
-                }
-            }
-            for (let i = 0; i < this.TargetArray.length; i++) {
-                let num = this.TargetArray[i].getChildByName("num");
-            }
             DropRule.Instance.Cloned = false;
             GameManager.Instance.TargetPosition = new Vector2(owner.x, owner.y);
-            this.DisPose(owner);
-        }
-        DisPose(_node) {
-            let ball = _node.getComponent(Ball);
-            if (ball.TargetArray.length > 0) {
-                if (!ball.mark) {
-                    ball.mark = true;
-                }
-                ball.clear = true;
-                for (let i = 0; i < ball.TargetArray.length; i++) {
-                    if (ball.TargetArray[i].getComponent(Ball).mark)
-                        continue;
-                    ball.TargetArray[i].getComponent(Ball).mark = true;
-                    ball.TargetArray[i].getComponent(Ball).clear = true;
-                    let target = ball.TargetArray[i];
-                    let ball2 = target.getComponent(Ball);
-                    if (ball2.TargetArray.length > 0) {
-                        for (let j = 0; j < ball2.TargetArray.length; j++) {
-                            if (ball2.TargetArray[j] == _node) {
-                                continue;
-                            }
-                            ball2.clear = true;
-                            ball2.mark = true;
-                            this.DisPose(ball2.TargetArray[j]);
-                        }
-                    }
-                }
-            }
+            this.MouseClick(owner);
         }
         MouseClick(_node) {
+            let _nodeball = _node.getComponent(Ball);
             for (let i = 0; i < InGameView.Instance.prefabbox.numChildren; i++) {
                 let other = InGameView.Instance.prefabbox.getChildAt(i);
+                let ball = other.getComponent(Ball);
                 if (other.x == _node.x && other.y == _node.y) {
                     continue;
                 }
+                if (ball.mark) {
+                    continue;
+                }
+                let distan = Laya.Vector3.distance(new Laya.Vector3(other.x, other.y, 0), new Laya.Vector3(_node.x, _node.y, 0));
                 let distanceX = Math.abs(_node.x - other.x);
                 let distanceY = Math.abs(_node.y - other.y);
                 let dis = _node.width / 2 + other.width / 2;
+                if (Math.abs(distan - dis) <= 3 || Math.abs(distan - dis) <= 3) {
+                    if (ball.score == _nodeball.score) {
+                        ball.mark = true;
+                        this.MouseClick(other);
+                    }
+                }
             }
         }
     }

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
bin/js/bundle.js.map


+ 140 - 118
src/Main/Ball.ts

@@ -14,7 +14,7 @@ export  default class Ball extends Laya.Script{
     private _rig:Laya.RigidBody;
     //光圈
     public Light:Laya.Image;
-    public TargetArray = [];
+    // public TargetArray = [];
     //是否已经移动
     private  moved = false;
     //该球是否已被标记
@@ -49,7 +49,7 @@ export  default class Ball extends Laya.Script{
     
     onUpdate(){
         this.CheckLight();
-        if(this.clear){
+        if(this.mark){
             let _rig = this.owner.getComponent(Laya.RigidBody) as Laya.RigidBody;
             let _collider = this.owner.getComponent(Laya.CircleCollider) as Laya.CircleCollider;
             _collider.isSensor = true;
@@ -61,24 +61,39 @@ export  default class Ball extends Laya.Script{
     }
     //判断光效开关
     CheckLight(){
-        if(this.TargetArray.length>0){
-            let num = 0;
-            for (let i = 0; i < this.TargetArray.length; i++) {
-                let ball = this.TargetArray[i] as Laya.Image;
-                if(ball.destroyed){
-                    num ++ ;
-                }
-            }
-            if(num == this.TargetArray.length){
-                this.Light.visible = false;
+        // if(this.TargetArray.length>0){
+        //     let num = 0;
+        //     for (let i = 0; i < this.TargetArray.length; i++) {
+        //         let ball = this.TargetArray[i] as Laya.Image;
+        //         if(ball.destroyed){
+        //             num ++ ;
+        //         }
+        //     }
+        //     if(num == this.TargetArray.length){
+        //         this.Light.visible = false;
+        //     }
+        //     else{
+        //         this.Light.visible = true;
+        //     }
+        // }
+        // else{
+        //     this.Light.visible = false;
+        // }
+        let _node = this.owner as Laya.Image;
+        for (let i = 0; i < InGameView.Instance.prefabbox.numChildren; i++){
+            let other = InGameView.Instance.prefabbox.getChildAt(i) as Laya.Image;
+            let ball = other.getComponent(Ball) as Ball;
+            if(other.x == _node.x && other.y == _node.y){
+                continue
             }
-            else{
-                this.Light.visible = true;
+            let distan =  Laya.Vector3.distance(new Laya.Vector3(other.x,other.y,0),new Laya.Vector3(_node.x,_node.y,0));
+            let dis = _node.width/2 + other.width/2;
+            if(Math.abs(distan-dis)  <=3 || Math.abs(distan-dis) <=3){
+                if(ball.score == this.score){
+                    this.Light.visible = true;
+                }
             }
         }
-        else{
-            this.Light.visible = false;
-        }
     }
     //普通模式
     ClickNone(){
@@ -157,56 +172,56 @@ export  default class Ball extends Laya.Script{
         EventManager.EventOff(PropEffecf.NONE,this,this.ClickNone);
         EventManager.EventOff(PropEffecf.HAMMER,this,this.ClickHammer);
     }
-    onTriggerEnter(other: any) {
-        let targetparent = other.owner;
-        if(DropRule.Instance.STAGE == 1 && GameManager.Instance.Wave<3){
-            if(targetparent.name == "BottomCollider" && this.Light.visible == true){
-                if(DropRule.Instance.STAGE == 1 && GameManager.Instance.Wave<3){
-                    if(!InGameView.Instance.guide.isPlaying && !GameManager.Instance.played){
-                        InGameView.Instance.guide.play(null,false);
-                        GameManager.Instance.played = true;
-                    }
-                    InGameView.Instance.Guide.visible = true;
-                }
-            }
-        }
-        if (targetparent.name != "RightCollider" && targetparent.name != "LeftCollider" && targetparent.name != "BottomCollider") {
-            let num = targetparent.getChildByName("num") as Laya.FontClip;
-            let ownernum = this.owner.getChildByName("num") as Laya.FontClip;
-            if (Number(num.value) == Number(ownernum.value)) {
-                this.TargetArray.push(targetparent);
-            }
-        }
-    }
-    onTriggerStay(other: any) {
-        let targetparent = other.owner;
-        if (targetparent.name != "RightCollider" && targetparent.name != "LeftCollider" && targetparent.name != "BottomCollider") {
-            let num = targetparent.getChildByName("num") as Laya.FontClip;
-            let ownernum = this.owner.getChildByName("num") as Laya.FontClip;
-            if (Number(num.value) == Number(ownernum.value)) {
-                this.TargetArray.push(targetparent);
-            }
-        }
-    }
-    onTriggerExit(other:any){
-        let targetparent = other.owner;
-        // if(targetparent.destroyed){
-        //     for (let i = this.TargetArray.length-1; i > -1; i--) {
-        //         if(this.TargetArray[i] == targetparent){
-        //             this.TargetArray.splice(i,1);
-        //         }
-        //     }
-        // }
-            if(targetparent && !targetparent.destroyed){
-                if(targetparent.name != "RightCollider" && targetparent.name != "LeftCollider" && targetparent.name != "BottomCollider"){
-                    for (let i = this.TargetArray.length-1; i > -1; i--) {
-                        if(this.TargetArray[i] == targetparent){
-                            this.TargetArray.splice(i,1);
-                        }
-                    }
-                }
-            }
-    }
+    // onTriggerEnter(other: any) {
+    //     let targetparent = other.owner;
+    //     if(DropRule.Instance.STAGE == 1 && GameManager.Instance.Wave<3){
+    //         if(targetparent.name == "BottomCollider" && this.Light.visible == true){
+    //             if(DropRule.Instance.STAGE == 1 && GameManager.Instance.Wave<3){
+    //                 if(!InGameView.Instance.guide.isPlaying && !GameManager.Instance.played){
+    //                     InGameView.Instance.guide.play(null,false);
+    //                     GameManager.Instance.played = true;
+    //                 }
+    //                 InGameView.Instance.Guide.visible = true;
+    //             }
+    //         }
+    //     }
+    //     if (targetparent.name != "RightCollider" && targetparent.name != "LeftCollider" && targetparent.name != "BottomCollider") {
+    //         let num = targetparent.getChildByName("num") as Laya.FontClip;
+    //         let ownernum = this.owner.getChildByName("num") as Laya.FontClip;
+    //         if (Number(num.value) == Number(ownernum.value)) {
+    //             this.TargetArray.push(targetparent);
+    //         }
+    //     }
+    // }
+    // onTriggerStay(other: any) {
+    //     let targetparent = other.owner;
+    //     if (targetparent.name != "RightCollider" && targetparent.name != "LeftCollider" && targetparent.name != "BottomCollider") {
+    //         let num = targetparent.getChildByName("num") as Laya.FontClip;
+    //         let ownernum = this.owner.getChildByName("num") as Laya.FontClip;
+    //         if (Number(num.value) == Number(ownernum.value)) {
+    //             this.TargetArray.push(targetparent);
+    //         }
+    //     }
+    // }
+    // onTriggerExit(other:any){
+    //     let targetparent = other.owner;
+    //     // if(targetparent.destroyed){
+    //     //     for (let i = this.TargetArray.length-1; i > -1; i--) {
+    //     //         if(this.TargetArray[i] == targetparent){
+    //     //             this.TargetArray.splice(i,1);
+    //     //         }
+    //     //     }
+    //     // }
+    //         if(targetparent && !targetparent.destroyed){
+    //             if(targetparent.name != "RightCollider" && targetparent.name != "LeftCollider" && targetparent.name != "BottomCollider"){
+    //                 for (let i = this.TargetArray.length-1; i > -1; i--) {
+    //                     if(this.TargetArray[i] == targetparent){
+    //                         this.TargetArray.splice(i,1);
+    //                     }
+    //                 }
+    //             }
+    //         }
+    // }
     //往目标点移动
     Move(_position: Laya.Vector2) {
         if(!this.moved){
@@ -214,11 +229,11 @@ export  default class Ball extends Laya.Script{
             //消除数量加1  判读是否震动
             GameManager.Instance.EliminateNum += 1;  
             //加分
-            
             let ball = owner.getComponent(Ball) as Ball;
             let ownerscore = ball.score;
             GameManager.Instance.ScoreRecord += ownerscore;
             GameManager.Instance.ScoreRecord2  = GameManager.Instance.ScoreRecord;
+
             let move = Laya.Tween.to(this.owner, {
                 x: _position.x, y: _position.y, update: new Laya.Handler(this, function(){
     
@@ -242,8 +257,7 @@ export  default class Ball extends Laya.Script{
                     //合成之后把本波消除分数归0
                     GameManager.Instance.ScoreRecord = 0;
                     GameManager.Instance.played = false;
-                    // console.log("分数++++",score);
-                    // console.log("总进度分数---",GameManager.Instance.ScoreProgress);
+                    
                     GameManager.Instance.Wave += 1;
                     AudioManager.playMusic(MusicType.clear);
                     if(DropRule.Instance.STAGE == 1){
@@ -261,72 +275,80 @@ export  default class Ball extends Laya.Script{
    //点击到球
     ClickBall(){
         let owner = this.owner as Laya.Image;
-        //将数组中被删除掉的球移除
-        for (let j = this.TargetArray.length-1; j > -1; j--) {
-            if(this.TargetArray[j].destroyed || this.TargetArray[j] == null){
-                this.TargetArray.splice(j,1);
-            }
-        }
-        for (let i = 0; i < this.TargetArray.length; i++) {
-            let num = this.TargetArray[i].getChildByName("num") as Laya.FontClip;
-        }
+        // //将数组中被删除掉的球移除
+        // for (let j = this.TargetArray.length-1; j > -1; j--) {
+        //     if(this.TargetArray[j].destroyed || this.TargetArray[j] == null){
+        //         this.TargetArray.splice(j,1);
+        //     }
+        // }
+        // for (let i = 0; i < this.TargetArray.length; i++) {
+        //     let num = this.TargetArray[i].getChildByName("num") as Laya.FontClip;
+        // }
         DropRule.Instance.Cloned = false;
         GameManager.Instance.TargetPosition =new Vector2(owner.x,owner.y);
-        this.DisPose(owner); 
+        // this.DisPose(owner); 
+        this.MouseClick(owner);
     }
     //处理被点到的球的子物体
-    DisPose(_node:Laya.Image){
-        let ball = _node.getComponent(Ball) as Ball;
-        //被点击的球的周围数量
-        if(ball.TargetArray.length>0){
-            //被点击的球的分数
-            if(!ball.mark){
-                // let ownerscore = ball.score;
-                // GameManager.Instance.ScoreRecord += ownerscore;
-                ball.mark = true;
-            }
-            ball.clear = true;
-            for (let i = 0; i < ball.TargetArray.length; i++) {
-                if(ball.TargetArray[i].getComponent(Ball).mark)continue;
-                //记录分数
-                // let score = ball.TargetArray[i].getChildByName("num") as Laya.FontClip;
-                // GameManager.Instance.ScoreRecord += Number(score.value);
-                ball.TargetArray[i].getComponent(Ball).mark = true;
-                ball.TargetArray[i].getComponent(Ball).clear = true;
+    // DisPose(_node:Laya.Image){
+    //     let ball = _node.getComponent(Ball) as Ball;
+    //     //被点击的球的周围数量
+    //     if(ball.TargetArray.length>0){
+    //         //被点击的球的分数
+    //         if(!ball.mark){
+    //             // let ownerscore = ball.score;
+    //             // GameManager.Instance.ScoreRecord += ownerscore;
+    //             ball.mark = true;
+    //         }
+    //         ball.clear = true;
+    //         for (let i = 0; i < ball.TargetArray.length; i++) {
+    //             if(ball.TargetArray[i].getComponent(Ball).mark)continue;
+    //             //记录分数
+    //             // let score = ball.TargetArray[i].getChildByName("num") as Laya.FontClip;
+    //             // GameManager.Instance.ScoreRecord += Number(score.value);
+    //             ball.TargetArray[i].getComponent(Ball).mark = true;
+    //             ball.TargetArray[i].getComponent(Ball).clear = true;
                 
-                let target = ball.TargetArray[i];
-                let ball2 = target.getComponent(Ball) as Ball;
-                //被点击的球的周围球的子物体数量
-                if(ball2.TargetArray.length>0){
-                    for (let j = 0; j < ball2.TargetArray.length; j++) {
-                        if(ball2.TargetArray[j] == _node ){
-                            continue
-                        }
-                        ball2.clear = true;
-                        ball2.mark = true;
-                        this.DisPose(ball2.TargetArray[j]);
-                    }
-                }
-            }
-        }
-    }
+    //             let target = ball.TargetArray[i];
+    //             let ball2 = target.getComponent(Ball) as Ball;
+    //             //被点击的球的周围球的子物体数量
+    //             if(ball2.TargetArray.length>0){
+    //                 for (let j = 0; j < ball2.TargetArray.length; j++) {
+    //                     if(ball2.TargetArray[j] == _node ){
+    //                         continue
+    //                     }
+    //                     ball2.clear = true;
+    //                     ball2.mark = true;
+    //                     this.DisPose(ball2.TargetArray[j]);
+    //                 }
+    //             }
+    //         }
+    //     }
+    // }
     //鼠标点击
     MouseClick(_node:Laya.Image){
+        let _nodeball = _node.getComponent(Ball) as Ball;
         for (let i = 0; i < InGameView.Instance.prefabbox.numChildren; i++){
             let other = InGameView.Instance.prefabbox.getChildAt(i) as Laya.Image;
+            let ball = other.getComponent(Ball) as Ball;
             if(other.x == _node.x && other.y == _node.y){
                 continue
             }
+            if(ball.mark){
+                continue
+            } 
+            let distan =  Laya.Vector3.distance(new Laya.Vector3(other.x,other.y,0),new Laya.Vector3(_node.x,_node.y,0));
             let distanceX = Math.abs(_node.x - other.x) ;
             let distanceY = Math.abs(_node.y - other.y) ;
             let dis = _node.width/2 + other.width/2;
-            if(distanceX-dis <=3 || distanceY-dis <=3){
-
+            if(Math.abs(distan-dis)  <= AccountManager.Instance.curplayerData.Distance || Math.abs(distan-dis) <= AccountManager.Instance.curplayerData.Distance){
+                if(ball.score == _nodeball.score){
+                    ball.mark = true;
+                    this.MouseClick(other);
+                }
             }
-            
         }
 
-
     }
     
 }

+ 4 - 0
src/Net/PlayerData.ts

@@ -141,6 +141,10 @@ export class PlayerData {
     public get ShakeNum():number{
         return this.netzheshe["ShakeNum"];
     }
+    //获取球球之间的消除间隔距离
+    public get Distance():number{
+        return this.netzheshe["Distance"]
+    }
     public get touchsize():number
     {
         return Number(this.netzheshe["touchsize"]);

+ 2 - 2
src/Tool/DropRule.ts

@@ -216,7 +216,7 @@ export class DropRule{
         //刚体碰撞器
         let collider = ball.addComponent(Laya.CircleCollider) as Laya.CircleCollider;
         collider.restitution = AccountManager.Instance.curplayerData.Restitution;
-        collider.radius = size/2 + 1.5;
+        collider.radius = size/2 ;
         // console.log("_index--",_index);
         console.log("碰撞器半径--",collider.radius,size);
         let rig = ball.addComponent(Laya.RigidBody) as Laya.RigidBody;
@@ -271,7 +271,7 @@ export class DropRule{
         if(this.STAGE == 1 && GameManager.Instance.Wave<3){
             collider.restitution = 0;
         }
-        collider.radius = size/2 + 1.5;
+        collider.radius = size/2 ;
         let rig = ball.addComponent(Laya.RigidBody) as Laya.RigidBody;
         rig.allowRotation = true;
         rig.gravityScale = 3;