Quellcode durchsuchen

bulletCollisionTower

0224995 vor 2 Wochen
Ursprung
Commit
13af5b90a1

Datei-Diff unterdrückt, da er zu groß ist
+ 326 - 120
assets/Scene/GameScene.scene


Datei-Diff unterdrückt, da er zu groß ist
+ 142 - 2306
assets/Scene/StartScene.scene


+ 5 - 1
assets/Script/Game/MyApp/GameScene/Bottom.ts

@@ -54,8 +54,12 @@ export class Bottom extends ModulerBase {
     }
 
     private _setRoleImg() {
-        for (let i = 0; i < this._characterSlot.children.length; i++) {
+        for (let i = 0; i < GameInfo.Instance.getRoleImgNames().length; i++) {
             const role: Node = this._characterSlot.children[i];
+            const lock: Node = role.getChildByName("Lock");
+            if(lock.active){
+                lock.active = false;
+            }
             const sprite: Node = role.getChildByName("Sprite");
             const imgName: string = GameInfo.Instance.getRoleImgNames()[i];
             sprite.getComponent(Sprite).spriteFrame = resMgr.getSpriteFrame(imgName);

+ 8 - 5
assets/Script/Game/MyApp/GameScene/Bullet.ts

@@ -1,9 +1,6 @@
-import { _decorator, Animation, AnimationClip, Component, find, Node, Sprite, SpriteFrame, UITransform, Vec3 } from 'cc';
+import { _decorator, Animation, AnimationClip, Component, Node, Rect, SpriteFrame, UITransform, Vec3 } from 'cc';
 import { LifeBar } from './LifeBar';
 import { BulletPool } from './BulletPool';
-import { Role } from '../Role';
-import { GameMgr } from '../../GameFrameWork/GameMgr';
-import { Top } from './Top';
 const { ccclass, property } = _decorator;
 export enum BulletState {
     Normal,
@@ -100,7 +97,13 @@ export class Bullet extends Component {
     private onBulletCollision(targetNode: Node) {
         if (this._hasCollided || !targetNode.isValid) return;
         const boxBullet = this.node.getComponent(UITransform).getBoundingBoxToWorld();
-        const boxTarget = targetNode.getComponent(UITransform).getBoundingBoxToWorld();
+        let boxTarget: Rect = null;
+        if(this.targetNode.getChildByName("Rect")){
+            boxTarget = this.targetNode.getChildByName("Rect").getComponent(UITransform).getBoundingBoxToWorld();
+        } else {
+            boxTarget = this.targetNode.getComponent(UITransform).getBoundingBoxToWorld();
+        }
+        
         if (boxTarget.intersects(boxBullet)) {
             const targetLifeBar = targetNode.getComponent(LifeBar);
             const curHp: number = targetLifeBar._curHp - this.atk;

+ 5 - 5
assets/Script/Game/MyApp/GameScene/EnemyMgr.ts

@@ -27,7 +27,7 @@ export class EnemyMgr extends ModulerBase {
 
     //角色卡牌消耗量
     private _cardConsume: Map<string, number> = new Map();
-    
+
     protected onLoad(): void {
         this._bg = this.node.parent.getChildByName("Bg");
         this._lvDts = dataMgr.getAllDataByName("LevelDt");
@@ -38,10 +38,10 @@ export class EnemyMgr extends ModulerBase {
     init() {
         //第几关的数据
         this._lvDt = this._lvDts[GameInfo.Instance.getCurlv() - 1];
-        this._createEnemy();
-        this.schedule(() => {
-            this._createEnemy();
-        }, 20)
+        // this._createEnemy();
+        // this.schedule(() => {
+        //     this._createEnemy();
+        // }, 20)
         //设置敌方防御塔血量
         this._enemyTower.getComponent(EnemyTower).enemyTotalHp = this._lvDt.enemyTowerHp;
         //设置背景

+ 1 - 1
assets/Script/Game/MyApp/GameScene/EnemyTower.ts

@@ -21,7 +21,7 @@ export class EnemyTower extends Role {
     start() {
         this.hp = this.enemyTotalHp;
         this._initLifeBar();
-        super._setupPhysics();
+        //super._setupPhysics();
     }
 
     //初始化血条

+ 2 - 1
assets/Script/Game/MyApp/GameScene/GameOver.ts

@@ -2,6 +2,7 @@ import { _decorator, director, Label } from 'cc';
 import { UIBase } from '../../GameFrameWork/UIBase';
 import { resMgr } from '../../../Frames/ResourcesMgr';
 import { GameOverData } from './Data/GameOverData';
+import { UIMgr } from '../../../Frames/UIManager';
 const { ccclass, property } = _decorator;
 
 @ccclass('GameOver')
@@ -134,7 +135,7 @@ export class GameOver extends UIBase {
     private _onBtnBack() {
         //销毁
         this.gameOverDt.clearData();
-        this.hide(false);
+        UIMgr.closeUI("GameOver");
         director.loadScene("StartScene");
     }
 }

+ 2 - 2
assets/Script/Game/MyApp/GameScene/MyTower.ts

@@ -1,4 +1,4 @@
-import { _decorator, director, Label, PhysicsGroup} from 'cc';
+import { _decorator, director, find, Label, PhysicsGroup} from 'cc';
 import { Role } from '../Role';
 import { LifeBar } from './LifeBar';
 import { Enemy } from './Enemy';
@@ -19,7 +19,7 @@ export class MyTower extends Role {
     start() {
         this.hp = GameInfo.Instance.getMyTowerHp();
         this._initLifeBar();
-        super._setupPhysics();
+        //super._setupPhysics();
     }
 
     //初始化血条

+ 3 - 3
assets/Script/Game/MyApp/Role.ts

@@ -97,7 +97,7 @@ export class Role extends Component {
         this.node.setWorldPosition(pos);
         this.bulletLayer = find("Canvas/GameRoot/BulletLayer");
 
-        this._setupPhysics();
+        //this._setupPhysics();
     }
 
     private _setRoleData(roleData: RoleData) {
@@ -161,7 +161,6 @@ export class Role extends Component {
         const startPos = this.node.position.clone();
         const endPos = new Vec2((this.direction * this.atkLength) + this.node.position.x, this.node.position.y);
         const results = PhysicsSystem2D.instance.raycast(startPos, endPos);
-
         if (results?.length) {
             for (const result of results) {
                 const target = result.collider.node.getComponent(Role);
@@ -253,7 +252,7 @@ export class Role extends Component {
         // this._animations.set(RoleState.Die, dieAni);
 
         this._createClip(RoleState.Move, this._moveFrames, 8);
-        this._createClip(RoleState.Attack, this._atkFrames, 8);
+        this._createClip(RoleState.Attack, this._atkFrames, 6);
         this._createClip(RoleState.Idle, this._idleFrames, 8);
         this._createClip(RoleState.Die, this._dieFrames, 9);
     }
@@ -324,6 +323,7 @@ export class Role extends Component {
             targetNode: this.currentTarget.node,
             atk: this.atk,
         })
+        console.log(this._bullet.getComponent(Animation))
     }
 
     //要求子类实现的碰撞分组和阵营判断方法,确保不同阵营角色可以正确交互

+ 53 - 0
assets/Script/Game/MyApp/TouchCharacterSlot-001.ts

@@ -0,0 +1,53 @@
+import { _decorator, find, Label, math, Node, Rect, UITransform } from 'cc';
+import { TouchMgr } from './TouchMgr';
+import { CharacterSlotMgr } from './CharacterSlotMgr';
+import { UIMgr } from '../../Frames/UIManager';
+import { PopupUI } from '../UI/PopupUI';
+import { UIType } from '../GameFrameWork/UIBase';
+import { PopupUIDataConfig } from './GameScene/Data/PopupUIDataConfig';
+const { ccclass, property } = _decorator;
+
+@ccclass('TouchCharacterSlot')
+export class TouchCharacterSlot extends TouchMgr {
+    private _characterSlot: Node = null;
+    private unLock: Node = null;
+    protected onLoad(): void {
+        this._characterSlot = this.node.parent.getChildByName("CharacterSlot");
+    }
+    func(pos: math.Vec2): void {
+        this.node.parent.getChildByName("CharacterSlot").getComponent(CharacterSlotMgr).removeCardImg(pos);
+        for (const node of this._characterSlot.children) {
+            if (node.getChildByName("Label").active) {
+                const box: Rect = node.getComponent(UITransform).getBoundingBoxToWorld();
+                if (box.contains(pos)) {
+                    this.unLock = node;
+                    PopupUIDataConfig.Instance.setUIName("解锁");
+                    PopupUIDataConfig.Instance.setTypeImg("Lock");
+                    PopupUIDataConfig.Instance.setTypeMoney("Gold");
+                    PopupUIDataConfig.Instance.setLabel(
+                        `可用卡槽:${PopupUIDataConfig.Instance.getAvailableCardSlot()}`,
+                        `下一级:${PopupUIDataConfig.Instance.getAvailableCardSlot() + 1}`,
+                        `耗费:`, `2000`);
+                    PopupUIDataConfig.Instance.setFunction(() => {
+                        this.closeNode();
+                    })
+                    UIMgr.openUI("PopupUI", UIType.WIDGET);
+                }
+            }
+        }
+    }
+
+    closeNode() {
+        if (this.unLock) {
+            this.unLock.getChildByName("Lock").active = false;
+            this.unLock.getChildByName("Label").active = false;
+            PopupUIDataConfig.Instance.setAvailableCardSlot(PopupUIDataConfig.Instance.getAvailableCardSlot() + 1)
+
+            const indexNext: number = this.unLock.getSiblingIndex();
+            if (indexNext === this.unLock.parent.children.length - 1) return;
+            const nodeNext = this.unLock.parent.children[indexNext + 1];
+            nodeNext.getChildByName("Lock").active = true;
+            nodeNext.getChildByName("Label").active = true;
+        }
+    }
+}

+ 1 - 0
assets/Script/Game/MyApp/TouchCharacterSlot-001.ts.meta

@@ -0,0 +1 @@
+{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"3c3e5f8c-dd29-4fac-9be3-7ba10181ff56","files":[],"subMetas":{},"userData":{}}

+ 5 - 6
assets/Script/Game/UI/BattleSceneTop.ts

@@ -4,6 +4,7 @@ import { UIMgr } from '../../Frames/UIManager';
 import { ModulerBase } from '../GameFrameWork/ModulerBase';
 import { GameMgr } from '../GameFrameWork/GameMgr';
 import { SelectTroops } from './SelectTroops';
+import { messageMgr } from '../../Frames/MessageMgr';
 const { ccclass, property } = _decorator;
 
 @ccclass('BattleSceneTop')
@@ -14,12 +15,10 @@ export class BattleSceneTop extends ModulerBase {
         this._gold(GameInfo.Instance.getGold());
         this._diamond(GameInfo.Instance.getDiamond());
         this.battleMode("战斗模式");
-        SelectTroops
-        //this.onMsg("BattleMode", this._battleMode)
-    }
-    protected start(): void {
-        
+        messageMgr.addEvent("reduceGold", this._gold, this);
+        messageMgr.addEvent("reduceDiamond", this._diamond, this);
     }
+
     //金币数量
     private _gold(goldAmound: number) {
         this.getLabel("_gold").string = String(goldAmound);
@@ -32,7 +31,7 @@ export class BattleSceneTop extends ModulerBase {
 
     //返回按钮
     private _btnReturn() {
-        if(!GameMgr.Instance.getModuler(SelectTroops).showing()){
+        if (!GameMgr.Instance.getModuler(SelectTroops).showing()) {
             UIMgr.openUI("Start");
         } else {
             GameMgr.Instance.getModuler(SelectTroops).hide(false);

+ 11 - 4
assets/Script/Game/UI/PopupUI.ts

@@ -5,6 +5,7 @@ import { PopupUIDataConfig } from '../MyApp/GameScene/Data/PopupUIDataConfig';
 import { UIMgr } from '../../Frames/UIManager';
 import { GameInfo } from '../../GameInfo';
 import { Tip } from './Tip';
+import { messageMgr } from '../../Frames/MessageMgr';
 const { ccclass, property } = _decorator;
 
 @ccclass('PopupUI')
@@ -73,24 +74,30 @@ export class PopupUI extends UIBase {
         //     }
         // }
         const resourceMap = {
-            "Gold":{
+            "Gold": {
                 getAmount: GameInfo.Instance.getGold(),
                 message: "金币不足!",
             },
-            "Diamond":{
+            "Diamond": {
                 getAmount: GameInfo.Instance.getDiamond(),
                 message: "钻石不足!",
             }
         };
 
         const resource = resourceMap[this._typeMoney];
-        if(resource && Number(this._consume) > resource.getAmount){
+        //消耗
+        const consume: number = Number(this._consume);
+        //总共
+        const totalGold: number = GameInfo.Instance.getGold();
+        
+        if (resource && Number(this._consume) > resource.getAmount) {
             const tip: Node = instantiate(resMgr.getPrefab("Tip"));
             tip.getComponent(Tip).setContent(resource.message);
             tip.parent = this.node;
             return;
         }
-
+        messageMgr.dispatch("reduceGold", (totalGold - consume));
+        GameInfo.Instance.setGold((totalGold - consume));
         (PopupUIDataConfig.Instance.getFunction())();
         UIMgr.closeUI("PopupUI", true);
         PopupUIDataConfig.Instance.clearDt();

+ 1 - 1
assets/Script/GameInfo.ts

@@ -8,7 +8,7 @@ export class GameInfo {
     //失败场数
     private _failNumber: number = 0;
     //金币数量
-    private _goldAmount: number = 1845;
+    private _goldAmount: number = 2845;
     //钻石数量
     private _diamondAmout: number = 254;
     //等级

+ 2 - 2
assets/resources/Res/Prefab/Enemy.prefab

@@ -545,8 +545,8 @@
     "tag": 0,
     "_group": 2,
     "_density": 1,
-    "_sensor": false,
-    "_friction": 0.2,
+    "_sensor": true,
+    "_friction": -0.2,
     "_restitution": 0,
     "_offset": {
       "__type__": "cc.Vec2",

+ 2 - 2
assets/resources/Res/Prefab/Role.prefab

@@ -545,8 +545,8 @@
     "tag": 0,
     "_group": 4,
     "_density": 1,
-    "_sensor": false,
-    "_friction": 0.2,
+    "_sensor": true,
+    "_friction": 0,
     "_restitution": 0,
     "_offset": {
       "__type__": "cc.Vec2",

+ 1 - 1
assets/resources/Res/Prefab/Skill.prefab

@@ -115,7 +115,7 @@
     "_spriteFrame": null,
     "_type": 0,
     "_fillType": 0,
-    "_sizeMode": 1,
+    "_sizeMode": 0,
     "_fillCenter": {
       "__type__": "cc.Vec2",
       "x": 0,

+ 11 - 1
settings/v2/packages/project.json

@@ -18,6 +18,14 @@
       {
         "index": 4,
         "name": "Tower"
+      },
+      {
+        "index": 5,
+        "name": "Test1"
+      },
+      {
+        "index": 6,
+        "name": "Test2"
       }
     ],
     "collisionMatrix": {
@@ -25,7 +33,9 @@
       "1": 24,
       "2": 24,
       "3": 22,
-      "4": 14
+      "4": 14,
+      "5": 64,
+      "6": 32
     }
   }
 }

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.