Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nl.appic.stickyjumper;
- import com.badlogic.gdx.Input.Keys;
- public class Player extends DynamicGameObject {
- public static final float PLAYER_WIDTH = 2f;
- public static final float PLAYER_HEIGHT = 5f;
- public static final float JUMP_VELOCITY = 10;
- public static float MOVE_VELOCITY = 0;
- public static float accelX = 5;
- public enum PlayerState {
- JUMP, FALL, CHILL
- }
- private PlayerState state;
- private int stateTime;
- private boolean slowDown;
- public Player(float x, float y) {
- super(x, y, PLAYER_WIDTH, PLAYER_HEIGHT);
- state = PlayerState.CHILL;
- stateTime = 0;
- }
- public void update(float delta) {
- checkFloor(delta);
- decreaseMovingSpeed(delta);
- checkSideTeleport();
- position.add(velocity.x * delta, velocity.y * delta);
- stateTime += delta;
- }
- private void decreaseMovingSpeed(float delta) {
- if(slowDown){
- if(velocity.x == 0 && velocity.x < 1 || velocity.x < -1){
- velocity.x += MOVE_VELOCITY * delta;
- System.out.println(velocity.x);
- }else{
- velocity.x = 0;
- slowDown = false;
- }
- }else{
- // velocity.x = MOVE_VELOCITY;
- }
- }
- private void checkFloor(float delta) {
- if (position.y > 0) {
- velocity.add(World.GRAVITY.x * delta, World.GRAVITY.y * delta);
- } else {
- position.y = 0; // doesn't fall through ground
- }
- }
- @Override
- public boolean keyDown(int keycode) {
- switch (keycode) {
- case Keys.A:
- MOVE_VELOCITY = -accelX;
- break;
- case Keys.D:
- MOVE_VELOCITY = accelX;
- break;
- case Keys.W:
- velocity.y = JUMP_VELOCITY;
- break;
- }
- System.out.println(accelX);
- return super.keyDown(keycode);
- }
- @Override
- public boolean keyUp(int keycode) {
- slowDown = true;
- return super.keyUp(keycode);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement