use of io.anuke.ucore.entities.DestructibleEntity in project Mindustry by Anuken.
the class DamageArea method damage.
public static void damage(boolean enemies, float x, float y, float radius, int damage) {
Consumer<SolidEntity> cons = entity -> {
DestructibleEntity enemy = (DestructibleEntity) entity;
if (enemy.distanceTo(x, y) > radius || (entity instanceof Player && ((Player) entity).isAndroid)) {
return;
}
int amount = calculateDamage(x, y, enemy.x, enemy.y, radius, damage);
enemy.damage(amount);
};
if (enemies) {
Entities.getNearby(enemyGroup, x, y, radius * 2, cons);
} else {
int trad = (int) (radius / tilesize);
for (int dx = -trad; dx <= trad; dx++) {
for (int dy = -trad; dy <= trad; dy++) {
Tile tile = world.tile(Mathf.scl2(x, tilesize) + dx, Mathf.scl2(y, tilesize) + dy);
if (tile != null && tile.entity != null && Vector2.dst(dx, dy, 0, 0) <= trad) {
int amount = calculateDamage(x, y, tile.worldx(), tile.worldy(), radius, damage);
tile.entity.damage(amount);
}
}
}
Entities.getNearby(playerGroup, x, y, radius * 2, cons);
}
}
Aggregations