Search in sources :

Example 1 with SolidEntity

use of io.anuke.ucore.entities.SolidEntity in project Mindustry by Anuken.

the class Door method anyEntities.

boolean anyEntities(Tile tile) {
    int x = tile.x, y = tile.y;
    Block type = tile.block();
    rect.setSize(type.width * tilesize, type.height * tilesize);
    rect.setCenter(tile.drawx(), tile.drawy());
    for (SolidEntity e : Entities.getNearby(enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)) {
        Rectangle rect = e.hitbox.getRect(e.x, e.y);
        if (this.rect.overlaps(rect)) {
            return true;
        }
    }
    for (SolidEntity e : Entities.getNearby(playerGroup, x * tilesize, y * tilesize, tilesize * 2f)) {
        Rectangle rect = e.hitbox.getRect(e.x, e.y);
        if (this.rect.overlaps(rect)) {
            return true;
        }
    }
    return false;
}
Also used : SolidEntity(io.anuke.ucore.entities.SolidEntity) Rectangle(com.badlogic.gdx.math.Rectangle) Block(io.anuke.mindustry.world.Block)

Example 2 with SolidEntity

use of io.anuke.ucore.entities.SolidEntity in project Mindustry by Anuken.

the class Placement method validPlace.

public static boolean validPlace(int x, int y, Block type) {
    for (int i = 0; i < world.getSpawns().size; i++) {
        SpawnPoint spawn = world.getSpawns().get(i);
        if (Vector2.dst(x * tilesize, y * tilesize, spawn.start.worldx(), spawn.start.worldy()) < enemyspawnspace) {
            return false;
        }
    }
    Recipe recipe = Recipes.getByResult(type);
    if (recipe == null || !state.inventory.hasItems(recipe.requirements)) {
        return false;
    }
    rect.setSize(type.width * tilesize, type.height * tilesize);
    Vector2 offset = type.getPlaceOffset();
    rect.setCenter(offset.x + x * tilesize, offset.y + y * tilesize);
    synchronized (Entities.entityLock) {
        for (SolidEntity e : Entities.getNearby(enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)) {
            // not sure why this happens?
            if (e == null)
                continue;
            Rectangle rect = e.hitbox.getRect(e.x, e.y);
            if (Placement.rect.overlaps(rect)) {
                return false;
            }
        }
    }
    if (type.solid || type.solidifes) {
        for (Player player : playerGroup.all()) {
            if (!player.isAndroid && rect.overlaps(player.hitbox.getRect(player.x, player.y))) {
                return false;
            }
        }
    }
    Tile tile = world.tile(x, y);
    if (tile == null || (isSpawnPoint(tile) && (type.solidifes || type.solid)))
        return false;
    if (type.isMultiblock()) {
        int offsetx = -(type.width - 1) / 2;
        int offsety = -(type.height - 1) / 2;
        for (int dx = 0; dx < type.width; dx++) {
            for (int dy = 0; dy < type.height; dy++) {
                Tile other = world.tile(x + dx + offsetx, y + dy + offsety);
                if (other == null || (other.block() != Blocks.air && !other.block().alwaysReplace) || isSpawnPoint(other)) {
                    return false;
                }
            }
        }
        return true;
    } else {
        return tile.block() != type && (type.canReplace(tile.block()) || tile.block().alwaysReplace) && tile.block().isMultiblock() == type.isMultiblock() || tile.block() == Blocks.air;
    }
}
Also used : Player(io.anuke.mindustry.entities.Player) SolidEntity(io.anuke.ucore.entities.SolidEntity) Recipe(io.anuke.mindustry.resource.Recipe) Vector2(com.badlogic.gdx.math.Vector2) Rectangle(com.badlogic.gdx.math.Rectangle) SpawnPoint(io.anuke.mindustry.game.SpawnPoint) SpawnPoint(io.anuke.mindustry.game.SpawnPoint)

Example 3 with SolidEntity

use of io.anuke.ucore.entities.SolidEntity 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 4 with SolidEntity

use of io.anuke.ucore.entities.SolidEntity in project Mindustry by Anuken.

the class TeslaOrb method shock.

void shock() {
    float stopchance = 0.1f;
    float curx = x, cury = y;
    float shake = 3f;
    int max = 7;
    while (points.size < max) {
        if (Mathf.chance(stopchance)) {
            break;
        }
        Array<SolidEntity> enemies = Entities.getNearby(enemyGroup, curx, cury, range * 2f);
        for (SolidEntity entity : enemies) {
            if (entity != null && entity.distanceTo(curx, cury) < range && !hit.contains((Enemy) entity)) {
                hit.add((Enemy) entity);
                points.add(new Vector2(entity.x + Mathf.range(shake), entity.y + Mathf.range(shake)));
                damageEnemy((Enemy) entity);
                curx = entity.x;
                cury = entity.y;
                break;
            }
        }
    }
    if (points.size == 0) {
        remove();
    }
}
Also used : SolidEntity(io.anuke.ucore.entities.SolidEntity) Vector2(com.badlogic.gdx.math.Vector2)

Aggregations

SolidEntity (io.anuke.ucore.entities.SolidEntity)4 Rectangle (com.badlogic.gdx.math.Rectangle)3 Vector2 (com.badlogic.gdx.math.Vector2)3 Player (io.anuke.mindustry.entities.Player)2 Vars (io.anuke.mindustry.Vars)1 SpawnPoint (io.anuke.mindustry.game.SpawnPoint)1 Recipe (io.anuke.mindustry.resource.Recipe)1 Block (io.anuke.mindustry.world.Block)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 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