Search in sources :

Example 6 with Enemy

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

the class Save15 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();
    byte difficulty = stream.readByte();
    state.difficulty = Difficulty.values()[difficulty];
    // 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();
    if (!headless) {
        player.x = playerx;
        player.y = playery;
        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);
        player.weaponLeft = 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();
    } else {
        byte b = stream.readByte();
        for (int i = 0; i < b; i++) stream.readByte();
    }
    // 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;
    }
    if (!headless)
        ui.hudfrag.updateItems();
    // enemies
    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 && !headless)
        player.add();
    // map
    int seed = stream.readInt();
    world.loadMap(world.maps().getMap(mapid), seed);
    if (!headless)
        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)

Example 7 with Enemy

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

the class FortressType method behavior.

@Override
public void behavior(Enemy enemy) {
    if (enemy.distanceTo(world.getCore().worldx(), world.getCore().worldy()) <= 90f) {
        if (Timers.get(this, "spawn", spawnTime) && enemy.spawned < maxSpawn) {
            enemy.tr.trns(enemy.angle, 20f);
            Enemy s = new Enemy(EnemyTypes.fast);
            s.lane = enemy.lane;
            s.tier = enemy.tier;
            s.spawner = enemy;
            s.set(enemy.x + enemy.tr.x, enemy.y + enemy.tr.y);
            s.add();
            Effects.effect(Fx.spawn, enemy);
            enemy.spawned++;
        }
    }
}
Also used : Enemy(io.anuke.mindustry.entities.enemies.Enemy)

Example 8 with Enemy

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

the class Renderer method drawEnemyMarkers.

void drawEnemyMarkers() {
    Graphics.surface(indicatorSurface);
    Draw.color(Color.RED);
    for (Enemy enemy : enemyGroup.all()) {
        if (rect.setSize(camera.viewportWidth, camera.viewportHeight).setCenter(camera.position.x, camera.position.y).overlaps(enemy.hitbox.getRect(enemy.x, enemy.y))) {
            continue;
        }
        float angle = Angles.angle(camera.position.x, camera.position.y, enemy.x, enemy.y);
        float tx = Angles.trnsx(angle, Unit.dp.scl(20f));
        float ty = Angles.trnsy(angle, Unit.dp.scl(20f));
        Draw.rect("enemyarrow", camera.position.x + tx, camera.position.y + ty, angle);
    }
    Draw.color();
    Draw.alpha(0.4f);
    Graphics.flushSurface();
    Draw.color();
}
Also used : Enemy(io.anuke.mindustry.entities.enemies.Enemy)

Example 9 with Enemy

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

the class Save12 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.readInt();
        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();
    int tiles = stream.readInt();
    world.loadMap(world.maps().getMap(mapid), seed);
    renderer.clearTiles();
    for (Enemy enemy : enemiesToUpdate) {
        enemy.node = -2;
    }
    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 < tiles; i++) {
        int pos = stream.readInt();
        byte link = stream.readByte();
        boolean hasEntity = stream.readBoolean();
        int blockid = stream.readInt();
        Tile tile = world.tile(pos % world.width(), pos / world.width());
        tile.setBlock(BlockLoader.getByOldID(blockid));
        tile.link = link;
        if (hasEntity) {
            byte rotation = stream.readByte();
            int health = stream.readInt();
            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) IOException(java.io.IOException)

Example 10 with Enemy

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

the class Save13 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.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.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.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.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) Tile(io.anuke.mindustry.world.Tile)

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