Ejemplo n.º 1
0
  void load(String mundo) {
    int px = 0, py = 0, pdir = 0;
    try {
      String[] partes;
      partes = mundo.split("/");
      px = Integer.valueOf(partes[1].split(";")[0]);
      py = Integer.valueOf(partes[1].split(";")[1]);
      pdir = Integer.valueOf(partes[1].split(";")[2]);

      int y = 0;
      for (String fila : partes[0].split(";;")) {
        int x = 0;
        for (String id : fila.split(";")) {
          blocks[x][y] =
              new InstanceBlock(
                  Block.blocksList[Integer.valueOf(id)], x * Block.SIZE, y * Block.SIZE, this);
          x++;
        }
        y++;
      }
    } catch (Exception e) {
      for (int x = 0; x < BWIDTH; x++)
        for (int y = 0; y < BHEIGHT; y++)
          blocks[x][y] = new InstanceBlock(Block.stone, x * Block.SIZE, y * Block.SIZE, this);
    }
    if (player != null) {
      player.setX(px);
      player.setY(py);
      player.setLastDir(pdir);
    }
    for (int x = 0; x < BWIDTH; x++) {
      for (int y = 0; y < BHEIGHT; y++) {
        if (blocks[x][y] == null) {
          blocks[x][y] = new InstanceBlock(Block.stone, x * Block.SIZE, y * Block.SIZE, this);
        }
      }
    }
  }