|
|
@ -1,6 +1,7 @@ |
|
|
|
package sig.objects; |
|
|
|
package sig.objects; |
|
|
|
|
|
|
|
|
|
|
|
import sig.RabiClone; |
|
|
|
import sig.RabiClone; |
|
|
|
|
|
|
|
import sig.engine.Action; |
|
|
|
import sig.engine.AnimatedObject; |
|
|
|
import sig.engine.AnimatedObject; |
|
|
|
import sig.engine.Panel; |
|
|
|
import sig.engine.Panel; |
|
|
|
import sig.engine.Sprite; |
|
|
|
import sig.engine.Sprite; |
|
|
@ -10,8 +11,6 @@ import sig.map.Tile; |
|
|
|
import sig.map.View; |
|
|
|
import sig.map.View; |
|
|
|
import sig.objects.actor.State; |
|
|
|
import sig.objects.actor.State; |
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
@ -69,74 +68,62 @@ 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: |
|
|
|
if(prvState!=State.FALLING){ |
|
|
|
if(prvState!=State.FALLING){ |
|
|
|
jump_slide_fall_StartAnimationTimer = System.currentTimeMillis(); |
|
|
|
jump_slide_fall_StartAnimationTimer = System.currentTimeMillis(); |
|
|
|
setAnimatedSpr(Sprite.ERINA_JUMP_FALL1); |
|
|
|
setAnimatedSpr(Sprite.ERINA_JUMP_FALL1); |
|
|
|
} |
|
|
|
} |
|
|
|
if(System.currentTimeMillis()-jump_slide_fall_StartAnimationTimer>jump_fall_AnimationWaitTime){ |
|
|
|
if(System.currentTimeMillis()-jump_slide_fall_StartAnimationTimer>jump_fall_AnimationWaitTime){ |
|
|
|
setAnimatedSpr(Sprite.ERINA_JUMP_FALL); |
|
|
|
setAnimatedSpr(Sprite.ERINA_JUMP_FALL); |
|
|
|
jump_slide_fall_StartAnimationTimer=-1; |
|
|
|
jump_slide_fall_StartAnimationTimer=-1; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case IDLE: |
|
|
|
case IDLE: |
|
|
|
jump_velocity = NORMAL_JUMP_VELOCITY; |
|
|
|
jump_velocity = NORMAL_JUMP_VELOCITY; |
|
|
|
horizontal_friction = NORMAL_FRICTION; |
|
|
|
horizontal_friction = NORMAL_FRICTION; |
|
|
|
jump_slide_fall_StartAnimationTimer=-1; |
|
|
|
jump_slide_fall_StartAnimationTimer=-1; |
|
|
|
|
|
|
|
|
|
|
|
if(KeyHeld(KeyEvent.VK_A)||KeyHeld(KeyEvent.VK_LEFT)){ |
|
|
|
if(x_velocity!=0){ |
|
|
|
setAnimatedSpr(Sprite.ERINA_WALK); |
|
|
|
setAnimatedSpr(Sprite.ERINA_WALK); |
|
|
|
} |
|
|
|
} |
|
|
|
if(KeyHeld(KeyEvent.VK_D)||KeyHeld(KeyEvent.VK_RIGHT)){ |
|
|
|
else{ |
|
|
|
setAnimatedSpr(Sprite.ERINA_WALK); |
|
|
|
setAnimatedSpr(Sprite.ERINA); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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: |
|
|
|
if(prvState==State.SLIDE){ |
|
|
|
if(prvState==State.SLIDE){ |
|
|
|
//jump_velocity=-500;
|
|
|
|
//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); |
|
|
|
} |
|
|
|
} |
|
|
|
if(System.currentTimeMillis()-jump_slide_fall_StartAnimationTimer>jump_fall_AnimationWaitTime){ |
|
|
|
if(System.currentTimeMillis()-jump_slide_fall_StartAnimationTimer>jump_fall_AnimationWaitTime){ |
|
|
|
setAnimatedSpr(Sprite.ERINA_JUMP_RISE); |
|
|
|
setAnimatedSpr(Sprite.ERINA_JUMP_RISE); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case SLIDE: |
|
|
|
case SLIDE: |
|
|
|
horizontal_friction=0; |
|
|
|
horizontal_friction=0; |
|
|
|
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_SLIDE1); |
|
|
|
setAnimatedSpr(Sprite.ERINA_SLIDE1); |
|
|
|
} |
|
|
|
|
|
|
|
if(System.currentTimeMillis()-jump_slide_fall_StartAnimationTimer>slide_AnimationWaitTime){ |
|
|
|
|
|
|
|
setAnimatedSpr(Sprite.ERINA_SLIDE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
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)){ |
|
|
|
if(System.currentTimeMillis()-jump_slide_fall_StartAnimationTimer>slide_AnimationWaitTime){ |
|
|
|
facing_direction=RIGHT; |
|
|
|
setAnimatedSpr(Sprite.ERINA_SLIDE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(System.currentTimeMillis()-slide_time>slide_duration){ |
|
|
|
|
|
|
|
if(KeyHeld(Action.MOVE_LEFT)){ |
|
|
|
|
|
|
|
facing_direction=LEFT; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(KeyHeld(Action.MOVE_RIGHT)){ |
|
|
|
|
|
|
|
facing_direction=RIGHT; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
state=State.IDLE; |
|
|
|
} |
|
|
|
} |
|
|
|
state=State.IDLE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case STAGGER: |
|
|
|
case STAGGER: |
|
|
|
break; |
|
|
|
break; |
|
|
@ -146,7 +133,7 @@ public class Player extends AnimatedObject{ |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
prvState = state; |
|
|
|
prvState = state; |
|
|
|
if ((KeyHeld(KeyEvent.VK_SPACE)||KeyHeld(KeyEvent.VK_W))&&System.currentTimeMillis()-spacebarPressed<jumpHoldTime) { |
|
|
|
if (KeyHeld(Action.JUMP)&&System.currentTimeMillis()-spacebarPressed<jumpHoldTime) { |
|
|
|
y_velocity=jump_velocity; |
|
|
|
y_velocity=jump_velocity; |
|
|
|
} |
|
|
|
} |
|
|
|
//System.out.println(state);
|
|
|
|
//System.out.println(state);
|
|
|
@ -154,42 +141,42 @@ public class Player extends AnimatedObject{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void KeyReleased(int key) { |
|
|
|
protected void KeyReleased(Action a) { |
|
|
|
if (key==KeyEvent.VK_SPACE||key==KeyEvent.VK_W) { |
|
|
|
if (a==Action.JUMP) { |
|
|
|
spacebarPressed=0; |
|
|
|
spacebarPressed=0; |
|
|
|
spacebarReleased=true; |
|
|
|
spacebarReleased=true; |
|
|
|
} |
|
|
|
} |
|
|
|
if(state!=State.SLIDE){ |
|
|
|
if(state!=State.SLIDE){ |
|
|
|
if((key==KeyEvent.VK_A||key==KeyEvent.VK_LEFT)&&(KeyHeld(KeyEvent.VK_D)||KeyHeld(KeyEvent.VK_RIGHT))){ |
|
|
|
if((a==Action.MOVE_LEFT)&&(KeyHeld(Action.MOVE_RIGHT))){ |
|
|
|
facing_direction=RIGHT; |
|
|
|
facing_direction=RIGHT; |
|
|
|
} |
|
|
|
} else |
|
|
|
if((key==KeyEvent.VK_D||key==KeyEvent.VK_RIGHT)&&(KeyHeld(KeyEvent.VK_A)||KeyHeld(KeyEvent.VK_LEFT))){ |
|
|
|
if((a==Action.MOVE_RIGHT)&&(KeyHeld(Action.MOVE_LEFT))){ |
|
|
|
facing_direction=LEFT; |
|
|
|
facing_direction=LEFT; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void KeyPressed(int key) { |
|
|
|
@SuppressWarnings("incomplete-switch") |
|
|
|
|
|
|
|
protected void KeyPressed(Action a) { |
|
|
|
switch(state){ |
|
|
|
switch(state){ |
|
|
|
case ATTACK: |
|
|
|
case ATTACK: |
|
|
|
break; |
|
|
|
break; |
|
|
|
case IDLE: |
|
|
|
case IDLE: |
|
|
|
if(key==KeyEvent.VK_CONTROL){ |
|
|
|
if(a==Action.SLIDE||a==Action.FALL){ |
|
|
|
slide_time = System.currentTimeMillis(); |
|
|
|
slide_time = System.currentTimeMillis(); |
|
|
|
if(facing_direction){ |
|
|
|
if(facing_direction){ |
|
|
|
x_velocity=sliding_velocity; |
|
|
|
x_velocity=sliding_velocity; |
|
|
|
} |
|
|
|
} |
|
|
|
else{ |
|
|
|
else{ |
|
|
|
x_velocity=-sliding_velocity; |
|
|
|
x_velocity=-sliding_velocity; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
state=State.SLIDE; |
|
|
|
} |
|
|
|
} |
|
|
|
state=State.SLIDE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case FALLING: |
|
|
|
case FALLING: |
|
|
|
case JUMP: |
|
|
|
case JUMP: |
|
|
|
if(jumpCount>0 && spacebarReleased && (key == KeyEvent.VK_SPACE || key == KeyEvent.VK_W)){ |
|
|
|
if(jumpCount>0 && spacebarReleased && (a==Action.JUMP)){ |
|
|
|
jumpCount=0; |
|
|
|
jumpCount=0; |
|
|
|
y_velocity = jump_velocity; |
|
|
|
y_velocity = jump_velocity; |
|
|
|
spacebarReleased=false; |
|
|
|
spacebarReleased=false; |
|
|
@ -206,7 +193,7 @@ public class Player extends AnimatedObject{ |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if (groundCollision) { |
|
|
|
if (groundCollision) { |
|
|
|
if (spacebarReleased&&(key==KeyEvent.VK_SPACE||key==KeyEvent.VK_W)&&jumpCount>0) { |
|
|
|
if (spacebarReleased&&(a==Action.JUMP)&&jumpCount>0) { |
|
|
|
state = State.JUMP; |
|
|
|
state = State.JUMP; |
|
|
|
jumpCount--; |
|
|
|
jumpCount--; |
|
|
|
y_velocity = jump_velocity; |
|
|
|
y_velocity = jump_velocity; |
|
|
@ -216,12 +203,12 @@ public class Player extends AnimatedObject{ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if(state!=State.SLIDE){ |
|
|
|
if(state!=State.SLIDE){ |
|
|
|
switch(key){ |
|
|
|
switch(a){ |
|
|
|
case KeyEvent.VK_LEFT: case KeyEvent.VK_A: |
|
|
|
case MOVE_LEFT: |
|
|
|
facing_direction=LEFT; |
|
|
|
facing_direction=LEFT; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case KeyEvent.VK_RIGHT:case KeyEvent.VK_D: |
|
|
|
case MOVE_RIGHT: |
|
|
|
facing_direction=RIGHT; |
|
|
|
facing_direction=RIGHT; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -318,8 +305,8 @@ 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(Action.MOVE_RIGHT)?1:0; |
|
|
|
int left = (KeyHeld(KeyEvent.VK_LEFT))||(KeyHeld(KeyEvent.VK_A))?1:0; |
|
|
|
int left = KeyHeld(Action.MOVE_LEFT)?1:0; |
|
|
|
if(state==State.SLIDE){ |
|
|
|
if(state==State.SLIDE){ |
|
|
|
right=0; |
|
|
|
right=0; |
|
|
|
left=0; |
|
|
|
left=0; |
|
|
|