Implement easy stagger and unconscious setter functions
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
2356d42495
commit
ebbbabd7d0
@ -404,15 +404,15 @@ public class Player extends PhysicsObject{
|
|||||||
PhysicsObject pobj = (PhysicsObject)obj;
|
PhysicsObject pobj = (PhysicsObject)obj;
|
||||||
if(pobj.state!=State.STAGGER){
|
if(pobj.state!=State.STAGGER){
|
||||||
if(facing_direction){
|
if(facing_direction){
|
||||||
pobj.staggerDuration=0.3;
|
setUncontrollable(0.2);
|
||||||
|
pobj.setStagger(0.3);
|
||||||
pobj.x_velocity = -300;
|
pobj.x_velocity = -300;
|
||||||
pobj.y_velocity = -120;
|
pobj.y_velocity = -120;
|
||||||
pobj.state = State.STAGGER;
|
|
||||||
}else{
|
}else{
|
||||||
pobj.staggerDuration=0.3;
|
setUncontrollable(0.2);
|
||||||
|
pobj.setStagger(0.3);
|
||||||
pobj.x_velocity = 300;
|
pobj.x_velocity = 300;
|
||||||
pobj.y_velocity = -120;
|
pobj.y_velocity = -120;
|
||||||
pobj.state = State.STAGGER;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,9 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj
|
|||||||
|
|
||||||
public State state = State.IDLE;
|
public State state = State.IDLE;
|
||||||
public double x_velocity;
|
public double x_velocity;
|
||||||
public double staggerDuration = 0;
|
protected double staggerDuration = 0;
|
||||||
|
protected State resumeState=null;
|
||||||
|
protected double uncontrollableDuration = 0;
|
||||||
public double y_velocity;
|
public double y_velocity;
|
||||||
protected double gravity = GRAVITY;
|
protected double gravity = GRAVITY;
|
||||||
protected double x_acceleration,y_acceleration;
|
protected double x_acceleration,y_acceleration;
|
||||||
@ -43,7 +45,13 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj
|
|||||||
staggerDuration-=updateMult;
|
staggerDuration-=updateMult;
|
||||||
}else
|
}else
|
||||||
if(state==State.STAGGER && staggerDuration<=0){
|
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;
|
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) {
|
protected boolean checkCollision(double x,double y) {
|
||||||
int index = (int)y*RabiClone.BASE_WIDTH*Tile.TILE_WIDTH+(int)x;
|
int index = (int)y*RabiClone.BASE_WIDTH*Tile.TILE_WIDTH+(int)x;
|
||||||
if (index>=0&&index<RabiClone.COLLISION.length) {
|
if (index>=0&&index<RabiClone.COLLISION.length) {
|
||||||
|
@ -38,15 +38,13 @@ public class KnifeSwing extends AttachableObject{
|
|||||||
PhysicsObject pobj = (PhysicsObject)obj;
|
PhysicsObject pobj = (PhysicsObject)obj;
|
||||||
if(pobj.state!=State.STAGGER){
|
if(pobj.state!=State.STAGGER){
|
||||||
if(getSpriteTransform()==Transform.NONE){
|
if(getSpriteTransform()==Transform.NONE){
|
||||||
pobj.staggerDuration=0.3;
|
pobj.setStagger(0.3);
|
||||||
pobj.x_velocity = -500;
|
pobj.x_velocity = -500;
|
||||||
pobj.y_velocity = -300;
|
pobj.y_velocity = -300;
|
||||||
pobj.state = State.STAGGER;
|
|
||||||
}else{
|
}else{
|
||||||
pobj.staggerDuration=0.3;
|
pobj.setStagger(0.3);
|
||||||
pobj.x_velocity = 500;
|
pobj.x_velocity = 500;
|
||||||
pobj.y_velocity = -300;
|
pobj.y_velocity = -300;
|
||||||
pobj.state = State.STAGGER;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,15 +38,13 @@ public class KnifeSwing2 extends AttachableObject{
|
|||||||
PhysicsObject pobj = (PhysicsObject)obj;
|
PhysicsObject pobj = (PhysicsObject)obj;
|
||||||
if(pobj.state!=State.STAGGER){
|
if(pobj.state!=State.STAGGER){
|
||||||
if(getSpriteTransform()==Transform.NONE){
|
if(getSpriteTransform()==Transform.NONE){
|
||||||
pobj.staggerDuration=0.3;
|
pobj.setStagger(0.3);
|
||||||
pobj.x_velocity = -500;
|
pobj.x_velocity = -500;
|
||||||
pobj.y_velocity = -300;
|
pobj.y_velocity = -300;
|
||||||
pobj.state = State.STAGGER;
|
|
||||||
}else{
|
}else{
|
||||||
pobj.staggerDuration=0.3;
|
pobj.setStagger(0.3);
|
||||||
pobj.x_velocity = 500;
|
pobj.x_velocity = 500;
|
||||||
pobj.y_velocity = -300;
|
pobj.y_velocity = -300;
|
||||||
pobj.state = State.STAGGER;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user