BottledSoulTile.java 1.9 KB

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