Guest User

Untitled

a guest
Nov 18th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. package org.dx2.xview.map;
  2.  
  3. import net.openrs.cache.def.OverlayDefinition;
  4. import net.openrs.cache.def.UnderlayDefinition;
  5.  
  6. import org.dx2.xview.map.util.TileUtils;
  7.  
  8. /**
  9. * Represents a tile on a MapImage (the 64x64 coordinate).
  10. * @author `Discardedx2
  11. */
  12. public final class MapTileImage {
  13.  
  14. /**
  15. * The x position of this tile.
  16. */
  17. private int tileX;
  18. /**
  19. * The y position of this tile.
  20. */
  21. private int tileY;
  22. /**
  23. * This tile's blended colour a.
  24. */
  25. private int blendColourA;
  26. /**
  27. * This tile's blended colour b.
  28. */
  29. private int blendColourB;
  30. /**
  31. * This tile's overlay.
  32. */
  33. private int overlay;
  34. /**
  35. * This tile's underlay.
  36. */
  37. private int underlay;
  38. /**
  39. * This tile's palette.
  40. */
  41. private int[] tilePalette;
  42. /**
  43. * This tile's wall.
  44. */
  45. private MapTileWall wall;
  46.  
  47. /**
  48. * Constructs a new MapImage.
  49. * @param tileX The 64x64 x coordinate.
  50. * @param tileY The 64x64 y coordinate.
  51. */
  52. public MapTileImage(int tileX, int tileY) {
  53. this.tileX = tileX;
  54. this.tileY = tileY;
  55. }
  56.  
  57. /**
  58. * Render's this tile's colour palette
  59. * onto the main image, in which we can then output.
  60. * @param renderer The renderer to render too.
  61. */
  62. public void draw(MapRenderer renderer) {
  63. int drawX = tileX * 8;
  64. int drawY = tileY * 8;
  65. boolean blendedTile = false;
  66. if (!blendedTile || blendColourA == 0 && blendColourB == 0) {
  67. if (underlay != 0) {
  68. tilePalette = UnderlayDefinition.get(underlay).getColourPalette();
  69. for(int sectorX = 0; sectorX < 8; sectorX++) {
  70. for(int sectorY = 0; sectorY < 8; sectorY++) {
  71. renderer.fillPixel((sectorX + drawX), (sectorY + drawY), tilePalette[sectorX * sectorY]);
  72. }
  73. }
  74. }
  75. if (overlay != 0) {
  76. tilePalette = OverlayDefinition.get(overlay).getColourPalette();
  77. for(int sectorX = 0; sectorX < 8; sectorX++) {
  78. for(int sectorY = 0; sectorY < 8; sectorY++) {
  79. renderer.fillPixel((sectorX + drawX), (sectorY + drawY), tilePalette[sectorX * sectorY]);
  80. }
  81. }
  82. }
  83. } else {
  84. int[][] blendedTilePixels = TileUtils.getBlendedPixels(blendColourA);
  85. for(int pixel = 0; pixel < blendedTilePixels.length; pixel++) {
  86. renderer.fillPixel((blendedTilePixels[pixel][0] + drawX), (blendedTilePixels[pixel][1] + drawY), 0xe43243);
  87. }
  88. }
  89. if (wall != null) {
  90. int sizeX = tileX * 8;
  91. int sizeY = tileY * 8;
  92. switch(wall.getType()) {
  93. case 0:
  94. for (int x = 0; x < sizeX; x++) {
  95. for (int i = 0; i < 5; i++) {
  96. renderer.fillPixel((x + sizeX), (sizeY + i), 0xFFFFFF);
  97. }
  98. }
  99. break;
  100. }
  101. }
  102. }
  103.  
  104. /**
  105. * Gets the 64x64 x coordinate.
  106. * @return the tileX.
  107. */
  108. public int getTileX() {
  109. return tileX;
  110. }
  111.  
  112. /**
  113. * Gets the 64x64 y coordinate.
  114. * @return the tileY.
  115. */
  116. public int getTileY() {
  117. return tileY;
  118. }
  119.  
  120. /**
  121. * Gets this tile's blended colour a.
  122. * @return the shapeA.
  123. */
  124. public int getBlendedColourA() {
  125. return blendColourA;
  126. }
  127.  
  128. /**
  129. * Sets this tile's shape a.
  130. * @param shapeA the shapeA to set.
  131. */
  132. public void setBlendedColourA(int shapeA) {
  133. this.blendColourA = shapeA;
  134. }
  135.  
  136. /**
  137. * Gets this tile's blended colour b.
  138. * @return the shapeB.
  139. */
  140. public int getBlendedColourB() {
  141. return blendColourB;
  142. }
  143.  
  144. /**
  145. * Sets this tile's blended colour b.
  146. * @param shapeB the shapeB to set.
  147. */
  148. public void setBlendedColourB(int shapeB) {
  149. this.blendColourB = shapeB;
  150. }
  151.  
  152. /**
  153. * Gets this tile's overlay.
  154. * @return the overlay.
  155. */
  156. public int getOverlay() {
  157. return overlay;
  158. }
  159.  
  160. /**
  161. * Sets this tile's overlay.
  162. * @param overlay the overlay to set.
  163. */
  164. public void setOverlay(int overlay) {
  165. this.overlay = overlay;
  166. }
  167.  
  168. /**
  169. * Gets this tile's underlay.
  170. * @return the underlay.
  171. */
  172. public int getUnderlay() {
  173. return underlay;
  174. }
  175.  
  176. /**
  177. * Sets this tile's underlay.
  178. * @param underlay the underlay to set.
  179. */
  180. public void setUnderlay(int underlay) {
  181. this.underlay = underlay;
  182. }
  183.  
  184. /**
  185. * Gets this tiles wall.
  186. * @return the wall.
  187. */
  188. public MapTileWall getWall() {
  189. return wall;
  190. }
  191.  
  192. /**
  193. * Sets this tile's wall.
  194. * @param wall the wall to set.
  195. */
  196. public void setWall(MapTileWall wall) {
  197. this.wall = wall;
  198. }
  199.  
  200. }
Add Comment
Please, Sign In to add comment