BottledSoulTile.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package me.hammerle.supersnuvi.tiles;
  2. import me.hammerle.supersnuvi.entity.Entity;
  3. import me.hammerle.supersnuvi.util.BlockDataStorage;
  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. import me.hammerle.supersnuvi.gamelogic.Level;
  9. public class BottledSoulTile extends BaseCollisionTile
  10. {
  11. private final BlockDataStorage states = new BlockDataStorage();
  12. private final int score;
  13. public BottledSoulTile(int score)
  14. {
  15. super(0.0625f * (score - 1), 0.0625f, 0.0625f * score, 0.125f,
  16. Tile.SIZE * 0.2f, Tile.SIZE * 0.2f, Tile.SIZE * 0.8f, Tile.SIZE * 0.8f);
  17. super.setCollisionBox(CollisionBox.createScaledTileBox(0.2f, 0.2f, 0.8f, 0.8f));
  18. this.score = score;
  19. }
  20. @Override
  21. public void onEntityCollide(Entity ent, int x, int y, Face face, Level l)
  22. {
  23. if(ent.getItemCollector().canCollect())
  24. {
  25. if(states.add(x, y, l))
  26. {
  27. l.getTileUpdater().add(l.getData().getBackgroundIndex(), x, y);
  28. if(ent.getItemCollector().isHero())
  29. {
  30. SoundUtils.playSound(SoundUtils.Sound.COLLECT);
  31. l.addBottles(score);
  32. }
  33. ent.getHealth().addHealthPercent(0.143f * score);
  34. }
  35. }
  36. }
  37. @Override
  38. public CollisionObject getCollisionBox(int x, int y, Level l)
  39. {
  40. if(states.contains(x, y, l))
  41. {
  42. return CollisionObject.NULL_BOX;
  43. }
  44. return super.getCollisionBox(x, y, l);
  45. }
  46. @Override
  47. public boolean shouldAiUseCollisionBox(int x, int y, Level l)
  48. {
  49. return false;
  50. }
  51. @Override
  52. public boolean shouldRender(int x, int y, Level l)
  53. {
  54. return !states.contains(x, y, l);
  55. }
  56. @Override
  57. public void reset(Level l)
  58. {
  59. states.clear(l);
  60. }
  61. @Override
  62. public void reset(int x, int y, Level l)
  63. {
  64. states.clear(x, y, l);
  65. }
  66. @Override
  67. public int getBottleScore()
  68. {
  69. return score;
  70. }
  71. }