Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. public class MapChunkLoad {
  2.  
  3. public static void main(String[] args) {
  4. short[] groundLayer;
  5. int mapWidth = 9;
  6. int mapHeight = 9;
  7. int chunkWidth = mapWidth / 3; //3
  8. int chunkHeight = mapHeight / 3; //3
  9. int characterX = 8;
  10. int characterY = 8;
  11. String map = "1, 1, 1, 1, 1, 1, 1, 1, 7, " +
  12. "1, 8, 8, 1, 1, 1, 1, 1, 1, " +
  13. "1, 8, 9, 9, 1, 1, 1, 1, 1, " +
  14. "1, 1, 9, 9, 1, 1, 1, 1, 1, " +
  15. "1, 1, 1, 1, 1, 1, 1, 1, 1, " +
  16. "1, 1, 1, 1, 1, 1, 1, 1, 1, " +
  17. "1, 1, 1, 1, 1, 1, 1, 1, 1, " +
  18. "1, 1, 1, 1, 1, 1, 1, 1, 1, " +
  19. "6, 1, 1, 1, 1, 1, 1, 1, 1";
  20. String[] strArr = map.split(", ");
  21. groundLayer = new short[chunkWidth * chunkHeight];
  22.  
  23. //load into groundLayer
  24. int arrayIndex = 0;
  25. int count = (characterX - (chunkWidth/2)) + ((characterY - (chunkHeight/2)) * mapWidth); //top left tile within chunk
  26.  
  27. for (int y = 0; y < chunkHeight; y++){
  28. for (int x = 0; x < chunkWidth; x++){
  29. if (count > -1 && count < strArr.length){
  30. groundLayer[arrayIndex] = Short.parseShort(strArr[count]);
  31. System.out.println("arrayIndex[" + arrayIndex + "] = " + strArr[count]);
  32. } else {
  33. groundLayer[arrayIndex] = 0;
  34. System.out.println("arrayIndex[" + arrayIndex + "] = " + 0);
  35. }
  36.  
  37. arrayIndex++;
  38. count++;
  39. }
  40. count += (mapWidth - chunkWidth);
  41. }
  42.  
  43. System.out.println("");
  44. //print map grid
  45. int printcount = 0;
  46. for (int y = 0; y < chunkHeight; y++){
  47. for (int x = 0; x < chunkWidth; x++){
  48. if (x == chunkWidth - 1){
  49. System.out.println(groundLayer[printcount]);
  50. } else {
  51. System.out.print(groundLayer[printcount] + ", ");
  52. }
  53. printcount++;
  54. }
  55. }
  56.  
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement