12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package me.hammerle.supersnuvi.entity.components;
- import me.hammerle.supersnuvi.entity.Entity;
- import me.hammerle.supersnuvi.tiles.Tile;
- 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 * Tile.SIZE_SCALE;
- this.vx = vx * Tile.SIZE_SCALE;
- this.vy = vy * Tile.SIZE_SCALE;
- }
-
- 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 boolean isInWater()
- {
- return inWater;
- }
- @Override
- public void setFrictionFactor(float f)
- {
- friction = f;
- }
- @Override
- public float getFrictionFactor()
- {
- return friction;
- }
- }
|