DefaultMovement.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package me.hammerle.supersnuvi.entity.components;
  2. import me.hammerle.supersnuvi.entity.Entity;
  3. import me.hammerle.supersnuvi.tiles.Tile;
  4. public class DefaultMovement extends Movement
  5. {
  6. private final float jumpPower;
  7. private boolean inWater = false;
  8. private final float vx;
  9. private final float vy;
  10. private float friction = 1.0f;
  11. public DefaultMovement(Entity ent, float vx, float vy, float jumpPower)
  12. {
  13. super(ent);
  14. this.jumpPower = jumpPower * Tile.SIZE_SCALE;
  15. this.vx = vx * Tile.SIZE_SCALE;
  16. this.vy = vy * Tile.SIZE_SCALE;
  17. }
  18. private float getFactor()
  19. {
  20. return inWater ? 0.65f : 1.0f;
  21. }
  22. @Override
  23. public float getGravityFactor()
  24. {
  25. return inWater ? 0.5f : 1.0f;
  26. }
  27. @Override
  28. public float getVelocityX()
  29. {
  30. return vx * getFactor();
  31. }
  32. @Override
  33. public float getVelocityY()
  34. {
  35. return vy * getFactor();
  36. }
  37. @Override
  38. public boolean jump()
  39. {
  40. if(ent.isOnGround())
  41. {
  42. ent.setMotionY((ent.getMotionY() < 0.0f ? ent.getMotionY() : 0.0f) - getJumpPower());
  43. return true;
  44. }
  45. return false;
  46. }
  47. @Override
  48. public float getJumpPower()
  49. {
  50. return jumpPower * getFactor();
  51. }
  52. @Override
  53. public boolean hasGravity()
  54. {
  55. return true;
  56. }
  57. @Override
  58. public void setInWater(boolean b)
  59. {
  60. inWater = b;
  61. }
  62. @Override
  63. public boolean isInWater()
  64. {
  65. return inWater;
  66. }
  67. @Override
  68. public void setFrictionFactor(float f)
  69. {
  70. friction = f;
  71. }
  72. @Override
  73. public float getFrictionFactor()
  74. {
  75. return friction;
  76. }
  77. }