woso_javan 4 місяців тому
батько
коміт
4381f7c634

+ 1 - 1
assets/module_movecar/Script/Components/CarCarColorsComponent.ts

@@ -147,7 +147,7 @@ export class CarCarColorsComponent extends Component {
         this.node.removeFromParent()
         this.node.destroy()
 
-        console.log('活动的车辆数量:', CarColorsGlobalInstance.instance.carSysterm.activeCar.size);
+        // console.log('活动的车辆数量:', CarColorsGlobalInstance.instance.carSysterm.activeCar.size);
         if (CarColorsGlobalInstance.instance.carSysterm.activeCar.size === 0) {
             const children = CarColorsGlobalInstance.instance.levels.children;
             const levelComp = children[0].getComponent(LevelAction)!;

+ 2 - 2
assets/module_movecar/Script/Components/PinComponent.ts

@@ -99,9 +99,9 @@ export class PinComponent extends Component {
         });
 
         if (this.isBlocked) {
-            console.log(`${CarColorLog[this.pin_color]} 被遮挡了`);
+            // console.log(`${CarColorLog[this.pin_color]} 被遮挡了`);
         } else {
-            console.log(`${CarColorLog[this.pin_color]} 未被遮挡了,可以溜`);
+            // console.log(`${CarColorLog[this.pin_color]} 未被遮挡了,可以溜`);
         }
     }
 

+ 14 - 11
assets/module_movecar/Script/ElementAction.ts

@@ -1,4 +1,4 @@
-import { _decorator, BoxCollider2D, CircleCollider2D, Color, Component, ERigidBody2DType, instantiate, PolygonCollider2D, RigidBody2D, Sprite, tween, UIOpacity, view, Node, isValid } from 'cc';
+import { _decorator, BoxCollider2D, CircleCollider2D, Color, Component, ERigidBody2DType, instantiate, PolygonCollider2D, RigidBody2D, Sprite, tween, UIOpacity, view, Node, isValid, find } from 'cc';
 import { EventDispatcher } from '../../core_tgx/easy_ui_framework/EventDispatcher';
 import { CarColorHex, CarColors } from './CarColorsGlobalTypes';
 import { HoleComponent } from './Components/HoleComponent';
@@ -10,13 +10,23 @@ const { ccclass, property } = _decorator;
 
 @ccclass('ElementAction')
 export class ElementAction extends Component {
-    ele_color: CarColors
+    ele_color: CarColors;
+    parking: Node;
+
     start() {
+        this.parking = find('Canvas/Scene/Parkings')!;
+
         EventDispatcher.instance.on(GameEvent.EVENT_CHECK_ELEMENT_CHILDREN, this.checkElementChildren, this);
     }
 
     update(deltaTime: number) {
-        let currentPosition = this.node.getPosition().clone();
+        const currentPosition = this.node.getPosition().clone();
+        const worldPos = this.node.getWorldPosition();
+
+        if (worldPos.y <= this.parking.getWorldPosition().y) {
+            EventDispatcher.instance.emit(GameEvent.EVENT_UPDATE_LAYER);
+        }
+
         if (currentPosition.y < - view.getVisibleSize().height) {
             this.removeElement();
         }
@@ -26,7 +36,6 @@ export class ElementAction extends Component {
         if (isValid(this.node)) {
             this.node.removeFromParent();
             this.node.destroy();
-            EventDispatcher.instance.emit(GameEvent.EVENT_UPDATE_LAYER);
         }
     }
 
@@ -38,7 +47,7 @@ export class ElementAction extends Component {
         const pins = this.node.getComponentsInChildren(PinComponent)!;
         // console.log('检测是否还有钉子:', pins.length)
         if (pins.length == 0) {
-            console.log("没有钉子 Element刚体变成动力学");
+            // console.log("没有钉子 Element刚体变成动力学");
             this.node.getComponent(RigidBody2D).type = ERigidBody2DType.Dynamic;
         }
     }
@@ -56,12 +65,6 @@ export class ElementAction extends Component {
     public init_element(group_id: number, ele_color: CarColors) {
         this.ele_color = ele_color;
         this.node.getComponent(RigidBody2D).group = group_id;
-        this.node.getComponents(BoxCollider2D).forEach(element => {
-            element.group = group_id;
-        });
-        this.node.getComponents(CircleCollider2D).forEach(element => {
-            element.group = group_id;
-        });
         this.node.getComponents(PolygonCollider2D).forEach(element => {
             element.group = group_id;
         });

+ 67 - 6
assets/module_movecar/Script/LevelAction.ts

@@ -10,6 +10,7 @@ import { tgxUIMgr } from '../../core_tgx/tgx';
 import { UI_BattleResult } from '../../scripts/UIDef';
 import { LevelManager } from './Manager/LevelMgr';
 import { CarBoxComponent } from './Components/CarBoxComponent';
+import { CarColors } from './CarColorsGlobalTypes';
 const { ccclass, property } = _decorator;
 
 @ccclass('LevelAction')
@@ -242,29 +243,89 @@ export class LevelAction extends Component {
 
     //检测游戏是否结束
     checkGameOver() {
-        let checkOver = function () {
-            const points = find("Canvas/Scene/Parkings").children
+        const checkOver = () => {
+            const { isEnd } = LevelManager.instance.levelModel;
+            if (isEnd) return;
+
+            // 检查停车位是否都停了车
+            const points = find("Canvas/Scene/Parkings").children;
+            let allParkingOccupied = true;
 
             for (let i = points.length; i--;) {
                 if (points[i].name === "empty") {
-                    return
+                    allParkingOccupied = false;
+                    break;
                 }
 
                 if (points[i].name === "inuse" && points[i].children.length === 0) {
-                    return
+                    allParkingOccupied = false;
+                    break;
                 }
             }
 
+            console.log('allParkingOccupied:', allParkingOccupied);
+            if (!allParkingOccupied) {
+                return; // 还有空车位,游戏未结束
+            }
+
+            // 获取所有停车位上的车子颜色
+            const carColors = new Set<CarColors>();
+            for (const point of points) {
+                if (point.name === "inuse" && point.children.length == 1) {
+                    const car = point.children[0];
+                    const carComp = car.getComponent(CarCarColorsComponent);
+                    if (carComp) {
+                        carColors.add(carComp.carColor);
+                    }
+                }
+
+                if (point.name === "inuse" && point.children.length == 2) {
+                    const car = point.children[1];
+                    const carComp = car.getComponent(CarCarColorsComponent);
+                    if (carComp) {
+                        carColors.add(carComp.carColor);
+                    }
+                }
+            }
+
+            // 检查当前层级是否有与车子颜色相同的未锁钉子
+            const layer_arr = this.get_all_layer();
+            let hasMatchingPins = false;
+
+            for (const layer of layer_arr) {
+                if (layer.layer_status !== 1) continue; // 只检查当前显示的层级
+
+                for (const element of layer.node.children) {
+                    const pins = element.getComponentsInChildren(PinComponent);
+                    for (const pin of pins) {
+                        const pinCom = pin.getComponent(PinComponent);
+                        if (!pinCom.isBlocked && carColors.has(pinCom.pin_color)) {
+                            hasMatchingPins = true; // 有与车子颜色相同的未锁钉子
+                            break;
+                        }
+                    }
+                    if (hasMatchingPins) break;
+                }
+                if (hasMatchingPins) break;
+            }
+
+            console.log('hasMatchingPins:', hasMatchingPins)
+            if (hasMatchingPins) {
+                return; // 还有与车子颜色相同的钉子,游戏未结束
+            }
+
+            // 游戏结束
             const ui = tgxUIMgr.inst.getUI(UI_BattleResult)!;
             if (!ui) {
                 LevelManager.instance.levelModel.isWin = false;
                 LevelManager.instance.levelModel.isEnd = true;
                 tgxUIMgr.inst.showUI(UI_BattleResult);
             }
-        }
+        };
 
+        // 取消之前的检测,重新调度
         this.unschedule(checkOver);
-        this.scheduleOnce(checkOver, 3);
+        this.scheduleOnce(checkOver, 2); // 2 秒后检测
     }
 
     protected onDestroy(): void {