|
|
@ -65,13 +65,14 @@ public class Player extends AnimatedObject{ |
|
|
|
final static long slideBufferTime = TimeUtils.millisToNanos(200); |
|
|
|
final static long slideBufferTime = TimeUtils.millisToNanos(200); |
|
|
|
long slidePressed = -1; |
|
|
|
long slidePressed = -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean onSlope = false; |
|
|
|
|
|
|
|
|
|
|
|
public Player(Panel panel) { |
|
|
|
public Player(Panel panel) { |
|
|
|
super(Sprite.ERINA, 5, panel); |
|
|
|
super(Sprite.ERINA, 5, panel); |
|
|
|
setX(RabiClone.BASE_WIDTH / 2 - getAnimatedSpr().getWidth() / 2); |
|
|
|
setX(RabiClone.BASE_WIDTH / 2 - getAnimatedSpr().getWidth() / 2); |
|
|
|
setY(RabiClone.BASE_HEIGHT * (2 / 3d) - getAnimatedSpr().getHeight() / 2); |
|
|
|
setY(RabiClone.BASE_HEIGHT * (2 / 3d) - getAnimatedSpr().getHeight() / 2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void update(double updateMult) { |
|
|
|
public void update(double updateMult) { |
|
|
|
super.update(updateMult); |
|
|
|
super.update(updateMult); |
|
|
@ -105,12 +106,10 @@ public class Player extends AnimatedObject{ |
|
|
|
setAnimatedSpr(Sprite.ERINA_WALK); |
|
|
|
setAnimatedSpr(Sprite.ERINA_WALK); |
|
|
|
if (x_velocity > 0) { |
|
|
|
if (x_velocity > 0) { |
|
|
|
facing_direction = RIGHT; |
|
|
|
facing_direction = RIGHT; |
|
|
|
} else |
|
|
|
} else if (x_velocity < 0) { |
|
|
|
if (x_velocity<0) { |
|
|
|
|
|
|
|
facing_direction = LEFT; |
|
|
|
facing_direction = LEFT; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
else{ |
|
|
|
|
|
|
|
setAnimatedSpr(Sprite.ERINA); |
|
|
|
setAnimatedSpr(Sprite.ERINA); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -150,8 +149,7 @@ public class Player extends AnimatedObject{ |
|
|
|
facing_direction == RIGHT && x_velocity > sliding_velocity * 0.5) { |
|
|
|
facing_direction == RIGHT && x_velocity > sliding_velocity * 0.5) { |
|
|
|
x_velocity -= sliding_acceleration * updateMult; |
|
|
|
x_velocity -= sliding_acceleration * updateMult; |
|
|
|
} |
|
|
|
} |
|
|
|
} else |
|
|
|
} else if (KeyHeld(Action.MOVE_RIGHT) && !KeyHeld(Action.MOVE_LEFT)) { |
|
|
|
if (KeyHeld(Action.MOVE_RIGHT)&&!KeyHeld(Action.MOVE_LEFT)) { |
|
|
|
|
|
|
|
if (facing_direction == LEFT && x_velocity < -sliding_velocity * 0.5 || |
|
|
|
if (facing_direction == LEFT && x_velocity < -sliding_velocity * 0.5 || |
|
|
|
facing_direction == RIGHT && x_velocity < sliding_velocity * 1.5) { |
|
|
|
facing_direction == RIGHT && x_velocity < sliding_velocity * 1.5) { |
|
|
|
x_velocity += sliding_acceleration * updateMult; |
|
|
|
x_velocity += sliding_acceleration * updateMult; |
|
|
@ -172,7 +170,6 @@ public class Player extends AnimatedObject{ |
|
|
|
// System.out.println(state);
|
|
|
|
// System.out.println(state);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void KeyReleased(Action a) { |
|
|
|
protected void KeyReleased(Action a) { |
|
|
|
if (a == Action.JUMP) { |
|
|
|
if (a == Action.JUMP) { |
|
|
@ -182,8 +179,7 @@ public class Player extends AnimatedObject{ |
|
|
|
if (state != State.SLIDE) { |
|
|
|
if (state != State.SLIDE) { |
|
|
|
if ((a == Action.MOVE_LEFT) && (KeyHeld(Action.MOVE_RIGHT))) { |
|
|
|
if ((a == Action.MOVE_LEFT) && (KeyHeld(Action.MOVE_RIGHT))) { |
|
|
|
facing_direction = RIGHT; |
|
|
|
facing_direction = RIGHT; |
|
|
|
} else |
|
|
|
} else if ((a == Action.MOVE_RIGHT) && (KeyHeld(Action.MOVE_LEFT))) { |
|
|
|
if((a==Action.MOVE_RIGHT)&&(KeyHeld(Action.MOVE_LEFT))){ |
|
|
|
|
|
|
|
facing_direction = LEFT; |
|
|
|
facing_direction = LEFT; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -244,24 +240,22 @@ public class Player extends AnimatedObject{ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void performSlide() { |
|
|
|
private void performSlide() { |
|
|
|
slide_time = RabiClone.TIME; |
|
|
|
slide_time = RabiClone.TIME; |
|
|
|
slide_time2 = System.nanoTime(); |
|
|
|
slide_time2 = System.nanoTime(); |
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void handleCameraRoomMovement() { |
|
|
|
private void handleCameraRoomMovement() { |
|
|
|
int tileX = (int) (getX()) / Tile.TILE_WIDTH; |
|
|
|
int tileX = (int) (getX()) / Tile.TILE_WIDTH; |
|
|
|
int tileY = (int) (getY()) / Tile.TILE_HEIGHT; |
|
|
|
int tileY = (int) (getY()) / Tile.TILE_HEIGHT; |
|
|
|
double newX=RabiClone.level_renderer.getX(),newY=RabiClone.level_renderer.getY(); //By default we use a fixed view.
|
|
|
|
double newX = RabiClone.level_renderer.getX(), newY = RabiClone.level_renderer.getY(); // By default we use a
|
|
|
|
|
|
|
|
// fixed view.
|
|
|
|
View currentView = RabiClone.CURRENT_MAP.getView(tileX, tileY); |
|
|
|
View currentView = RabiClone.CURRENT_MAP.getView(tileX, tileY); |
|
|
|
if (currentView != lastCameraView) { |
|
|
|
if (currentView != lastCameraView) { |
|
|
|
lastCameraView = currentView; |
|
|
|
lastCameraView = currentView; |
|
|
@ -346,7 +340,6 @@ public class Player extends AnimatedObject{ |
|
|
|
RabiClone.level_renderer.setY(newY < 0 ? 0 : newY); |
|
|
|
RabiClone.level_renderer.setY(newY < 0 ? 0 : newY); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void handleMovementPhysics(double updateMult) { |
|
|
|
private void handleMovementPhysics(double updateMult) { |
|
|
|
int right = KeyHeld(Action.MOVE_RIGHT)?1:0; |
|
|
|
int right = KeyHeld(Action.MOVE_RIGHT)?1:0; |
|
|
|
int left = KeyHeld(Action.MOVE_LEFT)?1:0; |
|
|
|
int left = KeyHeld(Action.MOVE_LEFT)?1:0; |
|
|
@ -364,6 +357,7 @@ public class Player extends AnimatedObject{ |
|
|
|
: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 sideCollision = false; |
|
|
|
boolean sideCollision = false; |
|
|
|
for(int i=0;i<4;i++){ |
|
|
|
for(int i=0;i<4;i++){ |
|
|
|
double check_distance_x = (displacement_x/4)*(i+1); |
|
|
|
double check_distance_x = (displacement_x/4)*(i+1); |
|
|
@ -416,7 +410,7 @@ public class Player extends AnimatedObject{ |
|
|
|
&& getY()+check_distance_y>ySlopeCollisionPoint(checked_tile_bottom_center)) |
|
|
|
&& getY()+check_distance_y>ySlopeCollisionPoint(checked_tile_bottom_center)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
moveUpSlope(checked_tile_bottom_center); |
|
|
|
moveUpSlope(checked_tile_bottom_center); |
|
|
|
collisionOccured = groundCollision(check_distance_y); |
|
|
|
collisionOccured = groundCollision(0); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
//System.out.println((int)getX()/Tile.TILE_WIDTH);
|
|
|
|
//System.out.println((int)getX()/Tile.TILE_WIDTH);
|
|
|
@ -441,51 +435,47 @@ public class Player extends AnimatedObject{ |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (!sideCollision) { |
|
|
|
if (!sideCollision) { |
|
|
|
Tile checked_tile_bottom_center = RabiClone.CURRENT_MAP.getTile((int)(getX())/Tile.TILE_WIDTH, (int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT); |
|
|
|
|
|
|
|
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); |
|
|
|
if(displacement_x>0){ |
|
|
|
|
|
|
|
if(checked_tile_bottom_center==Tile.SMALL_SLOPE_RIGHT){ |
|
|
|
|
|
|
|
setY(getY()+displacement_x); |
|
|
|
|
|
|
|
System.out.println("We're in RIGHT."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else{ |
|
|
|
|
|
|
|
if(checked_tile_bottom_center==Tile.SMALL_SLOPE_LEFT){ |
|
|
|
|
|
|
|
setY(getY()-displacement_x); |
|
|
|
|
|
|
|
System.out.println("We're in it for LEFT."); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private double ySlopeCollisionPoint(Tile tile) { |
|
|
|
private double ySlopeCollisionPoint(Tile tile) { |
|
|
|
switch (tile) { |
|
|
|
switch (tile) { |
|
|
|
case BIG_SLOPE_LEFT1: |
|
|
|
case BIG_SLOPE_LEFT1: |
|
|
|
return -(getX()%Tile.TILE_WIDTH/2)+(int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT*Tile.TILE_HEIGHT+(getAnimatedSpr().getHeight()/2-4); |
|
|
|
return -(getX() % Tile.TILE_WIDTH / 2) |
|
|
|
|
|
|
|
+ (int) (getY() + getAnimatedSpr().getHeight() / 2) / Tile.TILE_HEIGHT * Tile.TILE_HEIGHT |
|
|
|
|
|
|
|
+ (getAnimatedSpr().getHeight() / 2 - 4); |
|
|
|
|
|
|
|
|
|
|
|
case BIG_SLOPE_LEFT2: |
|
|
|
case BIG_SLOPE_LEFT2: |
|
|
|
return -(getX()%Tile.TILE_WIDTH/2)+(int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT*Tile.TILE_HEIGHT+(getAnimatedSpr().getHeight()/2-4)-Tile.TILE_WIDTH/2; |
|
|
|
return -(getX() % Tile.TILE_WIDTH / 2) |
|
|
|
|
|
|
|
+ (int) (getY() + getAnimatedSpr().getHeight() / 2) / Tile.TILE_HEIGHT * Tile.TILE_HEIGHT |
|
|
|
|
|
|
|
+ (getAnimatedSpr().getHeight() / 2 - 4) - Tile.TILE_WIDTH / 2; |
|
|
|
|
|
|
|
|
|
|
|
case BIG_SLOPE_RIGHT1: |
|
|
|
case BIG_SLOPE_RIGHT1: |
|
|
|
return (getX()%Tile.TILE_WIDTH/2)+(int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT*Tile.TILE_HEIGHT+(getAnimatedSpr().getHeight()/2-4)-Tile.TILE_WIDTH; |
|
|
|
return (getX() % Tile.TILE_WIDTH / 2) |
|
|
|
|
|
|
|
+ (int) (getY() + getAnimatedSpr().getHeight() / 2) / Tile.TILE_HEIGHT * Tile.TILE_HEIGHT |
|
|
|
|
|
|
|
+ (getAnimatedSpr().getHeight() / 2 - 4) - Tile.TILE_WIDTH; |
|
|
|
|
|
|
|
|
|
|
|
case BIG_SLOPE_RIGHT2: |
|
|
|
case BIG_SLOPE_RIGHT2: |
|
|
|
return (getX()%Tile.TILE_WIDTH/2)+(int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT*Tile.TILE_HEIGHT+(getAnimatedSpr().getHeight()/2-4)-Tile.TILE_WIDTH+Tile.TILE_WIDTH/2; |
|
|
|
return (getX() % Tile.TILE_WIDTH / 2) |
|
|
|
|
|
|
|
+ (int) (getY() + getAnimatedSpr().getHeight() / 2) / Tile.TILE_HEIGHT * Tile.TILE_HEIGHT |
|
|
|
|
|
|
|
+ (getAnimatedSpr().getHeight() / 2 - 4) - Tile.TILE_WIDTH + Tile.TILE_WIDTH / 2; |
|
|
|
|
|
|
|
|
|
|
|
case SMALL_SLOPE_LEFT: |
|
|
|
case SMALL_SLOPE_LEFT: |
|
|
|
return -(getX()%Tile.TILE_WIDTH)+(int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT*Tile.TILE_HEIGHT+(getAnimatedSpr().getHeight()/2-4); |
|
|
|
return -(getX() % Tile.TILE_WIDTH) |
|
|
|
|
|
|
|
+ (int) (getY() + getAnimatedSpr().getHeight() / 2) / Tile.TILE_HEIGHT * Tile.TILE_HEIGHT |
|
|
|
|
|
|
|
+ (getAnimatedSpr().getHeight() / 2 - 4); |
|
|
|
|
|
|
|
|
|
|
|
case SMALL_SLOPE_RIGHT: |
|
|
|
case SMALL_SLOPE_RIGHT: |
|
|
|
return (getX()%Tile.TILE_WIDTH)+(int)(getY()+getAnimatedSpr().getHeight()/2)/Tile.TILE_HEIGHT*Tile.TILE_HEIGHT+(getAnimatedSpr().getHeight()/2-4)-Tile.TILE_WIDTH; |
|
|
|
return (getX() % Tile.TILE_WIDTH) |
|
|
|
|
|
|
|
+ (int) (getY() + getAnimatedSpr().getHeight() / 2) / Tile.TILE_HEIGHT * Tile.TILE_HEIGHT |
|
|
|
|
|
|
|
+ (getAnimatedSpr().getHeight() / 2 - 4) - Tile.TILE_WIDTH; |
|
|
|
} |
|
|
|
} |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void moveUpSlope(Tile checked_tile_bottom_center) { |
|
|
|
private void moveUpSlope(Tile checked_tile_bottom_center) { |
|
|
|
setY(ySlopeCollisionPoint(checked_tile_bottom_center)); |
|
|
|
setY(ySlopeCollisionPoint(checked_tile_bottom_center)); |
|
|
|
} |
|
|
|
} |
|
|
@ -503,7 +493,6 @@ public class Player extends AnimatedObject{ |
|
|
|
return collisionOccured; |
|
|
|
return collisionOccured; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void handleKeyboardMovement(double updateMult, int movement, double friction, double drag) { |
|
|
|
private void handleKeyboardMovement(double updateMult, int movement, double friction, double drag) { |
|
|
|
if (movement != 0 && Math.abs(x_velocity) < WALKING_SPEED_LIMIT) { |
|
|
|
if (movement != 0 && Math.abs(x_velocity) < WALKING_SPEED_LIMIT) { |
|
|
|
x_acceleration = drag * (movement); |
|
|
|
x_acceleration = drag * (movement); |
|
|
@ -522,13 +511,15 @@ public class Player extends AnimatedObject{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void draw(byte[] p) {} |
|
|
|
public void draw(byte[] p) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
public String toString() { |
|
|
|
return "Player [facing_direction=" + (facing_direction?"RIGHT":"LEFT") + ", groundCollision=" + groundCollision + ", jumpCount=" |
|
|
|
return "Player [facing_direction=" + (facing_direction ? "RIGHT" : "LEFT") + ", groundCollision=" |
|
|
|
+ jumpCount + ", x_velocity=" + x_velocity + ", y_velocity=" + y_velocity + ", x=" + getX() + ", y=" + getY() + "]"; |
|
|
|
+ groundCollision + ", jumpCount=" |
|
|
|
|
|
|
|
+ jumpCount + ", x_velocity=" + x_velocity + ", y_velocity=" + y_velocity + ", x=" + getX() + ", y=" |
|
|
|
|
|
|
|
+ getY() + "]"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|