|
|
5 月之前 | |
|---|---|---|
| .. | ||
| QuickTestSetup.md | 5 月之前 | |
| QuickTestSetup.md.meta | 5 月之前 | |
| README.md | 5 月之前 | |
| README.md.meta | 5 月之前 | |
| ResourceMapping.md | 5 月之前 | |
| ResourceMapping.md.meta | 5 月之前 | |
| TestGuide.md | 5 月之前 | |
| TestGuide.md.meta | 5 月之前 | |
| TestSetupGuide.md | 5 月之前 | |
| TestSetupGuide.md.meta | 5 月之前 | |
| enemies.json | 5 月之前 | |
| enemies.json.meta | 5 月之前 | |
| weapons.json | 5 月之前 | |
| weapons.json.meta | 5 月之前 | |
本系统提供了完整的武器和敌人配置管理功能,通过JSON文件配置游戏中的武器和敌人类型,支持随机生成、权重分配、稀有度系统等功能。
assets/
├── data/
│ ├── weapons.json # 武器配置文件
│ ├── enemies.json # 敌人配置文件
│ └── README.md # 本说明文档
└── scripts/
├── ConfigManager.ts # 配置管理器
├── WeaponBlockExample.ts # 武器方块示例
└── EnemySpawnerExample.ts # 敌人生成器示例
根据 WeaponNeed.txt 设计了以下8种武器类型:
pea_shooter) - 单发射击sharp_carrot) - 穿透攻击saw_grass) - 弹射+穿透watermelon_bomb) - 爆炸伤害boomerang_plant) - 弧线穿透hot_pepper) - 范围灼烧cactus_shotgun) - 散射攻击okra_missile) - 制导导弹{
"id": "weapon_id",
"name": "武器名称",
"type": "武器类型",
"rarity": "稀有度",
"weight": 权重值,
"stats": {
"damage": 伤害值,
"fireRate": 射速,
"range": 射程,
"bulletSpeed": 子弹速度,
"penetration": 穿透数,
"accuracy": 精准度
},
"bulletConfig": {
"bulletType": "子弹类型",
"bulletPrefab": "子弹预制体路径",
"hitEffect": "命中特效路径"
},
"attackPattern": {
"type": "攻击模式",
"projectileCount": 投射物数量,
"spreadAngle": 散射角度
},
"visualConfig": {
"weaponSprites": {
"1x1": "1x1尺寸图标路径",
"1x2": "1x2尺寸图标路径",
"2x1": "2x1尺寸图标路径",
"2x2": "2x2尺寸图标路径"
},
"muzzleFlash": "枪口闪光特效",
"fireSound": "射击音效"
}
}
根据 EnemyNeed.txt 设计了以下12种敌人类型:
normal_zombie) - 基础敌人roadblock_zombie) - 装甲敌人wandering_zombie) - 摇摆移动mage_zombie) - 远程法术archer_zombie) - 远程射击stealth_zombie) - 隐身能力bucket_zombie) - 重装甲barrel_zombie) - 死亡爆炸boss1_gatekeeper) - 铁栅门BOSSboss2_gravedigger) - 墓碑BOSSboss3_cyborg) - 机械臂BOSS// 在场景中添加ConfigManager组件
const configManager = ConfigManager.getInstance();
// 检查配置是否加载完成
if (configManager.isConfigLoaded()) {
// 配置已加载,可以使用
}
// 获取随机武器
const randomWeapon = configManager.getRandomWeapon();
// 获取指定稀有度的武器
const rareWeapon = configManager.getRandomWeapon('rare');
// 根据ID获取武器
const specificWeapon = configManager.getWeaponById('pea_shooter');
// 获取所有武器
const allWeapons = configManager.getAllWeapons();
// 获取随机敌人
const randomEnemy = configManager.getRandomEnemy();
// 获取指定稀有度的敌人
const bossEnemy = configManager.getRandomEnemy('boss');
// 根据波次获取合适的敌人
const waveEnemy = configManager.getEnemyForWave(10);
// 根据ID获取敌人
const specificEnemy = configManager.getEnemyById('normal_zombie');
// 使用WeaponBlockExample创建武器方块
const weaponBlockExample = this.getComponent(WeaponBlockExample);
// 创建指定ID的武器方块
weaponBlockExample.createWeaponBlockById('pea_shooter', position);
// 获取方块的武器配置
const weaponConfig = WeaponBlockExample.getBlockWeaponConfig(blockNode);
// 使用EnemySpawnerExample生成敌人
const enemySpawner = this.getComponent(EnemySpawnerExample);
// 生成指定类型的敌人
enemySpawner.spawnEnemyByType('normal_zombie');
// 生成指定稀有度的敌人
enemySpawner.spawnEnemyByRarity('boss');
// 设置当前波次
enemySpawner.setCurrentWave(15);
import { ConfigManager, WeaponConfig } from './ConfigManager';
// 在generateRandomBlock方法中使用武器配置
private generateRandomBlock(): Node {
const configManager = ConfigManager.getInstance();
const weaponConfig = configManager.getRandomWeapon();
if (weaponConfig) {
const block = this.createBlockWithWeapon(weaponConfig);
return block;
}
return this.createDefaultBlock();
}
// 创建带武器配置的方块
private createBlockWithWeapon(weaponConfig: WeaponConfig): Node {
const blockNode = instantiate(this.blockPrefab);
// 添加武器组件
const weaponComponent = blockNode.addComponent('WeaponComponent');
weaponComponent.weaponConfig = weaponConfig;
// 设置方块外观
this.setupBlockVisual(blockNode, weaponConfig);
return blockNode;
}
import { ConfigManager, EnemyConfig } from './ConfigManager';
// 在生成敌人时使用配置
public spawnEnemy(waveNumber: number): Node {
const configManager = ConfigManager.getInstance();
const enemyConfig = configManager.getEnemyForWave(waveNumber);
if (enemyConfig) {
const enemy = this.createEnemyWithConfig(enemyConfig);
return enemy;
}
return this.createDefaultEnemy();
}
// 创建带配置的敌人
private createEnemyWithConfig(enemyConfig: EnemyConfig): Node {
const enemyNode = instantiate(this.enemyPrefab);
// 添加敌人组件
const enemyComponent = enemyNode.addComponent('EnemyComponent');
enemyComponent.enemyConfig = enemyConfig;
// 设置敌人属性
this.setupEnemyStats(enemyNode, enemyConfig);
return enemyNode;
}
weapons.json 中添加新的武器配置enemies.json 中添加新的敌人配置waveProgression 中配置敌人出现的波次ConfigManager提供了多种调试方法:
// 检查配置加载状态
console.log('配置加载状态:', configManager.isConfigLoaded());
// 查看所有武器数量
console.log('武器总数:', configManager.getAllWeapons().length);
// 查看指定稀有度的武器数量
console.log('史诗武器数量:', configManager.getWeaponsByRarity('epic').length);
// 查看所有敌人数量
console.log('敌人总数:', configManager.getAllEnemies().length);
通过这个配置系统,你可以轻松地管理游戏中的武器和敌人,实现丰富的游戏内容和平衡性调整。