|
@@ -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);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
}
|