Search in sources :

Example 11 with Tile

use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.

the class AndroidInput method breakBlock.

public void breakBlock() {
    Tile tile = selected();
    breaktime += Timers.delta();
    if (breaktime >= tile.block().breaktime) {
        brokeBlock = true;
        breakBlock(tile.x, tile.y, true);
        breaktime = 0f;
    }
}
Also used : Tile(io.anuke.mindustry.world.Tile)

Example 12 with Tile

use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.

the class AndroidInput method touchDown.

@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    if (ui.hasMouse()) {
        brokeBlock = true;
        return false;
    }
    lmousex = screenX;
    lmousey = screenY;
    if ((!placeMode.pan || breaking()) && pointer == 0) {
        mousex = screenX;
        mousey = screenY;
    }
    placing = pointer == 0;
    warmup = 0;
    if (!state.is(State.menu)) {
        Tile cursor = world.tile(Mathf.scl2(Graphics.mouseWorld().x, tilesize), Mathf.scl2(Graphics.mouseWorld().y, tilesize));
        if (cursor != null && !ui.hasMouse(screenX, screenY)) {
            Tile linked = cursor.isLinked() ? cursor.getLinked() : cursor;
            if (linked != null && linked.block().isConfigurable(linked)) {
                ui.configfrag.showConfig(linked);
            } else if (!ui.configfrag.hasConfigMouse()) {
                ui.configfrag.hideConfig();
            }
            if (linked != null) {
                linked.block().tapped(linked);
                if (Net.active())
                    NetEvents.handleBlockTap(linked);
            }
        }
    }
    return false;
}
Also used : Tile(io.anuke.mindustry.world.Tile)

Example 13 with Tile

use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.

the class AndroidInput method update.

@Override
public void update() {
    enableHold = breakMode == PlaceMode.holdDelete;
    float xa = Inputs.getAxis("move_x");
    float ya = Inputs.getAxis("move_y");
    if (Math.abs(xa) < controllerMin)
        xa = 0;
    if (Math.abs(ya) < controllerMin)
        ya = 0;
    player.x += xa * 4f;
    player.y += ya * 4f;
    rotation += Inputs.getAxis("rotate_alt");
    rotation += Inputs.getAxis("rotate");
    rotation = Mathf.mod(rotation, 4);
    if (enableHold && Gdx.input.isTouched(0) && Mathf.near2d(lmousex, lmousey, Gdx.input.getX(0), Gdx.input.getY(0), Unit.dp.scl(50)) && !ui.hasMouse()) {
        warmup += Timers.delta();
        float lx = mousex, ly = mousey;
        mousex = Gdx.input.getX(0);
        mousey = Gdx.input.getY(0);
        Tile sel = selected();
        if (sel == null)
            return;
        if (warmup > warmupDelay && validBreak(sel.x, sel.y)) {
            breaktime += Timers.delta();
            if (breaktime > selected().block().breaktime) {
                breakBlock();
                breaktime = 0;
            }
        }
        mousex = lx;
        mousey = ly;
    } else {
        warmup = 0;
        breaktime = 0;
        mousex = Mathf.clamp(mousex, 0, Gdx.graphics.getWidth());
        mousey = Mathf.clamp(mousey, 0, Gdx.graphics.getHeight());
    }
}
Also used : Tile(io.anuke.mindustry.world.Tile)

Example 14 with Tile

use of io.anuke.mindustry.world.Tile 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 15 with Tile

use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.

the class EnemyType method update.

public void update(Enemy enemy) {
    float lastx = enemy.x, lasty = enemy.y;
    if (enemy.hitTime > 0) {
        enemy.hitTime -= Timers.delta();
    }
    if (enemy.lane >= world.getSpawns().size || enemy.lane < 0)
        enemy.lane = 0;
    boolean waiting = enemy.lane >= world.getSpawns().size || enemy.lane < 0 || world.getSpawns().get(enemy.lane).pathTiles == null || enemy.node <= 0;
    move(enemy);
    enemy.velocity.set(enemy.x - lastx, enemy.y - lasty).scl(1f / Timers.delta());
    enemy.totalMove.add(enemy.velocity);
    float minv = 0.07f;
    if (enemy.timer.get(timerReset, 80)) {
        enemy.totalMove.setZero();
    }
    if (enemy.velocity.len() < minv && !waiting && enemy.target == null) {
        enemy.idletime += Timers.delta();
    } else {
        enemy.idletime = 0;
    }
    if (enemy.timer.getTime(timerReset) > 50 && enemy.totalMove.len() < 0.2f && !waiting && enemy.target == null) {
        enemy.idletime = 999999f;
    }
    Tile tile = world.tileWorld(enemy.x, enemy.y);
    if (tile != null && tile.floor().liquid && tile.block() == Blocks.air) {
        // drown
        enemy.damage(enemy.health + 1);
    }
    if (Float.isNaN(enemy.angle)) {
        enemy.angle = 0;
    }
    if (enemy.target == null || alwaysRotate) {
        enemy.angle = Mathf.slerpDelta(enemy.angle, enemy.velocity.angle(), rotatespeed);
    } else {
        enemy.angle = Mathf.slerpDelta(enemy.angle, enemy.angleTo(enemy.target), turretrotatespeed);
    }
    enemy.x = Mathf.clamp(enemy.x, 0, world.width() * tilesize);
    enemy.y = Mathf.clamp(enemy.y, 0, world.height() * tilesize);
}
Also used : Tile(io.anuke.mindustry.world.Tile)

Aggregations

Tile (io.anuke.mindustry.world.Tile)45 Enemy (io.anuke.mindustry.entities.enemies.Enemy)10 Item (io.anuke.mindustry.resource.Item)7 SpawnPoint (io.anuke.mindustry.game.SpawnPoint)6 Block (io.anuke.mindustry.world.Block)6 Vector2 (com.badlogic.gdx.math.Vector2)5 IOException (java.io.IOException)5 Array (com.badlogic.gdx.utils.Array)4 Player (io.anuke.mindustry.entities.Player)3 BlockPart (io.anuke.mindustry.world.blocks.types.BlockPart)3 PowerAcceptor (io.anuke.mindustry.world.blocks.types.PowerAcceptor)3 Rock (io.anuke.mindustry.world.blocks.types.Rock)3 IntMap (com.badlogic.gdx.utils.IntMap)2 LiquidBlock (io.anuke.mindustry.world.blocks.types.LiquidBlock)2 StaticBlock (io.anuke.mindustry.world.blocks.types.StaticBlock)2 GridPoint2 (com.badlogic.gdx.math.GridPoint2)1 Rectangle (com.badlogic.gdx.math.Rectangle)1 Vars (io.anuke.mindustry.Vars)1 TileEntity (io.anuke.mindustry.entities.TileEntity)1 Difficulty (io.anuke.mindustry.game.Difficulty)1