use of io.anuke.ucore.function.Consumer 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);
}
}
use of io.anuke.ucore.function.Consumer in project Mindustry by Anuken.
the class UI method showTextInput.
public void showTextInput(String title, String text, String def, TextFieldFilter filter, Consumer<String> confirmed) {
new Dialog(title, "dialog") {
{
content().margin(30).add(text).padRight(6f);
TextField field = content().addField(def, t -> {
}).size(170f, 50f).get();
field.setTextFieldFilter((f, c) -> field.getText().length() < 12 && filter.acceptChar(f, c));
Platform.instance.addDialog(field);
buttons().defaults().size(120, 54).pad(4);
buttons().addButton("$text.ok", () -> {
confirmed.accept(field.getText());
hide();
}).disabled(b -> field.getText().isEmpty());
buttons().addButton("$text.cancel", this::hide);
}
}.show();
}
Aggregations