jump fall timers

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
unknown 3 years ago
parent efe985361f
commit 288ab9e936
  1. 25
      src/sig/objects/Player.java

@ -18,6 +18,7 @@ public class Player extends AnimatedObject{
final double NORMAL_FRICTION = 6400; final double NORMAL_FRICTION = 6400;
final boolean LEFT = false; final boolean LEFT = false;
final boolean RIGHT = true; final boolean RIGHT = true;
final int jump_fall_AnimationWaitTime = 200;
double y_acceleration = GRAVITY; double y_acceleration = GRAVITY;
double y_acceleration_limit = 100; double y_acceleration_limit = 100;
@ -38,6 +39,7 @@ public class Player extends AnimatedObject{
int maxJumpCount=2; int maxJumpCount=2;
int jumpCount=maxJumpCount; int jumpCount=maxJumpCount;
State state = State.IDLE; State state = State.IDLE;
State prvState = state;
final double viewBoundaryX=RabiClone.BASE_WIDTH/3; final double viewBoundaryX=RabiClone.BASE_WIDTH/3;
final double viewBoundaryY=RabiClone.BASE_HEIGHT/3; final double viewBoundaryY=RabiClone.BASE_HEIGHT/3;
@ -48,6 +50,7 @@ public class Player extends AnimatedObject{
boolean facing_direction = RIGHT; boolean facing_direction = RIGHT;
long spacebarPressed = System.currentTimeMillis(); long spacebarPressed = System.currentTimeMillis();
long jump_fall_StartAnimationTimer = -1;
int jumpHoldTime = 150; int jumpHoldTime = 150;
public Player(Panel panel) { public Player(Panel panel) {
@ -69,9 +72,18 @@ public class Player extends AnimatedObject{
case ATTACK: case ATTACK:
break; break;
case FALLING: case FALLING:
setAnimatedSpr(Sprite.ERINA_JUMP_FALL); if(prvState!=State.FALLING){
jump_fall_StartAnimationTimer = System.currentTimeMillis();
setAnimatedSpr(Sprite.ERINA_JUMP_FALL1);
}
if(System.currentTimeMillis()-jump_fall_StartAnimationTimer>jump_fall_AnimationWaitTime){
setAnimatedSpr(Sprite.ERINA_JUMP_FALL);
jump_fall_StartAnimationTimer=-1;
}
break; break;
case IDLE: case IDLE:
jump_fall_StartAnimationTimer=-1;
if(KeyHeld(KeyEvent.VK_A)||KeyHeld(KeyEvent.VK_LEFT)){ if(KeyHeld(KeyEvent.VK_A)||KeyHeld(KeyEvent.VK_LEFT)){
setAnimatedSpr(Sprite.ERINA_WALK); setAnimatedSpr(Sprite.ERINA_WALK);
} }
@ -90,7 +102,13 @@ public class Player extends AnimatedObject{
} }
break; break;
case JUMP: case JUMP:
setAnimatedSpr(Sprite.ERINA_JUMP_RISE); if(jump_fall_StartAnimationTimer==-1){
jump_fall_StartAnimationTimer = System.currentTimeMillis();
setAnimatedSpr(Sprite.ERINA_JUMP_RISE1);
}
if(System.currentTimeMillis()-jump_fall_StartAnimationTimer>jump_fall_AnimationWaitTime){
setAnimatedSpr(Sprite.ERINA_JUMP_RISE);
}
break; break;
case SLIDE: case SLIDE:
break; break;
@ -101,8 +119,9 @@ public class Player extends AnimatedObject{
default: default:
break; break;
} }
prvState = state;
if (KeyHeld(KeyEvent.VK_SPACE)||KeyHeld(KeyEvent.VK_W)&&System.currentTimeMillis()-spacebarPressed<jumpHoldTime) { if ((KeyHeld(KeyEvent.VK_SPACE)||KeyHeld(KeyEvent.VK_W))&&System.currentTimeMillis()-spacebarPressed<jumpHoldTime) {
y_velocity=jump_velocity; y_velocity=jump_velocity;
} }

Loading…
Cancel
Save