Package net.sourceforge.dsnk.model

Examples of net.sourceforge.dsnk.model.MapBlock


    if (readBytes != MAP_BLOCK_LENGTH) {
      throw new IOException(
          "Cannot read data block from file, not enough bytes available");
    }

    MapBlock block = getMapBlock(data);

    return block;
  }
View Full Code Here


  public MapBlock[] readAll() throws IOException {
    ArrayList<MapBlock> list = new ArrayList<MapBlock>();

    FileInputStream fis = new FileInputStream(this.file);

    MapBlock block = null;
    try {
      while ((block = readInternal(fis)) != null) {
        list.add(block);
      }
    } catch (IOException e) {
View Full Code Here

   * @param data
   *            data read from file
   * @return MapBlock object
   */
  private MapBlock getMapBlock(byte[] data) {
    MapBlock block = new MapBlock();

    // first read unused header (4 byte)
    int header = getIntValue(data, 0);
    // then read block cells (8 * 8 = 64)
    MapCell[] cells = new MapCell[64];
    for (int i = 0; i < cells.length; i++) {
      // each cell consists of 3 bytes
      cells[i] = getMapCell(data, (i * 3) + 4);
    }

    block.setHeader(header);
    block.setCells(cells);

    return block;
  }
View Full Code Here

    if (this.blocks != null) {
      int a = (int) this.blocks.length;
      for (int i = 0; i < a; i++) {
        for (int j = 0; j < a; j++) {
          MapBlock block = this.blocks[i][j];
          MapCell[] cells = block.getCells();
          for (int k = 0; k < 8; k++) {
            for (int m = 0; m < 8; m++) {
              int index = cells[(k * 8) + m].getIndex();
              g.setColor(this.colors[index]);
              // draw blocks from top to bottom and the left to
View Full Code Here

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // read a map block
    // the map block serves as index for the land tiles
    Map0Reader reader = new Map0Reader(new File("map0.mul"));
    MapBlock block = reader.read(167, 30);
    this.blocks = new MapBlock[1][1];
    for (int i = 0; i < 1; i++) {
      for (int k = 0; k < 1; k++) {
        this.blocks[i][k] = block;
      }
    }
   
    LandTileDataReader tileReader = new LandTileDataReader(new FileInputStream("tiledata.mul"));
    this.tileGroups = tileReader.readAll();
    tileReader.close();
   
    // check if tiles are loaded
    for (MapCell cell : block.getCells()) {
      // it seams as if the radarcol index also serves as tiledata index
      int id = cell.getIndex();
      int tileGroupIdx = id / 32;
      int tileIdx = id % 32;
      LandTile tile = this.tileGroups[tileGroupIdx].getTiles()[tileIdx];
View Full Code Here

    if (this.blocks != null) {
      int a = (int) this.blocks.length;
      for (int i = 0; i < a; i++) {
        for (int j = 0; j < a; j++) {
          MapBlock block = this.blocks[i][j];
          MapCell[] cells = block.getCells();
          for (int k = 0; k < 8; k++) {
            for (int m = 0; m < 8; m++) {
              int index = cells[(k * 8) + m].getIndex();
              int tileGroupIdx = index / 32;
              int tileIdx = index % 32;
View Full Code Here

    Point pos = centerBlock.getPosition();
    if ((pos != null) && (coordOnMap(pos))) {
      // check if center block is loaded
      if (centerBlock.getTiles() == null) {
        MapBlock mapBlock = mapReader.read(pos.x, pos.y);
        DrawableBlock tmp = convertToDrawableBlock(mapBlock);
        centerBlock.setTiles(tmp.getTiles());
      }

      // load neighbors if required
      for (NeighborDirection direction : NeighborDirection.values()) {
        Point newPos = getNeighborPosition(pos, direction);
        DrawableBlock neighbor = loadedBlocks.get(newPos);
        if (neighbor == null) {
          if (coordOnMap(newPos)) {
            MapBlock mapBlock = mapReader.read(newPos.x, newPos.y);
            neighbor = convertToDrawableBlock(mapBlock);
            neighbor.setPosition(newPos);
            loadedBlocks.put(newPos, neighbor);
          }
        }
View Full Code Here

TOP

Related Classes of net.sourceforge.dsnk.model.MapBlock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.