50 lines
1.5 KiB
Java
50 lines
1.5 KiB
Java
package com.zombie.game.systems;
|
|
|
|
import com.zombie.game.ecs.ECSWorld;
|
|
import com.zombie.game.ecs.System;
|
|
import com.zombie.game.ecs.components.*;
|
|
|
|
import java.util.*;
|
|
|
|
/**
|
|
* 燃烧区域系统
|
|
*
|
|
* 处理燃烧瓶留下的火焰区域:持续伤害 + 生命周期。
|
|
*/
|
|
public class FireZoneSystem implements System {
|
|
|
|
@Override
|
|
public void update(float dt, ECSWorld world) {
|
|
List<Integer> toRemove = new ArrayList<>();
|
|
|
|
for (int entityId : world.getFireZones()) {
|
|
FireZone fz = world.getFireZonesData().get(entityId);
|
|
Position fzPos = world.getPositions().get(entityId);
|
|
if (fz == null || fzPos == null) continue;
|
|
|
|
fz.update(dt);
|
|
|
|
// 对范围内的僵尸造成持续伤害
|
|
for (int zombieId : world.getZombies()) {
|
|
Health zombieHealth = world.getHealths().get(zombieId);
|
|
Position zombiePos = world.getPositions().get(zombieId);
|
|
if (zombieHealth == null || !zombieHealth.isAlive() || zombiePos == null) continue;
|
|
|
|
float dist = fzPos.distanceTo(zombiePos.getX(), zombiePos.getY());
|
|
if (dist < fz.getRadius()) {
|
|
zombieHealth.takeDamage(fz.getDamagePerTick());
|
|
}
|
|
}
|
|
|
|
if (fz.isExpired()) {
|
|
toRemove.add(entityId);
|
|
}
|
|
}
|
|
|
|
for (int id : toRemove) {
|
|
world.getFireZones().remove(id);
|
|
world.destroyEntity(id);
|
|
}
|
|
}
|
|
}
|