1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package me.hammerle.supersnuvi.entity.components;
- import me.hammerle.supersnuvi.entity.Entity;
- public class DefaultMovement extends Movement
- {
- private final float jumpPower;
- private boolean inWater = false;
- private final float vx;
- private final float vy;
-
- public DefaultMovement(Entity ent, float vx, float vy, float jumpPower)
- {
- super(ent);
- this.jumpPower = jumpPower;
- this.vx = vx;
- this.vy = vy;
- }
-
- private float getFactor()
- {
- return inWater ? 0.65f : 1.0f;
- }
- @Override
- public float getVelocityX()
- {
- return vx * getFactor();
- }
- @Override
- public float getVelocityY()
- {
- return vy * getFactor();
- }
- @Override
- public boolean jump()
- {
- if(ent.isOnGround())
- {
- ent.setMotionY(ent.getMotionY() - getJumpPower());
- return true;
- }
- return false;
- }
- @Override
- public float getJumpPower()
- {
- return jumpPower * getFactor();
- }
- @Override
- public boolean hasGravity()
- {
- return true;
- }
- @Override
- public void setInWater(boolean b)
- {
- inWater = b;
- }
- }
|