Advertisement
Guest User

player class

a guest
Aug 1st, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. package nl.appic.stickyjumper;
  2.  
  3. import com.badlogic.gdx.Input.Keys;
  4.  
  5. public class Player extends DynamicGameObject {
  6. public static final float PLAYER_WIDTH = 2f;
  7. public static final float PLAYER_HEIGHT = 5f;
  8. public static final float JUMP_VELOCITY = 10;
  9. public static float MOVE_VELOCITY = 0;
  10. public static float accelX = 5;
  11.  
  12. public enum PlayerState {
  13. JUMP, FALL, CHILL
  14. }
  15.  
  16. private PlayerState state;
  17. private int stateTime;
  18. private boolean slowDown;
  19.  
  20. public Player(float x, float y) {
  21. super(x, y, PLAYER_WIDTH, PLAYER_HEIGHT);
  22. state = PlayerState.CHILL;
  23. stateTime = 0;
  24. }
  25.  
  26. public void update(float delta) {
  27. checkFloor(delta);
  28. decreaseMovingSpeed(delta);
  29. checkSideTeleport();
  30.  
  31. position.add(velocity.x * delta, velocity.y * delta);
  32. stateTime += delta;
  33. }
  34.  
  35. private void decreaseMovingSpeed(float delta) {
  36. if(slowDown){
  37. if(velocity.x == 0 && velocity.x < 1 || velocity.x < -1){
  38. velocity.x += MOVE_VELOCITY * delta;
  39. System.out.println(velocity.x);
  40. }else{
  41. velocity.x = 0;
  42. slowDown = false;
  43. }
  44. }else{
  45. // velocity.x = MOVE_VELOCITY;
  46. }
  47. }
  48.  
  49. private void checkFloor(float delta) {
  50. if (position.y > 0) {
  51. velocity.add(World.GRAVITY.x * delta, World.GRAVITY.y * delta);
  52. } else {
  53. position.y = 0; // doesn't fall through ground
  54. }
  55. }
  56.  
  57. @Override
  58. public boolean keyDown(int keycode) {
  59. switch (keycode) {
  60. case Keys.A:
  61. MOVE_VELOCITY = -accelX;
  62. break;
  63. case Keys.D:
  64. MOVE_VELOCITY = accelX;
  65. break;
  66. case Keys.W:
  67. velocity.y = JUMP_VELOCITY;
  68. break;
  69. }
  70. System.out.println(accelX);
  71. return super.keyDown(keycode);
  72. }
  73.  
  74. @Override
  75. public boolean keyUp(int keycode) {
  76. slowDown = true;
  77. return super.keyUp(keycode);
  78. }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement