Search in sources :

Example 1 with IntMap

use of com.badlogic.gdx.utils.IntMap 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)

Example 2 with IntMap

use of com.badlogic.gdx.utils.IntMap 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 3 with IntMap

use of com.badlogic.gdx.utils.IntMap in project libgdx by libgdx.

the class AndroidControllers method gatherControllers.

private void gatherControllers(boolean sendEvent) {
    // gather all joysticks and gamepads, remove any disconnected ones
    IntMap<AndroidController> removedControllers = new IntMap<AndroidController>();
    removedControllers.putAll(controllerMap);
    for (int deviceId : InputDevice.getDeviceIds()) {
        InputDevice device = InputDevice.getDevice(deviceId);
        AndroidController controller = controllerMap.get(deviceId);
        if (controller != null) {
            removedControllers.remove(deviceId);
        } else {
            addController(deviceId, sendEvent);
        }
    }
    for (Entry<AndroidController> entry : removedControllers.entries()) {
        removeController(entry.key);
    }
}
Also used : InputDevice(android.view.InputDevice) IntMap(com.badlogic.gdx.utils.IntMap)

Aggregations

IntMap (com.badlogic.gdx.utils.IntMap)3 Array (com.badlogic.gdx.utils.Array)2 Enemy (io.anuke.mindustry.entities.enemies.Enemy)2 Item (io.anuke.mindustry.resource.Item)2 Block (io.anuke.mindustry.world.Block)2 Tile (io.anuke.mindustry.world.Tile)2 IOException (java.io.IOException)2 InputDevice (android.view.InputDevice)1