From 8e35ea24d73a14902bef4a14ac31e259fef6b03f Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Tue, 14 Jun 2022 19:29:09 +0000 Subject: [PATCH] Rearrange physics object specific methods so the hierarchy makes more sense Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 --- src/sig/engine/objects/Object.java | 10 +-------- src/sig/objects/Erinoah.java | 12 ++-------- src/sig/objects/Player.java | 10 --------- src/sig/objects/actor/PhysicsObject.java | 22 +++++++++++++++++-- .../actor/PhysicsObjectRequirements.java | 4 ++++ 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/sig/engine/objects/Object.java b/src/sig/engine/objects/Object.java index b215f9b..c7c2903 100644 --- a/src/sig/engine/objects/Object.java +++ b/src/sig/engine/objects/Object.java @@ -19,15 +19,7 @@ public abstract class Object implements GameEntity{ double x,y; Sprite spr; Panel panel; - Rectangle collisionBox; - - public Rectangle getCollisionBox() { - return collisionBox; - } - - public void setCollisionBox(Rectangle collisionBox) { - this.collisionBox = collisionBox; - } + protected Rectangle collisionBox; public Panel getPanel() { return panel; diff --git a/src/sig/objects/Erinoah.java b/src/sig/objects/Erinoah.java index 33b5861..8fd6a31 100644 --- a/src/sig/objects/Erinoah.java +++ b/src/sig/objects/Erinoah.java @@ -43,14 +43,6 @@ public class Erinoah extends PhysicsObject implements RenderedObject{ @Override public Rectangle getCollisionBounds() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void setCollisionBounds(Rectangle bounds) { - // TODO Auto-generated method stub - - } - + return new Rectangle(8,2,16,30); + } } diff --git a/src/sig/objects/Player.java b/src/sig/objects/Player.java index a42d5f5..3042730 100644 --- a/src/sig/objects/Player.java +++ b/src/sig/objects/Player.java @@ -347,16 +347,6 @@ public class Player extends PhysicsObject implements RenderedObject{ + getY() + "]"; } - @Override - public Rectangle getCollisionBounds() { - return getCollisionBox(); - } - - @Override - public void setCollisionBounds(Rectangle bounds) { - setCollisionBox(bounds); - } - @Override public Transform getSpriteTransform() { return facing_direction?Transform.HORIZONTAL:Transform.NONE; diff --git a/src/sig/objects/actor/PhysicsObject.java b/src/sig/objects/actor/PhysicsObject.java index cc2a33a..083a3b0 100644 --- a/src/sig/objects/actor/PhysicsObject.java +++ b/src/sig/objects/actor/PhysicsObject.java @@ -3,11 +3,11 @@ package sig.objects.actor; import sig.RabiClone; import sig.engine.AnimatedSprite; import sig.engine.Panel; +import sig.engine.Rectangle; import sig.engine.objects.AnimatedObject; -import sig.engine.objects.CollisionEntity; import sig.map.Tile; -public abstract class PhysicsObject extends AnimatedObject implements CollisionEntity,PhysicsObjectRequirements{ +public abstract class PhysicsObject extends AnimatedObject implements PhysicsObjectRequirements{ final public static double GRAVITY = 1300; final public static double NORMAL_FRICTION = 6400; final public static double NORMAL_JUMP_VELOCITY = -300; @@ -202,4 +202,22 @@ public abstract class PhysicsObject extends AnimatedObject implements CollisionE } } + public Rectangle getCollisionBox() { + return collisionBox; + } + + public void setCollisionBox(Rectangle collisionBox) { + this.collisionBox = collisionBox; + } + + @Override + public Rectangle getCollisionBounds() { + return getCollisionBox(); + } + + @Override + public void setCollisionBounds(Rectangle bounds) { + setCollisionBox(bounds); + } + } diff --git a/src/sig/objects/actor/PhysicsObjectRequirements.java b/src/sig/objects/actor/PhysicsObjectRequirements.java index c4b475e..3a24bca 100644 --- a/src/sig/objects/actor/PhysicsObjectRequirements.java +++ b/src/sig/objects/actor/PhysicsObjectRequirements.java @@ -1,6 +1,10 @@ package sig.objects.actor; +import sig.engine.Rectangle; + public interface PhysicsObjectRequirements { boolean rightKeyHeld(); boolean leftKeyHeld(); + Rectangle getCollisionBounds(); + void setCollisionBounds(Rectangle bounds); }