|
|
@ -1,6 +1,7 @@ |
|
|
|
package sig.objects; |
|
|
|
package sig.objects; |
|
|
|
|
|
|
|
|
|
|
|
import sig.RabiClone; |
|
|
|
import sig.RabiClone; |
|
|
|
|
|
|
|
import sig.engine.AnimatedObject; |
|
|
|
import sig.engine.Object; |
|
|
|
import sig.engine.Object; |
|
|
|
import sig.engine.Panel; |
|
|
|
import sig.engine.Panel; |
|
|
|
import sig.engine.Sprite; |
|
|
|
import sig.engine.Sprite; |
|
|
@ -8,10 +9,11 @@ import sig.map.CollisionType; |
|
|
|
import sig.map.Map; |
|
|
|
import sig.map.Map; |
|
|
|
import sig.map.Tile; |
|
|
|
import sig.map.Tile; |
|
|
|
import sig.map.View; |
|
|
|
import sig.map.View; |
|
|
|
|
|
|
|
import sig.objects.actor.State; |
|
|
|
|
|
|
|
|
|
|
|
import java.awt.event.KeyEvent; |
|
|
|
import java.awt.event.KeyEvent; |
|
|
|
|
|
|
|
|
|
|
|
public class Player extends Object{ |
|
|
|
public class Player extends AnimatedObject{ |
|
|
|
final double GRAVITY = 890; |
|
|
|
final double GRAVITY = 890; |
|
|
|
final double NORMAL_FRICTION = 6400; |
|
|
|
final double NORMAL_FRICTION = 6400; |
|
|
|
|
|
|
|
|
|
|
@ -29,27 +31,82 @@ public class Player extends Object{ |
|
|
|
double horizontal_air_drag = 600; |
|
|
|
double horizontal_air_drag = 600; |
|
|
|
double horizontal_air_friction = 180; |
|
|
|
double horizontal_air_friction = 180; |
|
|
|
|
|
|
|
|
|
|
|
double jump_velocity = -400; |
|
|
|
double jump_velocity = -200; |
|
|
|
|
|
|
|
|
|
|
|
int maxJumpCount=1; |
|
|
|
int maxJumpCount=2; |
|
|
|
int jumpCount=maxJumpCount; |
|
|
|
int jumpCount=maxJumpCount; |
|
|
|
|
|
|
|
State state = State.IDLE; |
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
View lastCameraView = View.FIXED; |
|
|
|
View lastCameraView = View.FIXED; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean groundCollision = false; |
|
|
|
|
|
|
|
boolean spacebarReleased = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long spacebarPressed = System.currentTimeMillis(); |
|
|
|
|
|
|
|
int jumpHoldTime = 150; |
|
|
|
|
|
|
|
|
|
|
|
public Player(Panel panel) { |
|
|
|
public Player(Panel panel) { |
|
|
|
super(panel); |
|
|
|
super(Sprite.ERINA,5,panel); |
|
|
|
this.setSprite(Sprite.NANA_SMALL); |
|
|
|
setX(RabiClone.BASE_WIDTH/2-getAnimatedSpr().getWidth()/2); |
|
|
|
setX(RabiClone.BASE_WIDTH/2-getSprite().getWidth()/2); |
|
|
|
setY(RabiClone.BASE_HEIGHT*(2/3d)-getAnimatedSpr().getHeight()/2); |
|
|
|
setY(RabiClone.BASE_HEIGHT*(2/3d)-getSprite().getHeight()/2); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void update(double updateMult) { |
|
|
|
public void update(double updateMult) { |
|
|
|
|
|
|
|
super.update(updateMult); |
|
|
|
handleMovementPhysics(updateMult); |
|
|
|
handleMovementPhysics(updateMult); |
|
|
|
handleCameraRoomMovement(); |
|
|
|
handleCameraRoomMovement(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch(state){ |
|
|
|
|
|
|
|
case ATTACK: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case FALLING: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case IDLE: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case JUMP: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case SLIDE: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case STAGGER: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case UNCONTROLLABLE: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println(state); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void KeyReleased(int key) { |
|
|
|
|
|
|
|
if (key==KeyEvent.VK_SPACE) { |
|
|
|
|
|
|
|
spacebarReleased=true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void KeyPressed(int key) { |
|
|
|
|
|
|
|
if (groundCollision) { |
|
|
|
|
|
|
|
if (spacebarReleased&&key==KeyEvent.VK_SPACE&&jumpCount>0) { |
|
|
|
|
|
|
|
state = State.JUMP; |
|
|
|
|
|
|
|
jumpCount--; |
|
|
|
|
|
|
|
y_velocity = jump_velocity; |
|
|
|
|
|
|
|
spacebarReleased=false; |
|
|
|
|
|
|
|
//System.out.println("Jump");
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else |
|
|
|
|
|
|
|
if ((state == State.JUMP||state==State.FALLING) && jumpCount>0 && spacebarReleased && key == KeyEvent.VK_SPACE){ |
|
|
|
|
|
|
|
jumpCount=0; |
|
|
|
|
|
|
|
y_velocity = jump_velocity; |
|
|
|
|
|
|
|
spacebarReleased=false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -152,18 +209,44 @@ public class Player extends Object{ |
|
|
|
:y_velocity+y_acceleration*updateMult; |
|
|
|
:y_velocity+y_acceleration*updateMult; |
|
|
|
double displacement_y = y_velocity*updateMult; |
|
|
|
double displacement_y = y_velocity*updateMult; |
|
|
|
double displacement_x = x_velocity*updateMult; |
|
|
|
double displacement_x = x_velocity*updateMult; |
|
|
|
boolean groundCollision = false; |
|
|
|
|
|
|
|
boolean sideCollision = false; |
|
|
|
boolean sideCollision = false; |
|
|
|
|
|
|
|
for(int i=0;i<4;i++){ |
|
|
|
|
|
|
|
double check_distance_x = (displacement_x/4)*(i+1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Tile checked_tile_top_right = RabiClone.CURRENT_MAP.getTile((int)(getX()+getAnimatedSpr().getWidth()/2-4+check_distance_x)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT); |
|
|
|
|
|
|
|
Tile checked_tile_top_left = RabiClone.CURRENT_MAP.getTile((int)(getX()-getAnimatedSpr().getWidth()/2+4+check_distance_x)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT); |
|
|
|
|
|
|
|
if(checked_tile_top_right.getCollision()==CollisionType.BLOCK||checked_tile_top_left.getCollision()==CollisionType.BLOCK){ |
|
|
|
|
|
|
|
//System.out.println(checked_tile_top_right.getCollision()+"//"+checked_tile_top_left.getCollision());
|
|
|
|
|
|
|
|
if (checked_tile_top_right.getCollision()==CollisionType.BLOCK) { |
|
|
|
|
|
|
|
setX(((int)(getX()-getAnimatedSpr().getWidth()/2)/Tile.TILE_WIDTH)*Tile.TILE_WIDTH+Tile.TILE_WIDTH/2+3+check_distance_x); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setX(((int)(getX()+getAnimatedSpr().getWidth())/Tile.TILE_WIDTH)*Tile.TILE_WIDTH-Tile.TILE_WIDTH/2-3+check_distance_x); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
x_acceleration = 0; |
|
|
|
|
|
|
|
x_velocity = 0; |
|
|
|
|
|
|
|
sideCollision=true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (y_velocity==0) { |
|
|
|
|
|
|
|
Tile checked_tile_bottom_right = RabiClone.CURRENT_MAP.getTile((int)(getX()+getAnimatedSpr().getWidth()/2-4)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2+0.5)/Tile.TILE_HEIGHT); |
|
|
|
|
|
|
|
Tile checked_tile_bottom_left = RabiClone.CURRENT_MAP.getTile((int)(getX()-getAnimatedSpr().getWidth()/2+4)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2+0.5)/Tile.TILE_HEIGHT); |
|
|
|
|
|
|
|
if (!(checked_tile_bottom_right.getCollision()==CollisionType.BLOCK||checked_tile_bottom_left.getCollision()==CollisionType.BLOCK)) { |
|
|
|
|
|
|
|
groundCollision=false; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
groundCollision=true; |
|
|
|
|
|
|
|
jumpCount=maxJumpCount; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
//System.out.println(x_velocity);
|
|
|
|
//System.out.println(x_velocity);
|
|
|
|
//System.out.println(((int)(getX()+getSprite().getWidth()/2+displacement_x)/Tile.TILE_WIDTH)+"//"+((int)(getY()+getSprite().getHeight()/2)/Tile.TILE_HEIGHT));
|
|
|
|
//System.out.println(((int)(getX()+getAnimatedSpr().getWidth()/2+displacement_x)/Tile.TILE_WIDTH)+"//"+((int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT));
|
|
|
|
|
|
|
|
boolean collisionOccured=false; |
|
|
|
for(int i=0;i<4;i++){ |
|
|
|
for(int i=0;i<4;i++){ |
|
|
|
if (sideCollision&&groundCollision) { |
|
|
|
if (groundCollision) { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
double check_distance_y = (displacement_y/4)*(i+1); |
|
|
|
double check_distance_y = (displacement_y/4)*(i+1); |
|
|
|
double check_distance_x = (displacement_x/4)*(i+1); |
|
|
|
Tile checked_tile_bottom_right = RabiClone.CURRENT_MAP.getTile((int)(getX()+getAnimatedSpr().getWidth()/2-4)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2+check_distance_y)/Tile.TILE_HEIGHT); |
|
|
|
Tile checked_tile_bottom_right = RabiClone.CURRENT_MAP.getTile((int)(getX()+getSprite().getWidth()/2-4)/Tile.TILE_WIDTH, (int)(getY()+getSprite().getHeight()/2+check_distance_y)/Tile.TILE_HEIGHT); |
|
|
|
Tile checked_tile_bottom_left = RabiClone.CURRENT_MAP.getTile((int)(getX()-getAnimatedSpr().getWidth()/2+4)/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2+check_distance_y)/Tile.TILE_HEIGHT); |
|
|
|
Tile checked_tile_bottom_left = RabiClone.CURRENT_MAP.getTile((int)(getX()-getSprite().getWidth()/2+4)/Tile.TILE_WIDTH, (int)(getY()+getSprite().getHeight()/2+check_distance_y)/Tile.TILE_HEIGHT); |
|
|
|
|
|
|
|
//System.out.println((int)getX()/Tile.TILE_WIDTH);
|
|
|
|
//System.out.println((int)getX()/Tile.TILE_WIDTH);
|
|
|
|
if(checked_tile_bottom_right.getCollision()==CollisionType.BLOCK||checked_tile_bottom_left.getCollision()==CollisionType.BLOCK){ |
|
|
|
if(checked_tile_bottom_right.getCollision()==CollisionType.BLOCK||checked_tile_bottom_left.getCollision()==CollisionType.BLOCK){ |
|
|
|
setY((getY()-check_distance_y)); |
|
|
|
setY((getY()-check_distance_y)); |
|
|
@ -173,35 +256,25 @@ public class Player extends Object{ |
|
|
|
y_acceleration = 0; |
|
|
|
y_acceleration = 0; |
|
|
|
y_velocity = 0; |
|
|
|
y_velocity = 0; |
|
|
|
groundCollision=true; |
|
|
|
groundCollision=true; |
|
|
|
|
|
|
|
collisionOccured=true; |
|
|
|
|
|
|
|
state = State.IDLE; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Tile checked_tile_top_right = RabiClone.CURRENT_MAP.getTile((int)(getX()+getSprite().getWidth()/2-4+check_distance_x)/Tile.TILE_WIDTH, (int)(getY()+getSprite().getHeight()/2)/Tile.TILE_HEIGHT); |
|
|
|
|
|
|
|
Tile checked_tile_top_left = RabiClone.CURRENT_MAP.getTile((int)(getX()-getSprite().getWidth()/2+4+check_distance_x)/Tile.TILE_WIDTH, (int)(getY()+getSprite().getHeight()/2)/Tile.TILE_HEIGHT); |
|
|
|
|
|
|
|
if(checked_tile_top_right.getCollision()==CollisionType.BLOCK||checked_tile_top_left.getCollision()==CollisionType.BLOCK){ |
|
|
|
|
|
|
|
//System.out.println(checked_tile_top_right.getCollision()+"//"+checked_tile_top_left.getCollision());
|
|
|
|
|
|
|
|
if (checked_tile_top_right.getCollision()==CollisionType.BLOCK) { |
|
|
|
|
|
|
|
setX(((int)(getX()-getSprite().getWidth()/2)/Tile.TILE_WIDTH)*Tile.TILE_WIDTH+Tile.TILE_WIDTH/2+3+check_distance_x); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setX(((int)(getX()+getSprite().getWidth())/Tile.TILE_WIDTH)*Tile.TILE_WIDTH-Tile.TILE_WIDTH/2-3+check_distance_x); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
x_acceleration = 0; |
|
|
|
if (!collisionOccured) { |
|
|
|
x_velocity = 0; |
|
|
|
groundCollision=false; |
|
|
|
sideCollision=true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (!groundCollision){ |
|
|
|
if (!groundCollision){ |
|
|
|
this.setY(this.getY()+displacement_y); |
|
|
|
this.setY(this.getY()+displacement_y); |
|
|
|
y_acceleration = GRAVITY; |
|
|
|
y_acceleration = GRAVITY; |
|
|
|
|
|
|
|
if(y_velocity>0){ |
|
|
|
|
|
|
|
state = State.FALLING; |
|
|
|
|
|
|
|
} |
|
|
|
if (!sideCollision) { |
|
|
|
if (!sideCollision) { |
|
|
|
handleKeyboardMovement(updateMult, right-left, horizontal_air_friction, horizontal_air_drag); |
|
|
|
handleKeyboardMovement(updateMult, right-left, horizontal_air_friction, horizontal_air_drag); |
|
|
|
this.setX(this.getX()+displacement_x); |
|
|
|
this.setX(this.getX()+displacement_x); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (KeyHeld(KeyEvent.VK_SPACE)&&jumpCount>0) { |
|
|
|
|
|
|
|
jumpCount--; |
|
|
|
|
|
|
|
y_velocity = jump_velocity; |
|
|
|
|
|
|
|
//System.out.println("Jump");
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!sideCollision) { |
|
|
|
if (!sideCollision) { |
|
|
|
handleKeyboardMovement(updateMult, right-left, horizontal_friction, horizontal_drag); |
|
|
|
handleKeyboardMovement(updateMult, right-left, horizontal_friction, horizontal_drag); |
|
|
|
this.setX(this.getX()+displacement_x); |
|
|
|
this.setX(this.getX()+displacement_x); |
|
|
|