Search in sources :

Example 1 with Entity

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;
}
Also used : TileEntity(io.anuke.mindustry.entities.TileEntity) Entity(io.anuke.ucore.entities.Entity) TileEntity(io.anuke.mindustry.entities.TileEntity) SpawnPoint(io.anuke.mindustry.game.SpawnPoint)

Example 2 with Entity

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

Entity (io.anuke.ucore.entities.Entity)2 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 TileEntity (io.anuke.mindustry.entities.TileEntity)1 SpawnPoint (io.anuke.mindustry.game.SpawnPoint)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 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