xx 1 year ago
parent
commit
8322060af5
2 changed files with 36 additions and 31 deletions
  1. 9 5
      assets/script/game/box.ts
  2. 27 26
      assets/script/game/car.ts

+ 9 - 5
assets/script/game/box.ts

@@ -11,7 +11,7 @@ export class box extends base {
     @property(Node) buff:Node = null;
     @property(Node) lab_scores:Node = null;
     private scores:number = 10;
-    private CdTime:number =0.05;
+    private CdTime:number =0;
     private isOnCollide:boolean = false;
     private mCar:car = null;
     private active_node:boolean = false
@@ -41,13 +41,14 @@ export class box extends base {
     }
     public hurt(call,isKill=false){
         if(!this.isOnCollide){
-            this.scheduleOnce(()=>{
-                this.isOnCollide = false;
-            },this.CdTime)
+            // this.scheduleOnce(()=>{
+            //     this.isOnCollide = false;
+            // },this.CdTime)
             // director.once(Director.EVENT_AFTER_DRAW,()=>{
             //     this.isOnCollide = false;
             // })
-            this.isOnCollide = true;
+            // this.isOnCollide = true;
+            this.isOnCollide = false;
     
             let isUseBuff:boolean = this.mData.buff_type!=-1
             if(this.scores<=1||isKill){
@@ -114,6 +115,9 @@ export class box extends base {
     }
 
     getIsCanCollider(){
+        if(!this.node.active){
+            return false
+        }
         let box_world=this.node.parent.getComponent(UITransform).convertToWorldSpaceAR(this.node.position)
         let p = this.mCar.node.parent.getComponent(UITransform).convertToNodeSpaceAR(box_world)
         return Vec3.distance(p,this.mCar.node.position)<500

+ 27 - 26
assets/script/game/car.ts

@@ -344,7 +344,34 @@ export class car extends Component {
 
             x = this.node.position.x-x;
     
+
+            let left = this.canvas_width*0.5*-1+90*0.5;
+            let right = this.canvas_width*0.5-90*0.5;
             let size = this.node.getComponent(UITransform).contentSize;
+            if(this.carDir==DirType.LEFT){
+
+                let left_x = this.game_manager.getLeftObstacles(new Rect(this.node.position.x-size.width*0.5,this.node.position.y-size.height*0.5,size.width,size.height))
+                // console.log("left_x",left_x)
+                if(left_x!=null&&x<left_x){
+                    x = left_x+5
+                }
+
+                if(x<=left){
+                    x = this.node.position.x
+                }
+            }
+
+            if(this.carDir==DirType.RIGHT){
+                let right_x = this.game_manager.getRightObstacles(new Rect(this.node.position.x-size.width*0.5,this.node.position.y-size.height*0.5,size.width,size.height))
+                // console.log("right_x",right_x)
+                if(right_x!=null&&x>right_x){
+                    x = right_x-5
+                }
+                if(x>=right){
+                    x = this.node.position.x
+                }
+            }
+
             let rect = new Rect(x-size.width*0.5,y-size.height*0.5,size.width,size.height)
             // let rect = this.node.getComponent(UITransform).getBoundingBox()
             let list = this.game_manager.carCollider(rect)
@@ -373,32 +400,6 @@ export class car extends Component {
                 }
             }
 
-            let left = this.canvas_width*0.5*-1+90*0.5;
-            let right = this.canvas_width*0.5-90*0.5;
-
-            if(this.carDir==DirType.LEFT){
-
-                let left_x = this.game_manager.getLeftObstacles(new Rect(this.node.position.x-size.width*0.5,this.node.position.y-size.height*0.5,size.width,size.height))
-                // console.log("left_x",left_x)
-                if(left_x!=null&&x<left_x){
-                    x = left_x+5
-                }
-
-                if(x<=left){
-                    x = this.node.position.x
-                }
-            }
-
-            if(this.carDir==DirType.RIGHT){
-                let right_x = this.game_manager.getRightObstacles(new Rect(this.node.position.x-size.width*0.5,this.node.position.y-size.height*0.5,size.width,size.height))
-                // console.log("right_x",right_x)
-                if(right_x!=null&&x>right_x){
-                    x = right_x-5
-                }
-                if(x>=right){
-                    x = this.node.position.x
-                }
-            }
             // this._curRingPos_1.set(0, 0, 0);
             // Vec3.lerp(this._curRingPos_1, this.node.position, new Vec3(x,y), 50 * dt);