Search in sources :

Example 1 with Enemy

use of io.anuke.mindustry.entities.enemies.Enemy 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)

Example 2 with Enemy

use of io.anuke.mindustry.entities.enemies.Enemy in project Mindustry by Anuken.

the class Shield method update.

@Override
public void update() {
    float alpha = 0.1f;
    Interpolation interp = Interpolation.fade;
    if (active) {
        uptime = interp.apply(uptime, 1f, alpha * Timers.delta());
    } else {
        uptime = interp.apply(uptime, 0f, alpha * Timers.delta());
        if (uptime <= 0.05f)
            remove();
    }
    uptime = Mathf.clamp(uptime);
    if (!(tile.block() instanceof ShieldBlock)) {
        remove();
        return;
    }
    ShieldBlock block = (ShieldBlock) tile.block();
    Entities.getNearby(bulletGroup, x, y, block.shieldRadius * 2 * uptime + 10, entity -> {
        BulletEntity bullet = (BulletEntity) entity;
        if ((bullet.owner instanceof Enemy || hitPlayers)) {
            float dst = entity.distanceTo(this);
            if (dst < drawRadius() / 2f) {
                ((ShieldBlock) tile.block()).handleBullet(tile, bullet);
            }
        }
    });
}
Also used : Interpolation(com.badlogic.gdx.math.Interpolation) Enemy(io.anuke.mindustry.entities.enemies.Enemy) ShieldBlock(io.anuke.mindustry.world.blocks.types.defense.ShieldBlock) BulletEntity(io.anuke.ucore.entities.BulletEntity)

Example 3 with Enemy

use of io.anuke.mindustry.entities.enemies.Enemy in project Mindustry by Anuken.

the class Save12 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);
    // player x/y
    stream.writeFloat(Vars.player.x);
    stream.writeFloat(Vars.player.y);
    // player health
    stream.writeInt(Vars.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);
    }
    // --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.writeInt(enemy.health);
    }
    // --MAP DATA--
    // seed
    stream.writeInt(world.getSeed());
    int totalblocks = 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.breakable()) {
                totalblocks++;
            }
        }
    }
    // tile amount
    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.breakable()) {
                // tile pos
                stream.writeInt(x + y * world.width());
                stream.writeByte(tile.link);
                // whether it has a tile entity
                stream.writeBoolean(tile.entity != null);
                // block ID
                stream.writeInt(tile.block().id);
                if (tile.entity != null) {
                    // rotation
                    stream.writeByte(tile.getRotation());
                    // health
                    stream.writeInt((int) tile.entity.health);
                    int 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 : Enemy(io.anuke.mindustry.entities.enemies.Enemy) Tile(io.anuke.mindustry.world.Tile)

Example 4 with Enemy

use of io.anuke.mindustry.entities.enemies.Enemy in project Mindustry by Anuken.

the class Save13 method read.

@Override
public void read(DataInputStream stream) throws IOException {
    /*long loadTime = */
    stream.readLong();
    // general state
    byte mode = stream.readByte();
    byte mapid = stream.readByte();
    int wave = stream.readInt();
    float wavetime = stream.readFloat();
    float playerx = stream.readFloat();
    float playery = stream.readFloat();
    int playerhealth = stream.readInt();
    Vars.player.x = playerx;
    Vars.player.y = playery;
    Vars.player.health = playerhealth;
    state.mode = GameMode.values()[mode];
    Core.camera.position.set(playerx, playery, 0);
    // weapons
    control.upgrades().getWeapons().clear();
    control.upgrades().getWeapons().add(Weapon.blaster);
    Vars.player.weaponLeft = Vars.player.weaponRight = Weapon.blaster;
    int weapons = stream.readByte();
    for (int i = 0; i < weapons; i++) {
        control.upgrades().addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
    }
    ui.hudfrag.updateWeapons();
    // inventory
    int totalItems = stream.readByte();
    Arrays.fill(state.inventory.getItems(), 0);
    for (int i = 0; i < totalItems; i++) {
        Item item = Item.getByID(stream.readByte());
        int amount = stream.readInt();
        state.inventory.getItems()[item.id] = amount;
    }
    ui.hudfrag.updateItems();
    // enemies
    Entities.clear();
    int enemies = stream.readInt();
    Array<Enemy> enemiesToUpdate = new Array<>();
    for (int i = 0; i < enemies; i++) {
        byte type = stream.readByte();
        int lane = stream.readByte();
        float x = stream.readFloat();
        float y = stream.readFloat();
        byte tier = stream.readByte();
        int health = stream.readShort();
        try {
            Enemy enemy = new Enemy(EnemyType.getByID(type));
            enemy.lane = lane;
            enemy.health = health;
            enemy.x = x;
            enemy.y = y;
            enemy.tier = tier;
            enemy.add(enemyGroup);
            enemiesToUpdate.add(enemy);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    state.enemies = enemies;
    state.wave = wave;
    state.wavetime = wavetime;
    if (!android)
        Vars.player.add();
    // map
    int seed = stream.readInt();
    world.loadMap(world.maps().getMap(mapid), seed);
    renderer.clearTiles();
    for (Enemy enemy : enemiesToUpdate) {
        enemy.node = -2;
    }
    int rocks = stream.readInt();
    for (int x = 0; x < world.width(); x++) {
        for (int y = 0; y < world.height(); y++) {
            Tile tile = world.tile(x, y);
            // remove breakables like rocks
            if (tile.breakable()) {
                world.tile(x, y).setBlock(Blocks.air);
            }
        }
    }
    for (int i = 0; i < rocks; i++) {
        int pos = stream.readInt();
        Tile tile = world.tile(pos % world.width(), pos / world.width());
        Block result = WorldGenerator.rocks.get(tile.floor());
        if (result != null)
            tile.setBlock(result);
    }
    int tiles = stream.readInt();
    for (int i = 0; i < tiles; i++) {
        int pos = stream.readInt();
        int blockid = stream.readInt();
        Tile tile = world.tile(pos % world.width(), pos / world.width());
        tile.setBlock(BlockLoader.getByOldID(blockid));
        if (blockid == Blocks.blockpart.id) {
            tile.link = stream.readByte();
        }
        if (tile.entity != null) {
            byte rotation = stream.readByte();
            short health = stream.readShort();
            int items = stream.readByte();
            tile.entity.health = health;
            tile.setRotation(rotation);
            for (int j = 0; j < items; j++) {
                int itemid = stream.readByte();
                int itemamount = stream.readInt();
                tile.entity.items[itemid] = itemamount;
            }
            tile.entity.read(stream);
        }
    }
}
Also used : Array(com.badlogic.gdx.utils.Array) Item(io.anuke.mindustry.resource.Item) Enemy(io.anuke.mindustry.entities.enemies.Enemy) Tile(io.anuke.mindustry.world.Tile) Block(io.anuke.mindustry.world.Block) IOException(java.io.IOException)

Example 5 with Enemy

use of io.anuke.mindustry.entities.enemies.Enemy in project Mindustry by Anuken.

the class Save14 method read.

@Override
public void read(DataInputStream stream) throws IOException {
    /*long loadTime = */
    stream.readLong();
    // general state
    byte mode = stream.readByte();
    byte mapid = stream.readByte();
    int wave = stream.readInt();
    float wavetime = stream.readFloat();
    // block header
    int blocksize = stream.readInt();
    IntMap<Block> map = new IntMap<>();
    for (int i = 0; i < blocksize; i++) {
        String name = readString(stream);
        int id = stream.readShort();
        map.put(id, Block.getByName(name));
    }
    float playerx = stream.readFloat();
    float playery = stream.readFloat();
    int playerhealth = stream.readInt();
    Vars.player.x = playerx;
    Vars.player.y = playery;
    Vars.player.health = playerhealth;
    state.mode = GameMode.values()[mode];
    Core.camera.position.set(playerx, playery, 0);
    // weapons
    control.upgrades().getWeapons().clear();
    control.upgrades().getWeapons().add(Weapon.blaster);
    Vars.player.weaponLeft = Vars.player.weaponRight = Weapon.blaster;
    int weapons = stream.readByte();
    for (int i = 0; i < weapons; i++) {
        control.upgrades().addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
    }
    ui.hudfrag.updateWeapons();
    // inventory
    int totalItems = stream.readByte();
    Arrays.fill(state.inventory.getItems(), 0);
    for (int i = 0; i < totalItems; i++) {
        Item item = Item.getByID(stream.readByte());
        int amount = stream.readInt();
        state.inventory.getItems()[item.id] = amount;
    }
    ui.hudfrag.updateItems();
    // enemies
    Entities.clear();
    int enemies = stream.readInt();
    Array<Enemy> enemiesToUpdate = new Array<>();
    for (int i = 0; i < enemies; i++) {
        byte type = stream.readByte();
        int lane = stream.readByte();
        float x = stream.readFloat();
        float y = stream.readFloat();
        byte tier = stream.readByte();
        int health = stream.readShort();
        try {
            Enemy enemy = new Enemy(EnemyType.getByID(type));
            enemy.lane = lane;
            enemy.health = health;
            enemy.x = x;
            enemy.y = y;
            enemy.tier = tier;
            enemy.add(enemyGroup);
            enemiesToUpdate.add(enemy);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    state.enemies = enemies;
    state.wave = wave;
    state.wavetime = wavetime;
    if (!android)
        Vars.player.add();
    // map
    int seed = stream.readInt();
    world.loadMap(world.maps().getMap(mapid), seed);
    renderer.clearTiles();
    for (Enemy enemy : enemiesToUpdate) {
        enemy.node = -2;
    }
    int rocks = stream.readInt();
    for (int x = 0; x < world.width(); x++) {
        for (int y = 0; y < world.height(); y++) {
            Tile tile = world.tile(x, y);
            // remove breakables like rocks
            if (tile.breakable()) {
                world.tile(x, y).setBlock(Blocks.air);
            }
        }
    }
    for (int i = 0; i < rocks; i++) {
        int pos = stream.readInt();
        Tile tile = world.tile(pos % world.width(), pos / world.width());
        if (tile == null)
            continue;
        Block result = WorldGenerator.rocks.get(tile.floor());
        if (result != null)
            tile.setBlock(result);
    }
    int tiles = stream.readInt();
    for (int i = 0; i < tiles; i++) {
        int pos = stream.readInt();
        int blockid = stream.readInt();
        Tile tile = world.tile(pos % world.width(), pos / world.width());
        tile.setBlock(map.get(blockid));
        if (blockid == Blocks.blockpart.id) {
            tile.link = stream.readByte();
        }
        if (tile.entity != null) {
            byte rotation = stream.readByte();
            short health = stream.readShort();
            int items = stream.readByte();
            tile.entity.health = health;
            tile.setRotation(rotation);
            for (int j = 0; j < items; j++) {
                int itemid = stream.readByte();
                int itemamount = stream.readInt();
                tile.entity.items[itemid] = itemamount;
            }
            tile.entity.read(stream);
        }
    }
}
Also used : Tile(io.anuke.mindustry.world.Tile) IOException(java.io.IOException) Array(com.badlogic.gdx.utils.Array) Item(io.anuke.mindustry.resource.Item) Enemy(io.anuke.mindustry.entities.enemies.Enemy) IntMap(com.badlogic.gdx.utils.IntMap) Block(io.anuke.mindustry.world.Block)

Aggregations

Enemy (io.anuke.mindustry.entities.enemies.Enemy)20 Tile (io.anuke.mindustry.world.Tile)10 Block (io.anuke.mindustry.world.Block)5 Array (com.badlogic.gdx.utils.Array)4 SpawnPoint (io.anuke.mindustry.game.SpawnPoint)4 Item (io.anuke.mindustry.resource.Item)4 IOException (java.io.IOException)4 BlockPart (io.anuke.mindustry.world.blocks.types.BlockPart)3 Rock (io.anuke.mindustry.world.blocks.types.Rock)3 IntMap (com.badlogic.gdx.utils.IntMap)2 FileHandle (com.badlogic.gdx.files.FileHandle)1 Interpolation (com.badlogic.gdx.math.Interpolation)1 Vector2 (com.badlogic.gdx.math.Vector2)1 Player (io.anuke.mindustry.entities.Player)1 EnemySpawn (io.anuke.mindustry.game.EnemySpawn)1 InputHandler (io.anuke.mindustry.input.InputHandler)1 ToolFragment (io.anuke.mindustry.ui.fragments.ToolFragment)1 BlockBar (io.anuke.mindustry.world.BlockBar)1 BlockPair (io.anuke.mindustry.world.ColorMapper.BlockPair)1 ShieldBlock (io.anuke.mindustry.world.blocks.types.defense.ShieldBlock)1