Exemple #1
0
  String save() {
    String file = "";
    for (int y = 0; y < BHEIGHT; y++) {
      for (int x = 0; x < BWIDTH; x++) {
        file = file + blocks[x][y].getBlock().id + ";";
      }
      file = file + ";";
    }

    file = file + "/" + player.getX() + ";" + player.getY() + ";" + player.getDirection();
    return file;
  }
Exemple #2
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);
        }
      }
    }
  }
Exemple #3
0
  public void draw() {
    try {
      for (int x = 0; x < BWIDTH; x++)
        for (int y = 0; y < BHEIGHT; y++) {
          if (!(blocks[x][y].getBlock() == Block.air)) blocks[x][y].draw();
        }

      if (player != null) {
        player.draw();
      }
    } catch (NullPointerException e) {
      logger.log("NullPointerException in World.intersects(Rectangle)", Level.DEBUG);
      logger.log("Stack:", Level.DEBUG);
      logger.log(e.getMessage(), Level.DEBUG);
    }
  }
Exemple #4
0
 public void update(float delta) {
   player.update(delta);
 }