Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MapChunkLoad {
- public static void main(String[] args) {
- short[] groundLayer;
- int mapWidth = 9;
- int mapHeight = 9;
- int chunkWidth = mapWidth / 3; //3
- int chunkHeight = mapHeight / 3; //3
- int characterX = 8;
- int characterY = 8;
- String map = "1, 1, 1, 1, 1, 1, 1, 1, 7, " +
- "1, 8, 8, 1, 1, 1, 1, 1, 1, " +
- "1, 8, 9, 9, 1, 1, 1, 1, 1, " +
- "1, 1, 9, 9, 1, 1, 1, 1, 1, " +
- "1, 1, 1, 1, 1, 1, 1, 1, 1, " +
- "1, 1, 1, 1, 1, 1, 1, 1, 1, " +
- "1, 1, 1, 1, 1, 1, 1, 1, 1, " +
- "1, 1, 1, 1, 1, 1, 1, 1, 1, " +
- "6, 1, 1, 1, 1, 1, 1, 1, 1";
- String[] strArr = map.split(", ");
- groundLayer = new short[chunkWidth * chunkHeight];
- //load into groundLayer
- int arrayIndex = 0;
- int count = (characterX - (chunkWidth/2)) + ((characterY - (chunkHeight/2)) * mapWidth); //top left tile within chunk
- for (int y = 0; y < chunkHeight; y++){
- for (int x = 0; x < chunkWidth; x++){
- if (count > -1 && count < strArr.length){
- groundLayer[arrayIndex] = Short.parseShort(strArr[count]);
- System.out.println("arrayIndex[" + arrayIndex + "] = " + strArr[count]);
- } else {
- groundLayer[arrayIndex] = 0;
- System.out.println("arrayIndex[" + arrayIndex + "] = " + 0);
- }
- arrayIndex++;
- count++;
- }
- count += (mapWidth - chunkWidth);
- }
- System.out.println("");
- //print map grid
- int printcount = 0;
- for (int y = 0; y < chunkHeight; y++){
- for (int x = 0; x < chunkWidth; x++){
- if (x == chunkWidth - 1){
- System.out.println(groundLayer[printcount]);
- } else {
- System.out.print(groundLayer[printcount] + ", ");
- }
- printcount++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement