Complete refactor of physics code to apply to other objects

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 2 years ago
parent b39957091c
commit 71a9bd0871
  1. BIN
      maps/world1.map
  2. 9
      src/sig/objects/Erinoah.java
  3. 2
      src/sig/objects/LevelRenderer.java
  4. 36
      src/sig/objects/Player.java
  5. 75
      src/sig/objects/actor/PhysicsObject.java
  6. 10
      src/sig/objects/actor/PhysicsObjectRequirements.java

Binary file not shown.

@ -13,6 +13,15 @@ public class Erinoah extends PhysicsObject implements RenderedObject{
super(Sprite.ERINOAH,6.5,RabiClone.p);
setX(x);
setY(y);
setAccelerationLimits(100, 100);
setVelocityLimits(246, 500);
setGroundDrag(2000);
setGroundFriction(PhysicsObject.NORMAL_FRICTION);
setAirDrag(800);
setAirFriction(180);
setSlidingVelocity(164);
setSlidingAcceleration(120);
setJumpVelocity(PhysicsObject.NORMAL_JUMP_VELOCITY);
}
@Override

@ -73,7 +73,7 @@ public class LevelRenderer extends Object{
}
}
if (RabiClone.player!=null) {
Draw_Text(4,4,new String(RabiClone.player.y_velocity),Font.PROFONT_12);
Draw_Text(4,4,new String(RabiClone.player.getYVelocity()),Font.PROFONT_12);
Draw_Text(4,4+Font.PROFONT_12.getGlyphHeight(),new String(RabiClone.scaleTime),Font.PROFONT_12);
}
}

@ -21,34 +21,12 @@ public class Player extends PhysicsObject implements RenderedObject{
final static long slide_AnimationWaitTime = TimeUtils.millisToNanos(100);
final static long slide_duration = TimeUtils.millisToNanos(700);
double y_acceleration = PhysicsObject.GRAVITY;
double y_acceleration_limit = 100;
double x_acceleration = 0;
double x_acceleration_limit = 100;
double x_velocity = 0;
double x_velocity_limit = 246;
double y_velocity = 5;
double y_velocity_limit = 500;
double sliding_velocity = 164;
double sliding_acceleration = 120;
double horizontal_drag = 2000;
double horizontal_friction = PhysicsObject.NORMAL_FRICTION;
double horizontal_air_drag = 800;
double horizontal_air_friction = 180;
double jump_velocity = PhysicsObject.NORMAL_JUMP_VELOCITY;
int maxJumpCount = 2;
int jumpCount = maxJumpCount;
State state = State.IDLE;
State prvState = state;
final double viewBoundaryX = RabiClone.BASE_WIDTH / 3;
final double viewBoundaryY = RabiClone.BASE_HEIGHT / 3;
View lastCameraView = View.FIXED;
boolean groundCollision = false;
boolean spacebarReleased = true;
boolean facing_direction = RIGHT;
@ -66,6 +44,15 @@ public class Player extends PhysicsObject implements RenderedObject{
super(Sprite.ERINA, 5, panel);
setX(RabiClone.BASE_WIDTH / 2 - getAnimatedSpr().getWidth() / 2);
setY(RabiClone.BASE_HEIGHT * (2 / 3d) - getAnimatedSpr().getHeight() / 2);
setAccelerationLimits(100, 100);
setVelocityLimits(246, 500);
setGroundDrag(2000);
setGroundFriction(PhysicsObject.NORMAL_FRICTION);
setAirDrag(800);
setAirFriction(180);
setSlidingVelocity(164);
setSlidingAcceleration(120);
setJumpVelocity(PhysicsObject.NORMAL_JUMP_VELOCITY);
}
@Override
@ -76,7 +63,6 @@ public class Player extends PhysicsObject implements RenderedObject{
@Override
public void update(double updateMult) {
super.update(updateMult);
handleMovementPhysics(updateMult);
handleCameraRoomMovement();
switch (state) {
@ -365,4 +351,8 @@ public class Player extends PhysicsObject implements RenderedObject{
public boolean leftKeyHeld() {
return KeyHeld(Action.MOVE_LEFT);
}
public double getYVelocity() {
return y_velocity;
}
}

@ -13,16 +13,19 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj
final public static double NORMAL_JUMP_VELOCITY = -300;
final public static double WALKING_SPEED_LIMIT = 164;
State state = State.IDLE;
double x_velocity,y_velocity;
double x_acceleration,y_acceleration;
double x_velocity_limit,y_velocity_limit;
boolean groundCollision;
byte maxJumpCount=2;
byte jumpCount=0;
protected State state = State.IDLE;
protected double x_velocity,y_velocity;
protected double x_acceleration,y_acceleration;
protected double x_velocity_limit,y_velocity_limit;
protected double x_acceleration_limit,y_acceleration_limit;
protected boolean groundCollision;
protected byte maxJumpCount=2;
protected byte jumpCount=0;
protected double jump_velocity;
double horizontal_air_friction,horizontal_air_drag;
double horizontal_friction,horizontal_drag;
protected double horizontal_air_friction,horizontal_air_drag;
protected double horizontal_friction,horizontal_drag;
protected double sliding_velocity,sliding_acceleration;
protected PhysicsObject(AnimatedSprite spr, double animationSpd, Panel panel) {
super(spr, animationSpd, panel);
@ -215,5 +218,59 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj
public Rectangle getCollisionBounds() {
return getCollisionBox();
}
@Override
public void setVelocityLimits(double x, double y) {
this.x_velocity_limit=x;
this.y_velocity_limit=y;
}
@Override
public void setAccelerationLimits(double x, double y) {
this.x_acceleration_limit=x;
this.y_acceleration_limit=y;
}
@Override
public void setMaxJumpCount(byte jumps) {
this.maxJumpCount=jumps;
}
@Override
public void setGroundFriction(double x) {
this.horizontal_friction=x;
}
@Override
public void setAirFriction(double x) {
this.horizontal_air_friction=x;
}
@Override
public void setGroundDrag(double x) {
this.horizontal_drag=x;
}
@Override
public void setAirDrag(double x) {
this.horizontal_air_drag=x;
}
@Override
public void setSlidingVelocity(double x) {
this.sliding_velocity=x;
}
@Override
public void setSlidingAcceleration(double x) {
this.sliding_acceleration=x;
}
@Override
public void setJumpVelocity(double x) {
this.jump_velocity=x;
}
}

@ -7,4 +7,14 @@ public interface PhysicsObjectRequirements {
boolean leftKeyHeld();
Rectangle getCollisionBounds();
Rectangle setCollisionBounds();
void setVelocityLimits(double x,double y);
void setAccelerationLimits(double x,double y);
void setMaxJumpCount(byte jumps);
void setGroundFriction(double x);
void setAirFriction(double x);
void setGroundDrag(double x);
void setAirDrag(double x);
void setSlidingVelocity(double x);
void setSlidingAcceleration(double x);
void setJumpVelocity(double x);
}

Loading…
Cancel
Save