Search in sources :

Example 6 with Tile

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

the class Generator method drawLaserTo.

protected void drawLaserTo(Tile tile, int rotation) {
    Tile target = laserTarget(tile, rotation);
    if (target != null) {
        boolean interfering = isInterfering(target, rotation);
        t1.trns(rotation * 90, target.block().width * tilesize / 2 + 2f + (interfering ? Vector2.dst(tile.worldx(), tile.worldy(), target.worldx(), target.worldy()) / 2f - tilesize / 2f * target.block().width + 1 : 0));
        t2.trns(rotation * 90, width * tilesize / 2 + 2f);
        if (!interfering) {
            Draw.tint(Hue.mix(Color.GRAY, Color.WHITE, 0.904f + Mathf.sin(Timers.time(), 1.7f, 0.06f)));
        } else {
            Draw.tint(Hue.mix(Color.SCARLET, Color.WHITE, 0.902f + Mathf.sin(Timers.time(), 1.7f, 0.08f)));
            if (state.is(State.playing) && Mathf.chance(Timers.delta() * 0.033)) {
                Effects.effect(Fx.laserspark, target.worldx() - t1.x, target.worldy() - t1.y);
            }
        }
        float r = interfering ? 0f : 0f;
        int relative = tile.relativeTo(target.x, target.y);
        if (relative == -1) {
            Shapes.laser("laser", "laserend", tile.worldx() + t2.x, tile.worldy() + t2.y, target.worldx() - t1.x + Mathf.range(r), target.worldy() - t1.y + Mathf.range(r), 0.7f);
        } else {
            Draw.rect("laserfull", tile.worldx() + Geometry.d4[relative].x * width * tilesize / 2f, tile.worldy() + Geometry.d4[relative].y * width * tilesize / 2f);
        }
        Draw.color();
    }
}
Also used : Tile(io.anuke.mindustry.world.Tile)

Example 7 with Tile

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

the class Junction method acceptItem.

@Override
public boolean acceptItem(Item item, Tile tile, Tile source) {
    JunctionEntity entity = tile.entity();
    boolean x = tile.x == source.x;
    if (entity == null || entity.bx == null || entity.by == null || (x && entity.bx.full()) || (!x && entity.by.full()))
        return false;
    int dir = source.relativeTo(tile.x, tile.y);
    if (dir == -1)
        return false;
    Tile to = tile.getNearby(dir);
    return to != null && to.block().acceptItem(item, to, tile);
}
Also used : Tile(io.anuke.mindustry.world.Tile)

Example 8 with Tile

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

the class LiquidJunction method handleLiquid.

@Override
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount) {
    int dir = source.relativeTo(tile.x, tile.y);
    dir = (dir + 4) % 4;
    Tile to = tile.getNearby(dir);
    Timers.run(20f, () -> {
        if (to.block() instanceof LiquidBlock && ((LiquidBlock) to.block()).acceptLiquid(to, tile, liquid, amount))
            ((LiquidBlock) to.block()).handleLiquid(to, tile, liquid, amount);
    });
}
Also used : Tile(io.anuke.mindustry.world.Tile) LiquidBlock(io.anuke.mindustry.world.blocks.types.LiquidBlock)

Example 9 with Tile

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

the class LiquidJunction method acceptLiquid.

@Override
public boolean acceptLiquid(Tile dest, Tile source, Liquid liquid, float amount) {
    int dir = source.relativeTo(dest.x, dest.y);
    dir = (dir + 4) % 4;
    Tile to = dest.getNearby(dir);
    return to != null && to.block() instanceof LiquidBlock && ((LiquidBlock) to.block()).acceptLiquid(to, dest, liquid, amount);
}
Also used : Tile(io.anuke.mindustry.world.Tile) LiquidBlock(io.anuke.mindustry.world.blocks.types.LiquidBlock)

Example 10 with Tile

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

the class Renderer method drawOverlay.

void drawOverlay() {
    // draw tutorial placement point
    if (world.getMap().name.equals("tutorial") && control.tutorial().showBlock()) {
        int x = world.getCore().x + control.tutorial().getPlacePoint().x;
        int y = world.getCore().y + control.tutorial().getPlacePoint().y;
        int rot = control.tutorial().getPlaceRotation();
        Lines.stroke(1f);
        Draw.color(Color.YELLOW);
        Lines.square(x * tilesize, y * tilesize, tilesize / 2f + Mathf.sin(Timers.time(), 4f, 1f));
        Draw.color(Color.ORANGE);
        Lines.stroke(2f);
        if (rot != -1) {
            Lines.lineAngle(x * tilesize, y * tilesize, rot * 90, 6);
        }
        Draw.reset();
    }
    // draw config selected block
    if (ui.configfrag.isShown()) {
        Tile tile = ui.configfrag.getSelectedTile();
        Draw.color(Colors.get("accent"));
        Lines.stroke(1f);
        Lines.square(tile.drawx(), tile.drawy(), tile.block().width * tilesize / 2f + 1f);
        Draw.reset();
    }
    int tilex = control.input().getBlockX();
    int tiley = control.input().getBlockY();
    if (android) {
        Vector2 vec = Graphics.world(Gdx.input.getX(0), Gdx.input.getY(0));
        tilex = Mathf.scl2(vec.x, tilesize);
        tiley = Mathf.scl2(vec.y, tilesize);
    }
    InputHandler input = control.input();
    // draw placement box
    if ((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) && (!ui.hasMouse() || android) && control.input().drawPlace())) {
        input.placeMode.draw(control.input().getBlockX(), control.input().getBlockY(), control.input().getBlockEndX(), control.input().getBlockEndY());
        Lines.stroke(1f);
        Draw.color(Color.SCARLET);
        for (SpawnPoint spawn : world.getSpawns()) {
            Lines.dashCircle(spawn.start.worldx(), spawn.start.worldy(), enemyspawnspace);
        }
        if (world.getCore() != null) {
            Draw.color(Color.LIME);
            Lines.poly(world.getSpawnX(), world.getSpawnY(), 4, 6f, Timers.time() * 2f);
        }
        if (input.breakMode == PlaceMode.holdDelete)
            input.breakMode.draw(tilex, tiley, 0, 0);
    } else if (input.breakMode.delete && control.input().drawPlace() && (input.recipe == null || !state.inventory.hasItems(input.recipe.requirements)) && (input.placeMode.delete || input.breakMode.both || !android)) {
        if (input.breakMode == PlaceMode.holdDelete)
            input.breakMode.draw(tilex, tiley, 0, 0);
        else
            input.breakMode.draw(control.input().getBlockX(), control.input().getBlockY(), control.input().getBlockEndX(), control.input().getBlockEndY());
    }
    if (ui.toolfrag.confirming) {
        ToolFragment t = ui.toolfrag;
        PlaceMode.areaDelete.draw(t.px, t.py, t.px2, t.py2);
    }
    Draw.reset();
    // draw selected block bars and info
    if (input.recipe == null && !ui.hasMouse()) {
        Tile tile = world.tileWorld(Graphics.mouseWorld().x, Graphics.mouseWorld().y);
        if (tile != null && tile.block() != Blocks.air) {
            Tile target = tile;
            if (tile.isLinked())
                target = tile.getLinked();
            if (showBlockDebug && target.entity != null) {
                Draw.color(Color.RED);
                Lines.crect(target.drawx(), target.drawy(), target.block().width * tilesize, target.block().height * tilesize);
                Vector2 v = new Vector2();
                Draw.tcolor(Color.YELLOW);
                Draw.tscl(0.25f);
                Array<Object> arr = target.block().getDebugInfo(target);
                StringBuilder result = new StringBuilder();
                for (int i = 0; i < arr.size / 2; i++) {
                    result.append(arr.get(i * 2));
                    result.append(": ");
                    result.append(arr.get(i * 2 + 1));
                    result.append("\n");
                }
                Draw.textc(result.toString(), target.drawx(), target.drawy(), v);
                Draw.color(0f, 0f, 0f, 0.5f);
                Fill.rect(target.drawx(), target.drawy(), v.x, v.y);
                Draw.textc(result.toString(), target.drawx(), target.drawy(), v);
                Draw.tscl(fontscale);
                Draw.reset();
            }
            if (Inputs.keyDown("block_info") && target.block().fullDescription != null) {
                Draw.color(Colors.get("accent"));
                Lines.crect(target.drawx(), target.drawy(), target.block().width * tilesize, target.block().height * tilesize);
                Draw.color();
            }
            if (target.entity != null) {
                int bot = 0, top = 0;
                for (BlockBar bar : target.block().bars) {
                    float offset = Mathf.sign(bar.top) * (target.block().height / 2f * tilesize + 3f + 4f * ((bar.top ? top : bot))) + (bar.top ? -1f : 0f);
                    float value = bar.value.get(target);
                    if (MathUtils.isEqual(value, -1f))
                        continue;
                    drawBar(bar.color, target.drawx(), target.drawy() + offset, value);
                    if (bar.top)
                        top++;
                    else
                        bot++;
                }
            }
            target.block().drawSelect(target);
        }
    }
    if ((!debug || showUI) && Settings.getBool("healthbars")) {
        // draw entity health bars
        for (Enemy entity : enemyGroup.all()) {
            drawHealth(entity);
        }
        for (Player player : playerGroup.all()) {
            if (!player.isDead() && !player.isAndroid)
                drawHealth(player);
        }
    }
}
Also used : InputHandler(io.anuke.mindustry.input.InputHandler) Player(io.anuke.mindustry.entities.Player) Tile(io.anuke.mindustry.world.Tile) SpawnPoint(io.anuke.mindustry.game.SpawnPoint) ToolFragment(io.anuke.mindustry.ui.fragments.ToolFragment) Vector2(com.badlogic.gdx.math.Vector2) Enemy(io.anuke.mindustry.entities.enemies.Enemy) BlockBar(io.anuke.mindustry.world.BlockBar) SpawnPoint(io.anuke.mindustry.game.SpawnPoint)

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