Basic sliding bug fixes
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
66ffafef0f
commit
7b89ed7dcc
BIN
maps/world1.map
BIN
maps/world1.map
Binary file not shown.
@ -16,6 +16,7 @@ import java.awt.event.KeyEvent;
|
|||||||
public class Player extends AnimatedObject{
|
public class Player extends AnimatedObject{
|
||||||
final double GRAVITY = 1300;
|
final double GRAVITY = 1300;
|
||||||
final double NORMAL_FRICTION = 6400;
|
final double NORMAL_FRICTION = 6400;
|
||||||
|
final double NORMAL_JUMP_VELOCITY = -300;
|
||||||
final boolean LEFT = false;
|
final boolean LEFT = false;
|
||||||
final boolean RIGHT = true;
|
final boolean RIGHT = true;
|
||||||
final int jump_fall_AnimationWaitTime = 200;
|
final int jump_fall_AnimationWaitTime = 200;
|
||||||
@ -29,14 +30,15 @@ public class Player extends AnimatedObject{
|
|||||||
double x_velocity = 0;
|
double x_velocity = 0;
|
||||||
double x_velocity_limit = 164;
|
double x_velocity_limit = 164;
|
||||||
double y_velocity = 5;
|
double y_velocity = 5;
|
||||||
double y_velocity_limit = 400;
|
double y_velocity_limit = 500;
|
||||||
|
double sliding_velocity = 164;
|
||||||
|
|
||||||
double horizontal_drag = 2000;
|
double horizontal_drag = 2000;
|
||||||
double horizontal_friction = NORMAL_FRICTION;
|
double horizontal_friction = NORMAL_FRICTION;
|
||||||
double horizontal_air_drag = 800;
|
double horizontal_air_drag = 800;
|
||||||
double horizontal_air_friction = 180;
|
double horizontal_air_friction = 180;
|
||||||
|
|
||||||
double jump_velocity = -300;
|
double jump_velocity = NORMAL_JUMP_VELOCITY;
|
||||||
|
|
||||||
int maxJumpCount=2;
|
int maxJumpCount=2;
|
||||||
int jumpCount=maxJumpCount;
|
int jumpCount=maxJumpCount;
|
||||||
@ -85,6 +87,7 @@ public class Player extends AnimatedObject{
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IDLE:
|
case IDLE:
|
||||||
|
jump_velocity = NORMAL_JUMP_VELOCITY;
|
||||||
horizontal_friction = NORMAL_FRICTION;
|
horizontal_friction = NORMAL_FRICTION;
|
||||||
jump_slide_fall_StartAnimationTimer=-1;
|
jump_slide_fall_StartAnimationTimer=-1;
|
||||||
|
|
||||||
@ -106,6 +109,9 @@ public class Player extends AnimatedObject{
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case JUMP:
|
case JUMP:
|
||||||
|
if(prvState==State.SLIDE){
|
||||||
|
//jump_velocity=-500;
|
||||||
|
}
|
||||||
if(jump_slide_fall_StartAnimationTimer==-1){
|
if(jump_slide_fall_StartAnimationTimer==-1){
|
||||||
jump_slide_fall_StartAnimationTimer = System.currentTimeMillis();
|
jump_slide_fall_StartAnimationTimer = System.currentTimeMillis();
|
||||||
setAnimatedSpr(Sprite.ERINA_JUMP_RISE1);
|
setAnimatedSpr(Sprite.ERINA_JUMP_RISE1);
|
||||||
@ -124,6 +130,12 @@ public class Player extends AnimatedObject{
|
|||||||
setAnimatedSpr(Sprite.ERINA_SLIDE);
|
setAnimatedSpr(Sprite.ERINA_SLIDE);
|
||||||
}
|
}
|
||||||
if(System.currentTimeMillis()-slide_time>slide_duration){
|
if(System.currentTimeMillis()-slide_time>slide_duration){
|
||||||
|
if(KeyHeld(KeyEvent.VK_A)||KeyHeld(KeyEvent.VK_LEFT)){
|
||||||
|
facing_direction=LEFT;
|
||||||
|
}
|
||||||
|
if(KeyHeld(KeyEvent.VK_D)||KeyHeld(KeyEvent.VK_RIGHT)){
|
||||||
|
facing_direction=RIGHT;
|
||||||
|
}
|
||||||
state=State.IDLE;
|
state=State.IDLE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -139,7 +151,7 @@ public class Player extends AnimatedObject{
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
//System.out.println(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -149,6 +161,7 @@ public class Player extends AnimatedObject{
|
|||||||
spacebarPressed=0;
|
spacebarPressed=0;
|
||||||
spacebarReleased=true;
|
spacebarReleased=true;
|
||||||
}
|
}
|
||||||
|
if(state!=State.SLIDE){
|
||||||
if((key==KeyEvent.VK_A||key==KeyEvent.VK_LEFT)&&(KeyHeld(KeyEvent.VK_D)||KeyHeld(KeyEvent.VK_RIGHT))){
|
if((key==KeyEvent.VK_A||key==KeyEvent.VK_LEFT)&&(KeyHeld(KeyEvent.VK_D)||KeyHeld(KeyEvent.VK_RIGHT))){
|
||||||
facing_direction=RIGHT;
|
facing_direction=RIGHT;
|
||||||
}
|
}
|
||||||
@ -156,6 +169,7 @@ public class Player extends AnimatedObject{
|
|||||||
facing_direction=LEFT;
|
facing_direction=LEFT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void KeyPressed(int key) {
|
protected void KeyPressed(int key) {
|
||||||
@ -166,6 +180,12 @@ public class Player extends AnimatedObject{
|
|||||||
case IDLE:
|
case IDLE:
|
||||||
if(key==KeyEvent.VK_CONTROL){
|
if(key==KeyEvent.VK_CONTROL){
|
||||||
slide_time = System.currentTimeMillis();
|
slide_time = System.currentTimeMillis();
|
||||||
|
if(facing_direction){
|
||||||
|
x_velocity=sliding_velocity;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
x_velocity=-sliding_velocity;
|
||||||
|
}
|
||||||
state=State.SLIDE;
|
state=State.SLIDE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -197,6 +217,7 @@ public class Player extends AnimatedObject{
|
|||||||
//System.out.println("Jump");
|
//System.out.println("Jump");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(state!=State.SLIDE){
|
||||||
switch(key){
|
switch(key){
|
||||||
case KeyEvent.VK_LEFT: case KeyEvent.VK_A:
|
case KeyEvent.VK_LEFT: case KeyEvent.VK_A:
|
||||||
facing_direction=LEFT;
|
facing_direction=LEFT;
|
||||||
@ -206,6 +227,7 @@ public class Player extends AnimatedObject{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void handleCameraRoomMovement() {
|
private void handleCameraRoomMovement() {
|
||||||
@ -296,7 +318,10 @@ public class Player extends AnimatedObject{
|
|||||||
private void handleMovementPhysics(double updateMult) {
|
private void handleMovementPhysics(double updateMult) {
|
||||||
int right = (KeyHeld(KeyEvent.VK_RIGHT))||(KeyHeld(KeyEvent.VK_D))?1:0;
|
int right = (KeyHeld(KeyEvent.VK_RIGHT))||(KeyHeld(KeyEvent.VK_D))?1:0;
|
||||||
int left = (KeyHeld(KeyEvent.VK_LEFT))||(KeyHeld(KeyEvent.VK_A))?1:0;
|
int left = (KeyHeld(KeyEvent.VK_LEFT))||(KeyHeld(KeyEvent.VK_A))?1:0;
|
||||||
|
if(state==State.SLIDE){
|
||||||
|
right=0;
|
||||||
|
left=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
|
||||||
?Math.signum(x_velocity+x_acceleration*updateMult)*x_velocity_limit
|
?Math.signum(x_velocity+x_acceleration*updateMult)*x_velocity_limit
|
||||||
|
Loading…
x
Reference in New Issue
Block a user