use of io.anuke.ucore.entities.Entity in project Mindustry by Anuken.
the class World method findTileTarget.
public TileEntity findTileTarget(float x, float y, Tile tile, float range, boolean damaged) {
Entity closest = null;
float dst = 0;
int rad = (int) (range / tilesize) + 1;
int tilex = Mathf.scl2(x, tilesize);
int tiley = Mathf.scl2(y, tilesize);
for (int rx = -rad; rx <= rad; rx++) {
for (int ry = -rad; ry <= rad; ry++) {
Tile other = tile(rx + tilex, ry + tiley);
if (other != null && other.getLinked() != null) {
other = other.getLinked();
}
if (other == null || other.entity == null || (tile != null && other.entity == tile.entity))
continue;
TileEntity e = other.entity;
if (damaged && e.health >= e.tile.block().health)
continue;
float ndst = Vector2.dst(x, y, e.x, e.y);
if (ndst < range && (closest == null || ndst < dst)) {
dst = ndst;
closest = e;
}
}
}
return (TileEntity) closest;
}
use of io.anuke.ucore.entities.Entity 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