DefaultMovement.java 1.4 KB

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