Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. package theGame;
  2.  
  3. /**
  4.  *
  5.  * @author marius.patt
  6.  */
  7.  
  8. import java.awt.Graphics;
  9.  
  10. public class Level {
  11.   private TileSet ts;
  12.   private int sizeX, sizeY;
  13.   private int[][] tileMap;
  14.  
  15.   public Level(String path, TileSet ts) {
  16.     this.ts = ts;
  17.     String file = Util.loadFileAsString(path);
  18.     String[] tokens = file.split("\\s+");
  19.     sizeX = Util.parseInt(tokens[0]);
  20.     sizeY = Util.parseInt(tokens[1]);
  21.     tileMap = new int[sizeX][sizeY];
  22.     int i = 2;
  23.     for(int y = 0; y < sizeY; y++){
  24.       for(int x = 0; x < sizeX; x++){
  25.         tileMap[x][y] = Util.parseInt(tokens[i++]);
  26.       }
  27.     }
  28.   }
  29.  
  30.   public void renderMap(Graphics g){
  31.     for(int tileY = 0; tileY < sizeY; tileY++){
  32.       for(int tileX = 0; tileX < sizeX; tileX++){
  33.         ts.renderTile(g, tileMap[tileX][tileY], tileX * TileSet.TILEWIDTH, tileY * TileSet.TILEHEIGHT);
  34.       }
  35.     }
  36.   }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement