Tile.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package me.hammerle.supersnuvi.tiles;
  2. import me.hammerle.supersnuvi.entity.Entity;
  3. import me.hammerle.supersnuvi.util.CollisionObject;
  4. import me.hammerle.supersnuvi.util.Face;
  5. import me.hammerle.supersnuvi.gamelogic.Level;
  6. public abstract class Tile
  7. {
  8. public final static int SIZE = 32;
  9. public final static float SIZE_SCALE = SIZE / 32.0f;
  10. private CollisionObject movementCollision;
  11. private CollisionObject collisionBox;
  12. public Tile()
  13. {
  14. movementCollision = null;
  15. collisionBox = null;
  16. }
  17. /** Sets the collision box for movement
  18. *
  19. * @param cb a collision box
  20. * @return the tile which the change was applied to
  21. */
  22. public Tile setMovementBox(CollisionObject cb)
  23. {
  24. if(cb == CollisionObject.NULL_BOX)
  25. {
  26. this.movementCollision = null;
  27. }
  28. else
  29. {
  30. this.movementCollision = cb.copy();
  31. }
  32. return this;
  33. }
  34. /** Sets the collision box for normal collision
  35. *
  36. * @param cb a collision box
  37. * @return the tile which the change was applied to
  38. */
  39. public Tile setCollisionBox(CollisionObject cb)
  40. {
  41. if(cb == CollisionObject.NULL_BOX)
  42. {
  43. this.collisionBox = null;
  44. }
  45. else
  46. {
  47. this.collisionBox = cb.copy();
  48. }
  49. return this;
  50. }
  51. /** Sets the default collision box for movement and for collision
  52. *
  53. * @return the tile which the change was applied to
  54. */
  55. public Tile setDefaultCollisionBox()
  56. {
  57. this.movementCollision = CollisionObject.DEFAULT_TILE_BOX.copy();
  58. this.collisionBox = CollisionObject.DEFAULT_TILE_BOX.copy();
  59. return this;
  60. }
  61. public CollisionObject getCollisionBox(int x, int y, Level l)
  62. {
  63. if(collisionBox != null)
  64. {
  65. return collisionBox;
  66. }
  67. return CollisionObject.NULL_BOX.reset();
  68. }
  69. public boolean shouldAiUseCollisionBox(int x, int y, Level l)
  70. {
  71. return true;
  72. }
  73. public CollisionObject getMovementBox(int x, int y, Level l)
  74. {
  75. if(movementCollision != null)
  76. {
  77. return movementCollision;
  78. }
  79. return CollisionObject.NULL_BOX.reset();
  80. }
  81. public void onEntityCollide(Entity ent, int x, int y, Face face, Level l)
  82. {
  83. }
  84. public void tick()
  85. {
  86. }
  87. public void reset(Level l)
  88. {
  89. }
  90. public void reset(int x, int y, Level l)
  91. {
  92. }
  93. public int getBottleScore()
  94. {
  95. return 0;
  96. }
  97. public float getTextureMinX(int x, int y, Level l)
  98. {
  99. return 0.0f;
  100. }
  101. public float getTextureMaxX(int x, int y, Level l)
  102. {
  103. return 0.0625f;
  104. }
  105. public float getTextureMinY(int x, int y, Level l)
  106. {
  107. return 0.0f;
  108. }
  109. public float getTextureMaxY(int x, int y, Level l)
  110. {
  111. return 0.0625f;
  112. }
  113. public float getOffsetX()
  114. {
  115. return 0.0f;
  116. }
  117. public float getOffsetY()
  118. {
  119. return 0.0f;
  120. }
  121. public float getWidth()
  122. {
  123. return Tile.SIZE;
  124. }
  125. public float getHeight()
  126. {
  127. return Tile.SIZE;
  128. }
  129. public boolean shouldRender(int x, int y, Level l)
  130. {
  131. return true;
  132. }
  133. }