Crates.io | pvz_rust_wsll |
lib.rs | pvz_rust_wsll |
version | 0.2.1 |
created_at | 2025-05-13 12:51:09.240981+00 |
updated_at | 2025-05-16 07:39:55.841121+00 |
description | 一个用 Rust 实现的植物大战僵尸风格游戏的库和可执行程序。目前基本完成. |
homepage | |
repository | https://github.com/iamwsll/PVZbyRust |
max_upload_size | |
id | 1671872 |
size | 6,594,479 |
用Rust语言实现的植物大战僵尸游戏
English | 简体中文
这是一个使用Rust语言和ggez游戏引擎开发的植物大战僵尸风格游戏。本项目旨在展示如何使用Rust构建具有良好架构和模式的游戏应用,采用了工厂模式等设计模式使代码更易于扩展和维护。
git clone https://github.com/iamwsll/PVZbyRust.git
cd PVZbyRust
cargo run --release
src/
├── core/ # 核心游戏引擎
│ ├── game.rs # 游戏主循环和状态
│ ├── renderer.rs # 渲染系统
│ ├── resources.rs # 资源加载和管理
│ └── states.rs # 游戏状态定义
├── entities/ # 游戏实体
│ ├── pea.rs # 豌豆弹药
│ └── sun.rs # 阳光资源
├── mechanics/ # 游戏机制
│ ├── collision.rs # 碰撞检测
│ ├── entity_manager.rs # 实体管理
│ └── level_controller.rs # 关卡控制
├── plants/ # 植物相关功能
│ ├── peashooter.rs # 豌豆射手
│ ├── plant_factory.rs # 植物工厂
│ ├── plant_trait.rs # 植物特性接口
│ ├── sunflower.rs # 向日葵
│ └── wallnut.rs # 坚果墙
├── ui/ # 用户界面
│ ├── grid.rs # 游戏网格
│ ├── input_handler.rs # 输入处理
│ ├── shop.rs # 植物商店
│ └── shovel.rs # 铲子功能
├── zombies/ # 僵尸相关功能
│ ├── conehead_zombie.rs # 路障僵尸
│ ├── normal_zombie.rs # 普通僵尸
│ ├── zombie_factory.rs # 僵尸工厂
│ └── zombie_trait.rs # 僵尸特性接口
├── lib.rs # 库入口
└── main.rs # 程序入口
plants/
目录中创建新植物的实现文件PlantTrait
特性plant_factory.rs
中的PlantType
枚举中添加新植物类型PlantType.cost()
方法中添加新植物的成本PlantFactory.create_plant()
中添加新植物的创建逻辑shop.rs
中添加新植物的商店卡片zombies/
目录中创建新僵尸的实现文件ZombieTrait
特性zombie_factory.rs
中的ZombieType
枚举中添加新僵尸类型ZombieFactory.create_zombie()
中添加新僵尸的创建逻辑本项目使用MIT许可证 - 详见 LICENSE 文件。
如有任何问题或建议,请发送邮件至 1481121704@qq.com