0460-Bomb-实现角色死亡
环境
- Time 2024-03-22
- Zig 0.12.0-dev.3152+90c1a2c41
- WSL-Ubuntu 22.04.3 LTS
- raylib 5.0
前言
说明
参考资料:
- 《游戏开发:世嘉新人培训教材》
- 图片素材:https://www.ituring.com.cn/book/1742
目标
增加炸弹效果,实现敌人和角色可以被炸死的效果。
map.zig
update 方法中新增了碰撞检测方法。
pub fn update(self: *Map) void {
const playerPos = self.player1().getCell();
const mapUnit = self.world.indexRef(playerPos.x, playerPos.y);
if (mapUnit.contains(.item)) {
mapUnit.remove(.item);
self.player1().maxBombNumber += 1;
}
if (mapUnit.contains(.power)) {
self.player1().maxBombLength += 1;
mapUnit.remove(.power);
}
for (self.world.players) |*p| {
if (!p.alive) continue;
const enemyPos = p.getCell();
const unit = self.world.index(enemyPos.x, enemyPos.y);
if (unit.hasExplosion()) p.alive = false;
if (p.type != .enemy) continue;
if (enemyPos.isSame(playerPos)) self.player1().alive = false;
}
self.world.update();
}
效果

总结
实现了角色死亡后跳转到主菜单的功能。

浙公网安备 33010602011771号