Kepresses are no longer repeated
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
288ab9e936
commit
66ffafef0f
BIN
sprites/erina_slide.gif
Normal file
BIN
sprites/erina_slide.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 782 B |
BIN
sprites/erina_slide1.gif
Normal file
BIN
sprites/erina_slide1.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 467 B |
@ -411,9 +411,11 @@ public class Panel extends JPanel implements Runnable,KeyListener {
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
KEYS.put(e.getKeyCode(),true);
|
||||
for (int i=0;i<RabiClone.OBJ.size();i++) {
|
||||
RabiClone.OBJ.get(i).KeyPressed(e.getKeyCode());
|
||||
if (!KEYS.getOrDefault(e.getKeyCode(),false)) {
|
||||
KEYS.put(e.getKeyCode(),true);
|
||||
for (int i=0;i<RabiClone.OBJ.size();i++) {
|
||||
RabiClone.OBJ.get(i).KeyPressed(e.getKeyCode());
|
||||
}
|
||||
}
|
||||
//System.out.println("Key List: "+KEYS);
|
||||
}
|
||||
|
||||
@ -24,6 +24,8 @@ public class Sprite{
|
||||
public static AnimatedSprite ERINA_JUMP_RISE = new AnimatedSprite(new File(new File("..","sprites"),"erina_jump_rise.gif"),32,32);
|
||||
public static AnimatedSprite ERINA_JUMP_FALL1 = new AnimatedSprite(new File(new File("..","sprites"),"erina_jump_fall1.gif"),32,32);
|
||||
public static AnimatedSprite ERINA_JUMP_FALL = new AnimatedSprite(new File(new File("..","sprites"),"erina_jump_fall.gif"),32,32);
|
||||
public static AnimatedSprite ERINA_SLIDE1 = new AnimatedSprite(new File(new File("..","sprites"),"erina_slide1.gif"),32,32);
|
||||
public static AnimatedSprite ERINA_SLIDE = new AnimatedSprite(new File(new File("..","sprites"),"erina_slide.gif"),32,32);
|
||||
|
||||
|
||||
|
||||
|
||||
@ -19,6 +19,8 @@ public class Player extends AnimatedObject{
|
||||
final boolean LEFT = false;
|
||||
final boolean RIGHT = true;
|
||||
final int jump_fall_AnimationWaitTime = 200;
|
||||
final int slide_AnimationWaitTime = 100;
|
||||
final int slide_duration = 700;
|
||||
|
||||
double y_acceleration = GRAVITY;
|
||||
double y_acceleration_limit = 100;
|
||||
@ -50,7 +52,8 @@ public class Player extends AnimatedObject{
|
||||
boolean facing_direction = RIGHT;
|
||||
|
||||
long spacebarPressed = System.currentTimeMillis();
|
||||
long jump_fall_StartAnimationTimer = -1;
|
||||
long jump_slide_fall_StartAnimationTimer = -1;
|
||||
long slide_time = -1;
|
||||
int jumpHoldTime = 150;
|
||||
|
||||
public Player(Panel panel) {
|
||||
@ -73,16 +76,17 @@ public class Player extends AnimatedObject{
|
||||
break;
|
||||
case FALLING:
|
||||
if(prvState!=State.FALLING){
|
||||
jump_fall_StartAnimationTimer = System.currentTimeMillis();
|
||||
jump_slide_fall_StartAnimationTimer = System.currentTimeMillis();
|
||||
setAnimatedSpr(Sprite.ERINA_JUMP_FALL1);
|
||||
}
|
||||
if(System.currentTimeMillis()-jump_fall_StartAnimationTimer>jump_fall_AnimationWaitTime){
|
||||
if(System.currentTimeMillis()-jump_slide_fall_StartAnimationTimer>jump_fall_AnimationWaitTime){
|
||||
setAnimatedSpr(Sprite.ERINA_JUMP_FALL);
|
||||
jump_fall_StartAnimationTimer=-1;
|
||||
jump_slide_fall_StartAnimationTimer=-1;
|
||||
}
|
||||
break;
|
||||
case IDLE:
|
||||
jump_fall_StartAnimationTimer=-1;
|
||||
horizontal_friction = NORMAL_FRICTION;
|
||||
jump_slide_fall_StartAnimationTimer=-1;
|
||||
|
||||
if(KeyHeld(KeyEvent.VK_A)||KeyHeld(KeyEvent.VK_LEFT)){
|
||||
setAnimatedSpr(Sprite.ERINA_WALK);
|
||||
@ -102,15 +106,26 @@ public class Player extends AnimatedObject{
|
||||
}
|
||||
break;
|
||||
case JUMP:
|
||||
if(jump_fall_StartAnimationTimer==-1){
|
||||
jump_fall_StartAnimationTimer = System.currentTimeMillis();
|
||||
if(jump_slide_fall_StartAnimationTimer==-1){
|
||||
jump_slide_fall_StartAnimationTimer = System.currentTimeMillis();
|
||||
setAnimatedSpr(Sprite.ERINA_JUMP_RISE1);
|
||||
}
|
||||
if(System.currentTimeMillis()-jump_fall_StartAnimationTimer>jump_fall_AnimationWaitTime){
|
||||
if(System.currentTimeMillis()-jump_slide_fall_StartAnimationTimer>jump_fall_AnimationWaitTime){
|
||||
setAnimatedSpr(Sprite.ERINA_JUMP_RISE);
|
||||
}
|
||||
break;
|
||||
case SLIDE:
|
||||
horizontal_friction=0;
|
||||
if(jump_slide_fall_StartAnimationTimer==-1){
|
||||
jump_slide_fall_StartAnimationTimer = System.currentTimeMillis();
|
||||
setAnimatedSpr(Sprite.ERINA_SLIDE1);
|
||||
}
|
||||
if(System.currentTimeMillis()-jump_slide_fall_StartAnimationTimer>slide_AnimationWaitTime){
|
||||
setAnimatedSpr(Sprite.ERINA_SLIDE);
|
||||
}
|
||||
if(System.currentTimeMillis()-slide_time>slide_duration){
|
||||
state=State.IDLE;
|
||||
}
|
||||
break;
|
||||
case STAGGER:
|
||||
break;
|
||||
@ -149,10 +164,14 @@ public class Player extends AnimatedObject{
|
||||
case ATTACK:
|
||||
break;
|
||||
case IDLE:
|
||||
if(key==KeyEvent.VK_CONTROL){
|
||||
slide_time = System.currentTimeMillis();
|
||||
state=State.SLIDE;
|
||||
}
|
||||
break;
|
||||
case FALLING:
|
||||
case JUMP:
|
||||
if (jumpCount>0 && spacebarReleased && (key == KeyEvent.VK_SPACE || key == KeyEvent.VK_W)){
|
||||
if(jumpCount>0 && spacebarReleased && (key == KeyEvent.VK_SPACE || key == KeyEvent.VK_W)){
|
||||
jumpCount=0;
|
||||
y_velocity = jump_velocity;
|
||||
spacebarReleased=false;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user