BottledSoulTile.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package me.hammerle.supersnuvi.tiles;
  2. import java.util.HashSet;
  3. import me.hammerle.supersnuvi.entity.Entity;
  4. import me.hammerle.supersnuvi.util.CollisionBox;
  5. import me.hammerle.supersnuvi.util.CollisionObject;
  6. import me.hammerle.supersnuvi.util.Face;
  7. import me.hammerle.supersnuvi.util.SoundUtils;
  8. public class BottledSoulTile extends BaseTile
  9. {
  10. private final HashSet<Long> states;
  11. private final int score;
  12. public BottledSoulTile(int score)
  13. {
  14. super(0.0625f * (score - 1), 0.0625f, 0.0625f * score, 0.125f);
  15. states = new HashSet<>();
  16. super.setCollisionBox(CollisionBox.createScaledTileBox(0.2f, 0.2f, 0.8f, 0.8f));
  17. this.score = score;
  18. }
  19. @Override
  20. public void onEntityCollide(Entity ent, int x, int y, Face face)
  21. {
  22. if(ent.getItemCollector().canCollect())
  23. {
  24. if(states.add(getKey(x, y)))
  25. {
  26. ent.getLevel().updateTile(x, y);
  27. if(ent.getItemCollector().isHero())
  28. {
  29. SoundUtils.playSound(SoundUtils.Sound.COLLECT);
  30. ent.getLevel().increaseSouls(score);
  31. }
  32. ent.getHealth().addHealthPercent(0.143f * score);
  33. }
  34. }
  35. }
  36. @Override
  37. public CollisionObject getCollisionBox(int x, int y)
  38. {
  39. if(states.contains(getKey(x, y)))
  40. {
  41. return CollisionObject.NULL_BOX;
  42. }
  43. return super.getCollisionBox(x, y);
  44. }
  45. @Override
  46. public boolean shouldAiUseCollisionBox(int x, int y)
  47. {
  48. return false;
  49. }
  50. @Override
  51. public boolean shouldRender(int x, int y)
  52. {
  53. return !states.contains(getKey(x, y));
  54. }
  55. @Override
  56. public void reset()
  57. {
  58. states.clear();
  59. }
  60. @Override
  61. public int getBottleScore()
  62. {
  63. return score;
  64. }
  65. }