123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- 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;
- private float friction = 1.0f;
-
- 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 getGravityFactor()
- {
- return inWater ? 0.5f : 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() < 0.0f ? ent.getMotionY() : 0.0f) - 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;
- }
- @Override
- public void setFrictionFactor(float f)
- {
- friction = f;
- }
- @Override
- public float getFrictionFactor()
- {
- return friction;
- }
- }
|