Search in sources :

Example 1 with Consumer

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);
    }
}
Also used : Player(io.anuke.mindustry.entities.Player) Effects(io.anuke.ucore.core.Effects) Entity(io.anuke.ucore.entities.Entity) Tile(io.anuke.mindustry.world.Tile) Translator(io.anuke.ucore.util.Translator) Entities(io.anuke.ucore.entities.Entities) Physics(io.anuke.ucore.util.Physics) Rectangle(com.badlogic.gdx.math.Rectangle) Effect(io.anuke.ucore.core.Effects.Effect) Consumer(io.anuke.ucore.function.Consumer) Vector2(com.badlogic.gdx.math.Vector2) SolidEntity(io.anuke.ucore.entities.SolidEntity) DestructibleEntity(io.anuke.ucore.entities.DestructibleEntity) Mathf(io.anuke.ucore.util.Mathf) Vars(io.anuke.mindustry.Vars) DestructibleEntity(io.anuke.ucore.entities.DestructibleEntity) Player(io.anuke.mindustry.entities.Player) SolidEntity(io.anuke.ucore.entities.SolidEntity) Tile(io.anuke.mindustry.world.Tile)

Example 2 with Consumer

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();
}
Also used : TextField(io.anuke.ucore.scene.ui.TextField) Settings(io.anuke.ucore.core.Settings) TooltipManager(io.anuke.ucore.scene.ui.TooltipManager) Skin(io.anuke.ucore.scene.Skin) Gdx(com.badlogic.gdx.Gdx) TextFieldFilter(io.anuke.ucore.scene.ui.TextField.TextFieldFilter) Graphics(io.anuke.ucore.core.Graphics) Locale(java.util.Locale) Colors(com.badlogic.gdx.graphics.Colors) Dialog(io.anuke.ucore.scene.ui.Dialog) Vars.control(io.anuke.mindustry.Vars.control) Interpolation(com.badlogic.gdx.math.Interpolation) Unit(io.anuke.ucore.scene.ui.layout.Unit) Mathf(io.anuke.ucore.util.Mathf) Vars(io.anuke.mindustry.Vars) io.anuke.mindustry.ui.fragments(io.anuke.mindustry.ui.fragments) Core(io.anuke.ucore.core.Core) Platform(io.anuke.mindustry.io.Platform) Align(com.badlogic.gdx.utils.Align) Color(com.badlogic.gdx.graphics.Color) Draw(io.anuke.ucore.graphics.Draw) Consumer(io.anuke.ucore.function.Consumer) Listenable(io.anuke.ucore.function.Listenable) MapEditorDialog(io.anuke.mindustry.mapeditor.MapEditorDialog) SceneModule(io.anuke.ucore.modules.SceneModule) Keys(com.badlogic.gdx.Input.Keys) Actions(io.anuke.ucore.scene.actions.Actions) io.anuke.ucore.scene.builders.build(io.anuke.ucore.scene.builders.build) Timers(io.anuke.ucore.core.Timers) io.anuke.mindustry.ui.dialogs(io.anuke.mindustry.ui.dialogs) Dialog(io.anuke.ucore.scene.ui.Dialog) MapEditorDialog(io.anuke.mindustry.mapeditor.MapEditorDialog) TextField(io.anuke.ucore.scene.ui.TextField)

Aggregations

Vars (io.anuke.mindustry.Vars)2 Consumer (io.anuke.ucore.function.Consumer)2 Mathf (io.anuke.ucore.util.Mathf)2 Gdx (com.badlogic.gdx.Gdx)1 Keys (com.badlogic.gdx.Input.Keys)1 Color (com.badlogic.gdx.graphics.Color)1 Colors (com.badlogic.gdx.graphics.Colors)1 Interpolation (com.badlogic.gdx.math.Interpolation)1 Rectangle (com.badlogic.gdx.math.Rectangle)1 Vector2 (com.badlogic.gdx.math.Vector2)1 Align (com.badlogic.gdx.utils.Align)1 Vars.control (io.anuke.mindustry.Vars.control)1 Player (io.anuke.mindustry.entities.Player)1 Platform (io.anuke.mindustry.io.Platform)1 MapEditorDialog (io.anuke.mindustry.mapeditor.MapEditorDialog)1 io.anuke.mindustry.ui.dialogs (io.anuke.mindustry.ui.dialogs)1 io.anuke.mindustry.ui.fragments (io.anuke.mindustry.ui.fragments)1 Tile (io.anuke.mindustry.world.Tile)1 Core (io.anuke.ucore.core.Core)1 Effects (io.anuke.ucore.core.Effects)1