Fga

TileGrid Class- 27 episode User

Fga
Jul 28th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package data;
  2.  
  3. public class TileGrid {
  4.  
  5. public Tile[][] map;
  6. private int tilesWide, tilesHigh;
  7.  
  8. public TileGrid() {
  9. map = new Tile[tilesWide][tilesHigh];
  10. for (int i = 0; i < map.length; i++) {
  11. for (int j = 0; j < map[i].length; j++) {
  12. map[i][j] = new Tile(i * 64, j * 64, 64, 64, TileType.Grass);
  13. }
  14. }
  15. }
  16.  
  17. public TileGrid(int[][] newMap) {
  18. this.tilesWide = newMap[0].length;
  19. this.tilesHigh = newMap.length;
  20. map = new Tile[20][15];
  21. for (int i = 0; i < map.length; i++) {
  22. for (int j = 0; j < map[i].length; j++) {
  23. switch (newMap[j][i]) {
  24. case 0:
  25. map[i][j] = new Tile(i * 64, j * 64, 64, 64, TileType.Grass);
  26. break;
  27. case 1:
  28. map[i][j] = new Tile(i * 64, j * 64, 64, 64, TileType.Dirt);
  29. break;
  30. case 2:
  31. map[i][j] = new Tile(i * 64, j * 64, 64, 64, TileType.Water);
  32. break;
  33. case 3:
  34. map[i][j] = new Tile(i * 64, j * 64, 64, 64, TileType.Lava);
  35. break;
  36. case 4:
  37. map[i][j] = new Tile(i * 64, j * 64, 64, 64, TileType.Ice);
  38. break;
  39. }
  40. }
  41. }
  42. }
  43.  
  44. public void SetTile(int xCoord, int yCoord, TileType type) {
  45. map[xCoord][yCoord] = new Tile(xCoord * 64, yCoord * 64, 64, 64, type);
  46. }
  47.  
  48. public Tile GetTile(int xPlace, int yPlace) {
  49. if (xPlace < tilesHigh && yPlace < tilesHigh && xPlace > -1 && yPlace > -1)
  50. return map[xPlace][yPlace];
  51. else
  52. return new Tile(0, 0, 0, 0, TileType.NULL);
  53. }
  54.  
  55. public void Draw() {
  56. for (int i = 0; i < map.length; i++) {
  57. for (int j = 0; j < map[i].length; j++) {
  58. map[i][j].Draw();
  59. }
  60. }
  61. }
  62.  
  63. public int getTilesWide() {
  64. return tilesWide;
  65. }
  66.  
  67. public void setTilesWide(int tilesWide) {
  68. this.tilesWide = tilesWide;
  69. }
  70.  
  71. public int getTilesHigh() {
  72. return tilesHigh;
  73. }
  74.  
  75. public void setTilesHigh(int tilesHigh) {
  76. this.tilesHigh = tilesHigh;
  77. }
  78.  
  79. }
Add Comment
Please, Sign In to add comment