From ebbbabd7d06737345795af25ab058d10f7e26ca5 Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Tue, 21 Jun 2022 20:09:05 +0000 Subject: [PATCH] Implement easy stagger and unconscious setter functions Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 --- src/sig/objects/Player.java | 8 +++--- src/sig/objects/actor/PhysicsObject.java | 36 ++++++++++++++++++++++-- src/sig/objects/weapons/KnifeSwing.java | 6 ++-- src/sig/objects/weapons/KnifeSwing2.java | 6 ++-- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/sig/objects/Player.java b/src/sig/objects/Player.java index 8ca4152..910ef7b 100644 --- a/src/sig/objects/Player.java +++ b/src/sig/objects/Player.java @@ -404,15 +404,15 @@ public class Player extends PhysicsObject{ PhysicsObject pobj = (PhysicsObject)obj; if(pobj.state!=State.STAGGER){ if(facing_direction){ - pobj.staggerDuration=0.3; + setUncontrollable(0.2); + pobj.setStagger(0.3); pobj.x_velocity = -300; pobj.y_velocity = -120; - pobj.state = State.STAGGER; }else{ - pobj.staggerDuration=0.3; + setUncontrollable(0.2); + pobj.setStagger(0.3); pobj.x_velocity = 300; pobj.y_velocity = -120; - pobj.state = State.STAGGER; } } } diff --git a/src/sig/objects/actor/PhysicsObject.java b/src/sig/objects/actor/PhysicsObject.java index 364a141..1063a90 100644 --- a/src/sig/objects/actor/PhysicsObject.java +++ b/src/sig/objects/actor/PhysicsObject.java @@ -16,7 +16,9 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj public State state = State.IDLE; public double x_velocity; - public double staggerDuration = 0; + protected double staggerDuration = 0; + protected State resumeState=null; + protected double uncontrollableDuration = 0; public double y_velocity; protected double gravity = GRAVITY; protected double x_acceleration,y_acceleration; @@ -43,7 +45,13 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj staggerDuration-=updateMult; }else if(state==State.STAGGER && staggerDuration<=0){ - state=State.IDLE; + state=resumeState; + } + if(state==State.UNCONTROLLABLE && uncontrollableDuration>0){ + uncontrollableDuration-=updateMult; + }else + if(state==State.UNCONTROLLABLE && uncontrollableDuration<=0){ + state=resumeState; } } @@ -204,6 +212,30 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj return sideCollision; } + /** + * Sets how long this object will remain in the stagger state. + * Automatically resets the state to the previous state the object + * was in when the stagger state completes. + * @param duration Amount of time in seconds. + * */ + public void setStagger(double duration) { + staggerDuration=duration; + resumeState=state; + state=State.STAGGER; + } + + /** + * Sets how long this object will remain in the unconscious state. + * Automatically resets the state to the previous state the object + * was in when the unconscious state completes. + * @param duration Amount of time in seconds. + * */ + public void setUncontrollable(double duration) { + uncontrollableDuration=duration; + resumeState=state; + state=State.UNCONTROLLABLE; + } + protected boolean checkCollision(double x,double y) { int index = (int)y*RabiClone.BASE_WIDTH*Tile.TILE_WIDTH+(int)x; if (index>=0&&index