CrumblingStoneTile.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package me.hammerle.supersnuvi.tiles;
  2. import java.util.HashSet;
  3. import me.hammerle.supersnuvi.entity.Entity;
  4. import me.hammerle.supersnuvi.entity.EntityBuilder;
  5. import me.hammerle.supersnuvi.gamelogic.Level;
  6. import me.hammerle.supersnuvi.util.CollisionBox;
  7. import me.hammerle.supersnuvi.util.Face;
  8. import me.hammerle.supersnuvi.util.SoundUtils;
  9. import me.hammerle.supersnuvi.util.Utils;
  10. public class CrumblingStoneTile extends BaseTile
  11. {
  12. private final HashSet<Long> states;
  13. public CrumblingStoneTile()
  14. {
  15. super(0.1875f, 0.125f, 0.25f, 0.1875f);
  16. states = new HashSet<>();
  17. super.setCollisionBox(CollisionBox.createScaledTileBox(0.0f, 0.0f, 1.0f, 0.6f));
  18. super.setMovementBox(CollisionBox.createScaledTileBox(0.0f, 0.0f, 1.0f, 0.6f));
  19. }
  20. @Override
  21. public CollisionBox getCollisionBox(int x, int y)
  22. {
  23. if(states.contains(getKey(x, y)))
  24. {
  25. return CollisionBox.NULL_BOX;
  26. }
  27. return super.getCollisionBox(x, y);
  28. }
  29. @Override
  30. public CollisionBox getMovementBox(int x, int y)
  31. {
  32. if(states.contains(getKey(x, y)))
  33. {
  34. return CollisionBox.NULL_BOX;
  35. }
  36. return super.getMovementBox(x, y);
  37. }
  38. @Override
  39. public void onEntityCollide(Entity ent, int x, int y, Face face)
  40. {
  41. super.onEntityCollide(ent, x, y, face);
  42. if(face == Face.UP)
  43. {
  44. if(states.add(getKey(x, y)))
  45. {
  46. ent.getLevel().updateTile(x, y);
  47. Level l = ent.getLevel();
  48. l.spawnEntity(EntityBuilder.buildCrumblingStone(l, Utils.toCoord(x), Utils.toCoord(y)));
  49. SoundUtils.playSound(SoundUtils.Sound.STONE_CRUMBLING);
  50. }
  51. }
  52. }
  53. @Override
  54. public boolean shouldRender(int x, int y)
  55. {
  56. return !states.contains(getKey(x, y));
  57. }
  58. @Override
  59. public void reset()
  60. {
  61. states.clear();
  62. }
  63. }