From 71a9bd087120eca557bc99186541e19e401e969a Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Tue, 14 Jun 2022 20:30:36 -0500 Subject: [PATCH] Complete refactor of physics code to apply to other objects Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 --- maps/world1.map | Bin 299024 -> 299028 bytes src/sig/objects/Erinoah.java | 9 +++ src/sig/objects/LevelRenderer.java | 2 +- src/sig/objects/Player.java | 36 +++------ src/sig/objects/actor/PhysicsObject.java | 75 +++++++++++++++--- .../actor/PhysicsObjectRequirements.java | 10 +++ 6 files changed, 99 insertions(+), 33 deletions(-) diff --git a/maps/world1.map b/maps/world1.map index 34e6161b6fa095666bd54e5f2a659ae102b06634..1432afebbf7dbad5ce09a0bdcff7f9ca2f6300f4 100644 GIT binary patch delta 35 pcmbQRKxoPWp@tU57N!>FEiB9v1X&n3n79}OSVR~&c!Yph3;?Q|28RFu delta 31 lcmbQTKxo1Op@tU57N!>FEiB9vc$palSVR~&c!Yph3;>Z}25tZV diff --git a/src/sig/objects/Erinoah.java b/src/sig/objects/Erinoah.java index 67fd0a3..38fbdc1 100644 --- a/src/sig/objects/Erinoah.java +++ b/src/sig/objects/Erinoah.java @@ -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 diff --git a/src/sig/objects/LevelRenderer.java b/src/sig/objects/LevelRenderer.java index 42a4d5b..5e8e5a4 100644 --- a/src/sig/objects/LevelRenderer.java +++ b/src/sig/objects/LevelRenderer.java @@ -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); } } diff --git a/src/sig/objects/Player.java b/src/sig/objects/Player.java index d94220b..b0b10e4 100644 --- a/src/sig/objects/Player.java +++ b/src/sig/objects/Player.java @@ -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; + } } diff --git a/src/sig/objects/actor/PhysicsObject.java b/src/sig/objects/actor/PhysicsObject.java index 465108f..9fc6b93 100644 --- a/src/sig/objects/actor/PhysicsObject.java +++ b/src/sig/objects/actor/PhysicsObject.java @@ -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; + } } diff --git a/src/sig/objects/actor/PhysicsObjectRequirements.java b/src/sig/objects/actor/PhysicsObjectRequirements.java index fbfb612..a4482d3 100644 --- a/src/sig/objects/actor/PhysicsObjectRequirements.java +++ b/src/sig/objects/actor/PhysicsObjectRequirements.java @@ -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); }