Search in sources :

Example 11 with Block

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

the class Save15 method write.

@Override
public void write(DataOutputStream stream) throws IOException {
    // --META--
    // version id
    stream.writeInt(version);
    // last saved
    stream.writeLong(TimeUtils.millis());
    // --GENERAL STATE--
    // gamemode
    stream.writeByte(state.mode.ordinal());
    // map ID
    stream.writeByte(world.getMap().id);
    // wave
    stream.writeInt(state.wave);
    // wave countdown
    stream.writeFloat(state.wavetime);
    stream.writeByte(state.difficulty.ordinal());
    // --BLOCK HEADER--
    stream.writeInt(Block.getAllBlocks().size);
    for (int i = 0; i < Block.getAllBlocks().size; i++) {
        Block block = Block.getAllBlocks().get(i);
        writeString(stream, block.name);
        stream.writeShort(block.id);
    }
    if (!headless) {
        // player x/y
        stream.writeFloat(player.x);
        stream.writeFloat(player.y);
        // player health
        stream.writeInt(player.health);
        // amount of weapons
        stream.writeByte(control.upgrades().getWeapons().size - 1);
        // start at 1, because the first weapon is always the starter - ignore that
        for (int i = 1; i < control.upgrades().getWeapons().size; i++) {
            // weapon ordinal
            stream.writeByte(control.upgrades().getWeapons().get(i).id);
        }
    } else {
        stream.writeFloat(world.getSpawnX());
        stream.writeFloat(world.getSpawnY());
        stream.writeInt(150);
        stream.writeByte(0);
    }
    // --INVENTORY--
    int l = state.inventory.getItems().length;
    int itemsize = 0;
    for (int i = 0; i < l; i++) {
        if (state.inventory.getItems()[i] > 0) {
            itemsize++;
        }
    }
    // amount of items
    stream.writeByte(itemsize);
    for (int i = 0; i < l; i++) {
        if (state.inventory.getItems()[i] > 0) {
            // item ID
            stream.writeByte(i);
            // item amount
            stream.writeInt(state.inventory.getItems()[i]);
        }
    }
    // --ENEMIES--
    EntityContainer<Enemy> enemies = enemyGroup.all();
    // enemy amount
    stream.writeInt(enemies.size());
    for (int i = 0; i < enemies.size(); i++) {
        Enemy enemy = enemies.get(i);
        // type
        stream.writeByte(enemy.type.id);
        // lane
        stream.writeByte(enemy.lane);
        // x
        stream.writeFloat(enemy.x);
        // y
        stream.writeFloat(enemy.y);
        // tier
        stream.writeByte(enemy.tier);
        // health
        stream.writeShort(enemy.health);
    }
    // --MAP DATA--
    // seed
    stream.writeInt(world.getSeed());
    int totalblocks = 0;
    int totalrocks = 0;
    for (int x = 0; x < world.width(); x++) {
        for (int y = 0; y < world.height(); y++) {
            Tile tile = world.tile(x, y);
            if (tile != null && tile.breakable()) {
                if (tile.block() instanceof Rock) {
                    totalrocks++;
                } else {
                    totalblocks++;
                }
            }
        }
    }
    // amount of rocks
    stream.writeInt(totalrocks);
    // write all rocks
    for (int x = 0; x < world.width(); x++) {
        for (int y = 0; y < world.height(); y++) {
            Tile tile = world.tile(x, y);
            if (tile != null && tile.block() instanceof Rock) {
                stream.writeInt(tile.packedPosition());
            }
        }
    }
    // write all blocks
    stream.writeInt(totalblocks);
    for (int x = 0; x < world.width(); x++) {
        for (int y = 0; y < world.height(); y++) {
            Tile tile = world.tile(x, y);
            if (tile != null && tile.breakable() && !(tile.block() instanceof Rock)) {
                // tile pos
                stream.writeInt(x + y * world.width());
                // block ID
                stream.writeInt(tile.block().id);
                if (tile.block() instanceof BlockPart)
                    stream.writeByte(tile.link);
                if (tile.entity != null) {
                    // rotation
                    stream.writeByte(tile.getRotation());
                    // health
                    stream.writeShort((short) tile.entity.health);
                    byte amount = 0;
                    for (int i = 0; i < tile.entity.items.length; i++) {
                        if (tile.entity.items[i] > 0)
                            amount++;
                    }
                    // amount of items
                    stream.writeByte(amount);
                    for (int i = 0; i < tile.entity.items.length; i++) {
                        if (tile.entity.items[i] > 0) {
                            // item ID
                            stream.writeByte(i);
                            // item amount
                            stream.writeInt(tile.entity.items[i]);
                        }
                    }
                    tile.entity.write(stream);
                }
            }
        }
    }
}
Also used : BlockPart(io.anuke.mindustry.world.blocks.types.BlockPart) Rock(io.anuke.mindustry.world.blocks.types.Rock) Enemy(io.anuke.mindustry.entities.enemies.Enemy) Block(io.anuke.mindustry.world.Block) Tile(io.anuke.mindustry.world.Tile)

Example 12 with Block

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

the class MapEditorDialog method updateSelectedBlock.

public void updateSelectedBlock() {
    Block block = editor.getDrawBlock();
    int i = 0;
    for (BlockPair pair : ColorMapper.getPairs()) {
        if (pair.wall == block || (pair.wall == Blocks.air && pair.floor == block)) {
            blockgroup.getButtons().get(i).setChecked(true);
            break;
        }
        i++;
    }
}
Also used : BlockPair(io.anuke.mindustry.world.ColorMapper.BlockPair) Block(io.anuke.mindustry.world.Block)

Example 13 with Block

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

the class MapEditorDialog method addBlockSelection.

private void addBlockSelection(Table table) {
    Table content = new Table();
    pane = new ScrollPane(content, "volume");
    pane.setScrollingDisabled(true, false);
    pane.setFadeScrollBars(false);
    pane.setOverscroll(true, false);
    ButtonGroup<ImageButton> group = new ButtonGroup<>();
    blockgroup = group;
    int i = 0;
    for (BlockPair pair : ColorMapper.getPairs()) {
        Block block = pair.wall == Blocks.air ? pair.floor : pair.wall;
        ImageButton button = new ImageButton(Draw.hasRegion(block.name) ? Draw.region(block.name) : Draw.region(block.name + "1"), "toggle");
        button.clicked(() -> editor.setDrawBlock(block));
        button.resizeImage(8 * 4f);
        group.add(button);
        content.add(button).pad(4f).size(53f, 58f);
        if (i++ % 2 == 1) {
            content.row();
        }
    }
    group.getButtons().get(2).setChecked(true);
    Table extra = new Table("button");
    extra.labelWrap(() -> editor.getDrawBlock().formalName).width(180f).center();
    table.add(extra).padBottom(-6).growX();
    table.row();
    table.add(pane).growY().fillX();
}
Also used : Table(io.anuke.ucore.scene.ui.layout.Table) BlockPair(io.anuke.mindustry.world.ColorMapper.BlockPair) Block(io.anuke.mindustry.world.Block)

Example 14 with Block

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

the class BlockRenderer method processBlocks.

/**
 *Process all blocks to draw, simultaneously drawing block shadows and static blocks.
 */
public void processBlocks() {
    requestidx = 0;
    int crangex = (int) (camera.viewportWidth / (chunksize * tilesize)) + 1;
    int crangey = (int) (camera.viewportHeight / (chunksize * tilesize)) + 1;
    int rangex = (int) (camera.viewportWidth * camera.zoom / tilesize / 2) + 2;
    int rangey = (int) (camera.viewportHeight * camera.zoom / tilesize / 2) + 2;
    int expandr = 3;
    Graphics.surface(renderer.shadowSurface);
    for (int x = -rangex - expandr; x <= rangex + expandr; x++) {
        for (int y = -rangey - expandr; y <= rangey + expandr; y++) {
            int worldx = Mathf.scl(camera.position.x, tilesize) + x;
            int worldy = Mathf.scl(camera.position.y, tilesize) + y;
            boolean expanded = (x < -rangex || x > rangex || y < -rangey || y > rangey);
            Tile tile = world.tile(worldx, worldy);
            if (tile != null) {
                Block block = tile.block();
                if (!expanded && block != Blocks.air && world.isAccessible(worldx, worldy)) {
                    block.drawShadow(tile);
                }
                if (!(block instanceof StaticBlock)) {
                    if (block == Blocks.air) {
                        if (!state.is(State.paused))
                            tile.floor().update(tile);
                    } else {
                        if (!expanded) {
                            addRequest(tile, Layer.block);
                        }
                        if (block.expanded || !expanded) {
                            if (block.layer != null && block.isLayer(tile)) {
                                addRequest(tile, block.layer);
                            }
                            if (block.layer2 != null && block.isLayer2(tile)) {
                                addRequest(tile, block.layer2);
                            }
                        }
                    }
                }
            }
        }
    }
    Draw.color(0, 0, 0, 0.15f);
    Graphics.flushSurface();
    Draw.color();
    Graphics.end();
    drawCache(1, crangex, crangey);
    Graphics.begin();
    Arrays.sort(requests.items, 0, requestidx);
    iterateidx = 0;
}
Also used : Tile(io.anuke.mindustry.world.Tile) Block(io.anuke.mindustry.world.Block) StaticBlock(io.anuke.mindustry.world.blocks.types.StaticBlock) StaticBlock(io.anuke.mindustry.world.blocks.types.StaticBlock) SpawnPoint(io.anuke.mindustry.game.SpawnPoint)

Example 15 with Block

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

the class BlockRenderer method drawBlocks.

public void drawBlocks(boolean top) {
    Layer stopAt = top ? Layer.laser : Layer.overlay;
    for (; iterateidx < requestidx; iterateidx++) {
        if (iterateidx < requests.size - 1 && requests.get(iterateidx).layer.ordinal() > stopAt.ordinal()) {
            break;
        }
        BlockRequest req = requests.get(iterateidx);
        Block block = req.tile.block();
        if (req.layer == Layer.block) {
            block.draw(req.tile);
        } else if (req.layer == block.layer) {
            block.drawLayer(req.tile);
        } else if (req.layer == block.layer2) {
            block.drawLayer2(req.tile);
        }
    }
}
Also used : Block(io.anuke.mindustry.world.Block) StaticBlock(io.anuke.mindustry.world.blocks.types.StaticBlock) Layer(io.anuke.mindustry.world.Layer)

Aggregations

Block (io.anuke.mindustry.world.Block)16 Tile (io.anuke.mindustry.world.Tile)6 Enemy (io.anuke.mindustry.entities.enemies.Enemy)5 Array (com.badlogic.gdx.utils.Array)3 Item (io.anuke.mindustry.resource.Item)3 BlockPair (io.anuke.mindustry.world.ColorMapper.BlockPair)3 IOException (java.io.IOException)3 GridPoint2 (com.badlogic.gdx.math.GridPoint2)2 IntMap (com.badlogic.gdx.utils.IntMap)2 BlockPart (io.anuke.mindustry.world.blocks.types.BlockPart)2 Rock (io.anuke.mindustry.world.blocks.types.Rock)2 StaticBlock (io.anuke.mindustry.world.blocks.types.StaticBlock)2 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 Rectangle (com.badlogic.gdx.math.Rectangle)1 SpawnPoint (io.anuke.mindustry.game.SpawnPoint)1 Layer (io.anuke.mindustry.world.Layer)1 Floor (io.anuke.mindustry.world.blocks.types.Floor)1 SolidEntity (io.anuke.ucore.entities.SolidEntity)1 Table (io.anuke.ucore.scene.ui.layout.Table)1