WaterTile.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package me.hammerle.supersnuvi.tiles;
  2. import me.hammerle.snuviengine.api.Texture.Animation;
  3. import me.hammerle.supersnuvi.entity.Entity;
  4. import me.hammerle.supersnuvi.gamelogic.Level;
  5. import me.hammerle.supersnuvi.util.CollisionBox;
  6. import me.hammerle.supersnuvi.util.CollisionObject;
  7. import me.hammerle.supersnuvi.util.Face;
  8. public class WaterTile extends BaseTile
  9. {
  10. private final static Animation WATER = Level.TILES.addAnimation(160, 0,
  11. "resources/water/water_frame1.png", "resources/water/water_frame2.png",
  12. "resources/water/water_frame3.png", "resources/water/water_frame4.png",
  13. "resources/water/water_frame5.png", "resources/water/water_frame6.png",
  14. "resources/water/water_frame7.png", "resources/water/water_frame8.png");
  15. private int counter = 0;
  16. private final int level;
  17. public WaterTile(int level)
  18. {
  19. super(0.3125f, 0.0f, 0.375f, 0.00390625f * (level + 1));
  20. this.level = level;
  21. super.setCollisionBox(CollisionBox.createScaledTileBox(0.1f, (getOffsetY() / Tile.SIZE) + 0.1f, 0.9f, 1.0f));
  22. super.setMovementBox(CollisionObject.NULL_BOX);
  23. }
  24. @Override
  25. public void onEntityCollide(Entity ent, int x, int y, Face face)
  26. {
  27. super.onEntityCollide(ent, x, y, face);
  28. ent.getMovement().setInWater(true);
  29. float motionY = ent.getMotionY();
  30. if(motionY < 0)
  31. {
  32. motionY *= 0.92d;
  33. if(Math.abs(motionY) < 0.1)
  34. {
  35. motionY = 0;
  36. }
  37. ent.setMotionY(motionY);
  38. }
  39. }
  40. @Override
  41. public boolean shouldAiUseCollisionBox(int x, int y)
  42. {
  43. return false;
  44. }
  45. @Override
  46. public void tick()
  47. {
  48. if(level == 15)
  49. {
  50. counter++;
  51. if(counter > 3)
  52. {
  53. counter = 0;
  54. WATER.nextFrame();
  55. }
  56. }
  57. }
  58. @Override
  59. public final float getOffsetY()
  60. {
  61. return Tile.SIZE - (Tile.SIZE / 16) * (level + 1);
  62. }
  63. @Override
  64. public final float getHeight()
  65. {
  66. return (Tile.SIZE / 16) * (level + 1);
  67. }
  68. }