DefaultMovement.java 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. public DefaultMovement(Entity ent, float vx, float vy, float jumpPower)
  10. {
  11. super(ent);
  12. this.jumpPower = jumpPower;
  13. this.vx = vx;
  14. this.vy = vy;
  15. }
  16. private float getFactor()
  17. {
  18. return inWater ? 0.65f : 1.0f;
  19. }
  20. @Override
  21. public float getVelocityX()
  22. {
  23. return vx * getFactor();
  24. }
  25. @Override
  26. public float getVelocityY()
  27. {
  28. return vy * getFactor();
  29. }
  30. @Override
  31. public boolean jump()
  32. {
  33. if(ent.isOnGround())
  34. {
  35. ent.setMotionY(ent.getMotionY() - getJumpPower());
  36. return true;
  37. }
  38. return false;
  39. }
  40. @Override
  41. public float getJumpPower()
  42. {
  43. return jumpPower * getFactor();
  44. }
  45. @Override
  46. public boolean hasGravity()
  47. {
  48. return true;
  49. }
  50. @Override
  51. public void setInWater(boolean b)
  52. {
  53. inWater = b;
  54. }
  55. }