ColorRunner/core/src/de/samdev/colorrunner/game/world/entities/GravityEntity.java

46 lines
1.1 KiB
Java

package de.samdev.colorrunner.game.world.entities;
import de.samdev.colorrunner.game.world.CRGameWorld;
import de.samdev.colorrunner.game.world.entities.gameentities.ControllingType;
public abstract class GravityEntity extends MovingEntity {
public float GRAVITY_FORCE = 700f;
public final static float TERMINAL_VELOCITY = 900f;
public ControllingType ctrlType = ControllingType.RUNBOTTOM;
public GravityEntity(CRGameWorld _owner, float width, float height) {
this(_owner, 0, 0, width, height);
}
public GravityEntity(CRGameWorld _owner, float x, float y, float width, float height) {
super(_owner, x, y, width, height);
}
@Override
public void update(float delta) {
switch (ctrlType){
case RUNTOP:
GRAVITY_FORCE = -700;
break;
case RUNBOTTOM:
GRAVITY_FORCE = 700;
break;
case FLY:
GRAVITY_FORCE = 400;
break;
}
velocity.y -= GRAVITY_FORCE * delta;
if (velocity.y < -TERMINAL_VELOCITY) {
velocity.y = -TERMINAL_VELOCITY;
}
super.update(delta);
if (isTouching_BOTTOM() && velocity.y < 0)
velocity.y = 0;
}
}