Search in sources :

Example 1 with DestructibleEntity

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);
    }
}
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)

Aggregations

Rectangle (com.badlogic.gdx.math.Rectangle)1 Vector2 (com.badlogic.gdx.math.Vector2)1 Vars (io.anuke.mindustry.Vars)1 Player (io.anuke.mindustry.entities.Player)1 Tile (io.anuke.mindustry.world.Tile)1 Effects (io.anuke.ucore.core.Effects)1 Effect (io.anuke.ucore.core.Effects.Effect)1 DestructibleEntity (io.anuke.ucore.entities.DestructibleEntity)1 Entities (io.anuke.ucore.entities.Entities)1 Entity (io.anuke.ucore.entities.Entity)1 SolidEntity (io.anuke.ucore.entities.SolidEntity)1 Consumer (io.anuke.ucore.function.Consumer)1 Mathf (io.anuke.ucore.util.Mathf)1 Physics (io.anuke.ucore.util.Physics)1 Translator (io.anuke.ucore.util.Translator)1