Rabbit walks correctly now
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 805 B |
BIN
sprites/erina_jump_fall1.gif
Normal file
After Width: | Height: | Size: 477 B |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 800 B |
BIN
sprites/erina_jump_rise1.gif
Normal file
After Width: | Height: | Size: 473 B |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 1.3 KiB |
@ -19,6 +19,11 @@ public class Sprite{
|
|||||||
public static Sprite BACKGROUND3 = new Sprite(new File(new File("..","backgrounds"),"back3.gif"));
|
public static Sprite BACKGROUND3 = new Sprite(new File(new File("..","backgrounds"),"back3.gif"));
|
||||||
public static AnimatedSprite ERINOAH = new AnimatedSprite(new File(new File("..","sprites"),"erinoah.gif"),48,48);
|
public static AnimatedSprite ERINOAH = new AnimatedSprite(new File(new File("..","sprites"),"erinoah.gif"),48,48);
|
||||||
public static AnimatedSprite ERINA = new AnimatedSprite(new File(new File("..","sprites"),"erina.gif"),32,32);
|
public static AnimatedSprite ERINA = new AnimatedSprite(new File(new File("..","sprites"),"erina.gif"),32,32);
|
||||||
|
public static AnimatedSprite ERINA_WALK = new AnimatedSprite(new File(new File("..","sprites"),"erina_walk.gif"),32,32);
|
||||||
|
public static AnimatedSprite ERINA_JUMP_RISE1 = new AnimatedSprite(new File(new File("..","sprites"),"erina_jump_rise1.gif"),32,32);
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,15 +62,35 @@ public class Player extends AnimatedObject{
|
|||||||
super.update(updateMult);
|
super.update(updateMult);
|
||||||
handleMovementPhysics(updateMult);
|
handleMovementPhysics(updateMult);
|
||||||
handleCameraRoomMovement();
|
handleCameraRoomMovement();
|
||||||
|
int right = (KeyHeld(KeyEvent.VK_RIGHT))||(KeyHeld(KeyEvent.VK_D))?1:0;
|
||||||
|
int left = (KeyHeld(KeyEvent.VK_LEFT))||(KeyHeld(KeyEvent.VK_A))?1:0;
|
||||||
|
|
||||||
switch(state){
|
switch(state){
|
||||||
case ATTACK:
|
case ATTACK:
|
||||||
break;
|
break;
|
||||||
case FALLING:
|
case FALLING:
|
||||||
|
setAnimatedSpr(Sprite.ERINA_JUMP_FALL);
|
||||||
break;
|
break;
|
||||||
case IDLE:
|
case IDLE:
|
||||||
|
if(KeyHeld(KeyEvent.VK_A)||KeyHeld(KeyEvent.VK_LEFT)){
|
||||||
|
setAnimatedSpr(Sprite.ERINA_WALK);
|
||||||
|
}
|
||||||
|
if(KeyHeld(KeyEvent.VK_D)||KeyHeld(KeyEvent.VK_RIGHT)){
|
||||||
|
setAnimatedSpr(Sprite.ERINA_WALK);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(right-left==0){
|
||||||
|
setAnimatedSpr(Sprite.ERINA);
|
||||||
|
}
|
||||||
|
if(x_velocity!=0){
|
||||||
|
setAnimatedSpr(Sprite.ERINA_WALK);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
setAnimatedSpr(Sprite.ERINA);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case JUMP:
|
case JUMP:
|
||||||
|
setAnimatedSpr(Sprite.ERINA_JUMP_RISE);
|
||||||
break;
|
break;
|
||||||
case SLIDE:
|
case SLIDE:
|
||||||
break;
|
break;
|
||||||
@ -82,18 +102,25 @@ public class Player extends AnimatedObject{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (KeyHeld(KeyEvent.VK_SPACE)&&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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void KeyReleased(int key) {
|
protected void KeyReleased(int key) {
|
||||||
if (key==KeyEvent.VK_SPACE) {
|
if (key==KeyEvent.VK_SPACE||key==KeyEvent.VK_W) {
|
||||||
spacebarPressed=0;
|
spacebarPressed=0;
|
||||||
spacebarReleased=true;
|
spacebarReleased=true;
|
||||||
}
|
}
|
||||||
|
if((key==KeyEvent.VK_A||key==KeyEvent.VK_LEFT)&&(KeyHeld(KeyEvent.VK_D)||KeyHeld(KeyEvent.VK_RIGHT))){
|
||||||
|
facing_direction=RIGHT;
|
||||||
|
}
|
||||||
|
if((key==KeyEvent.VK_D||key==KeyEvent.VK_RIGHT)&&(KeyHeld(KeyEvent.VK_A)||KeyHeld(KeyEvent.VK_LEFT))){
|
||||||
|
facing_direction=LEFT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -106,7 +133,7 @@ public class Player extends AnimatedObject{
|
|||||||
break;
|
break;
|
||||||
case FALLING:
|
case FALLING:
|
||||||
case JUMP:
|
case JUMP:
|
||||||
if (jumpCount>0 && spacebarReleased && key == KeyEvent.VK_SPACE){
|
if (jumpCount>0 && spacebarReleased && (key == KeyEvent.VK_SPACE || key == KeyEvent.VK_W)){
|
||||||
jumpCount=0;
|
jumpCount=0;
|
||||||
y_velocity = jump_velocity;
|
y_velocity = jump_velocity;
|
||||||
spacebarReleased=false;
|
spacebarReleased=false;
|
||||||
@ -123,7 +150,7 @@ public class Player extends AnimatedObject{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (groundCollision) {
|
if (groundCollision) {
|
||||||
if (spacebarReleased&&key==KeyEvent.VK_SPACE&&jumpCount>0) {
|
if (spacebarReleased&&(key==KeyEvent.VK_SPACE||key==KeyEvent.VK_W)&&jumpCount>0) {
|
||||||
state = State.JUMP;
|
state = State.JUMP;
|
||||||
jumpCount--;
|
jumpCount--;
|
||||||
y_velocity = jump_velocity;
|
y_velocity = jump_velocity;
|
||||||
@ -229,8 +256,8 @@ public class Player extends AnimatedObject{
|
|||||||
|
|
||||||
|
|
||||||
private void handleMovementPhysics(double updateMult) {
|
private void handleMovementPhysics(double updateMult) {
|
||||||
int right = KeyHeld(KeyEvent.VK_RIGHT)?1:0;
|
int right = (KeyHeld(KeyEvent.VK_RIGHT))||(KeyHeld(KeyEvent.VK_D))?1:0;
|
||||||
int left = KeyHeld(KeyEvent.VK_LEFT)?1:0;
|
int left = (KeyHeld(KeyEvent.VK_LEFT))||(KeyHeld(KeyEvent.VK_A))?1:0;
|
||||||
|
|
||||||
x_velocity =
|
x_velocity =
|
||||||
Math.abs(x_velocity+x_acceleration*updateMult)>x_velocity_limit
|
Math.abs(x_velocity+x_acceleration*updateMult)>x_velocity_limit
|
||||||
|