Search in sources :

Example 41 with Tile

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

the class TunnelConveyor method getDestTunnel.

Tile getDestTunnel(Tile tile, Item item) {
    Tile dest = tile;
    int rel = (tile.getRotation() + 2) % 4;
    for (int i = 0; i < maxdist; i++) {
        if (dest == null)
            return null;
        dest = dest.getNearby(rel);
        if (dest != null && dest.block() instanceof TunnelConveyor && dest.getRotation() == rel && dest.getNearby(rel) != null && dest.getNearby(rel).block().acceptItem(item, dest.getNearby(rel), dest)) {
            return dest;
        }
    }
    return null;
}
Also used : Tile(io.anuke.mindustry.world.Tile)

Example 42 with Tile

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

the class Generator method laserTarget.

protected Tile laserTarget(Tile tile, int rotation) {
    rotation = Mathf.mod(rotation, 4);
    GridPoint2 point = Geometry.d4[rotation];
    for (int i = 1; i < laserRange; i++) {
        Tile other = world.tile(tile.x + i * point.x, tile.y + i * point.y);
        if (other != null && other.block() instanceof PowerAcceptor) {
            Tile linked = other.getLinked();
            if (linked == null || linked instanceof PowerAcceptor) {
                return other;
            }
        }
    }
    return null;
}
Also used : PowerAcceptor(io.anuke.mindustry.world.blocks.types.PowerAcceptor) Tile(io.anuke.mindustry.world.Tile) GridPoint2(com.badlogic.gdx.math.GridPoint2)

Example 43 with Tile

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

the class Junction method update.

@Override
public void update(Tile tile) {
    JunctionEntity entity = tile.entity();
    for (int i = 0; i < 2; i++) {
        Buffer buffer = (i == 0 ? entity.bx : entity.by);
        if (buffer.index > 0) {
            if (buffer.index > buffer.items.length)
                buffer.index = buffer.items.length;
            long l = buffer.items[0];
            float time = NumberUtils.intBitsToFloat(Bits.getLeftInt(l));
            if (Timers.time() >= time + speed || Timers.time() < time) {
                int val = Bits.getRightInt(l);
                Item item = Item.getByID(Bits.getLeftShort(val));
                int direction = Bits.getRightShort(val);
                Tile dest = tile.getNearby(direction);
                if (dest == null || !dest.block().acceptItem(item, dest, tile))
                    continue;
                dest.block().handleItem(item, dest, tile);
                System.arraycopy(buffer.items, 1, buffer.items, 0, buffer.index - 1);
                buffer.index--;
            }
        }
    }
}
Also used : Item(io.anuke.mindustry.resource.Item) Tile(io.anuke.mindustry.world.Tile)

Example 44 with Tile

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

the class PowerBooster method distributePower.

// TODO better distribution
protected void distributePower(Tile tile) {
    PowerEntity p = tile.entity();
    if (!p.timer.get(timerGenerate, powerTime)) {
        return;
    }
    int acceptors = 0;
    float flow = 0f;
    for (int i = 0; i < 2; i++) {
        for (int x = -powerRange; x <= powerRange; x++) {
            for (int y = -powerRange; y <= powerRange; y++) {
                if (x == 0 && y == 0) {
                    continue;
                }
                if (Vector2.dst(x, y, 0, 0) < powerRange) {
                    Tile dest = world.tile(tile.x + x, tile.y + y);
                    if (dest != null && dest.block() instanceof PowerAcceptor && ((PowerAcceptor) dest.block()).acceptsPower(dest)) {
                        if (i == 1) {
                            PowerAcceptor block = (PowerAcceptor) dest.block();
                            float transmission = Math.min(flow, p.power);
                            float amount = block.addPower(dest, transmission);
                            p.power -= amount;
                        } else {
                            acceptors++;
                        }
                    }
                }
            }
        }
        // TODO better distribution scheme
        if (i == 0 && acceptors > 0) {
            flow = Mathf.clamp(p.power / acceptors, 0f, powerSpeed / acceptors * Timers.delta());
        }
    }
}
Also used : PowerAcceptor(io.anuke.mindustry.world.blocks.types.PowerAcceptor) Tile(io.anuke.mindustry.world.Tile)

Example 45 with Tile

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

the class RepairTurret method drawLayer2.

@Override
public void drawLayer2(Tile tile) {
    PowerTurretEntity entity = tile.entity();
    TileEntity target = entity.blockTarget;
    if (entity.power >= powerUsed && target != null && Angles.angleDist(entity.angleTo(target), entity.rotation) < 10) {
        Tile targetTile = target.tile;
        float len = 4f;
        float x = tile.drawx() + Angles.trnsx(entity.rotation, len), y = tile.drawy() + Angles.trnsy(entity.rotation, len);
        float x2 = targetTile.drawx(), y2 = targetTile.drawy();
        Draw.color(Hue.rgb(138, 244, 138, (MathUtils.sin(Timers.time()) + 1f) / 14f));
        Draw.alpha(0.3f);
        Lines.stroke(4f);
        Lines.line(x, y, x2, y2);
        Lines.stroke(2f);
        Draw.rect("circle", x2, y2, 7f, 7f);
        Draw.alpha(1f);
        Lines.stroke(2f);
        Lines.line(x, y, x2, y2);
        Lines.stroke(1f);
        Draw.rect("circle", x2, y2, 5f, 5f);
        Draw.reset();
    }
}
Also used : TileEntity(io.anuke.mindustry.entities.TileEntity) 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