From d05007ad6b5e6db9ca3c96e742d7af338a913be8 Mon Sep 17 00:00:00 2001 From: unknown <45179536+r3cp3ct@users.noreply.github.com> Date: Sat, 18 Jun 2022 11:00:57 +0300 Subject: [PATCH] Bonk the buns now Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 --- maps/world1.map | Bin 299012 -> 299164 bytes src/sig/objects/Erinoah.java | 5 ++-- src/sig/objects/Player.java | 3 +- src/sig/objects/actor/PhysicsObject.java | 27 ++++++++++++++---- .../actor/PhysicsObjectRequirements.java | 1 + src/sig/objects/weapons/KnifeSwing.java | 24 ++++++++++++++++ 6 files changed, 52 insertions(+), 8 deletions(-) diff --git a/maps/world1.map b/maps/world1.map index ccabfa51df53fbcba08a683ab3479f0dc66700be..80ee1a4b94446007c2176a52695b49806b74e54a 100644 GIT binary patch delta 285 zcmXZTF-ikb5Qp)Y9fr8BiFw&(BH{%M zTX>V4!z1_=7C#t<|M#|WAD`~Kn^a!x%xCpTcF|YsPfM8;{V;Ua240jli!}*&C*pU-$S{FCZeBE z%6hRpZ%8x70TLXdjSh~`g+mW1`p7V7i0p$-XoN;+ghptDMredaXoN;+l&!K=w#xQI P87pIDtc;bhGSD+bb=weaponSwingAnimationTime)) { - RabiClone.OBJ.add(new KnifeSwing(Sprite.KNIFE_SWING,15,RabiClone.p,this)); + RabiClone.OBJ.add(new KnifeSwing(Sprite.KNIFE_SWING,40,RabiClone.p,this)); state=State.ATTACK; weaponSwingTime=RabiClone.TIME; } diff --git a/src/sig/objects/actor/PhysicsObject.java b/src/sig/objects/actor/PhysicsObject.java index 24de1f1..4f50cc3 100644 --- a/src/sig/objects/actor/PhysicsObject.java +++ b/src/sig/objects/actor/PhysicsObject.java @@ -14,8 +14,11 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj final public static double NORMAL_JUMP_VELOCITY = -300; final public static double WALKING_SPEED_LIMIT = 164; - protected State state = State.IDLE; - protected double x_velocity,y_velocity; + public State state = State.IDLE; + public double x_velocity; + public double staggerDuration = 0; + public double y_velocity; + protected double gravity = GRAVITY; protected double x_acceleration,y_acceleration; protected double x_velocity_limit,y_velocity_limit; protected double x_acceleration_limit,y_acceleration_limit; @@ -36,6 +39,12 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj public void update(double updateMult) { super.update(updateMult); handleMovementPhysics(updateMult); + if(state==State.STAGGER && staggerDuration>0){ + staggerDuration-=updateMult; + }else + if(state==State.STAGGER && staggerDuration<=0){ + state=State.IDLE; + } } protected void handleMovementPhysics(double updateMult) { @@ -110,13 +119,13 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj } } } - + sideCollision = sideCollisionChecking(displacement_x, sideCollision, hitAbove, startingX); if (!groundCollision){ this.setY(this.getY()+displacement_y); - y_acceleration = GRAVITY; + y_acceleration = gravity; if(y_velocity>0 && state!=State.SLIDE){ state = State.FALLING; } @@ -282,5 +291,13 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj public void setJumpVelocity(double x) { this.jump_velocity=x; } - + + @Override + public void setGravity(double gravity) { + this.gravity = gravity; + } + + public double getGravity() { + return gravity; + } } diff --git a/src/sig/objects/actor/PhysicsObjectRequirements.java b/src/sig/objects/actor/PhysicsObjectRequirements.java index a4482d3..5a20a5b 100644 --- a/src/sig/objects/actor/PhysicsObjectRequirements.java +++ b/src/sig/objects/actor/PhysicsObjectRequirements.java @@ -17,4 +17,5 @@ public interface PhysicsObjectRequirements { void setSlidingVelocity(double x); void setSlidingAcceleration(double x); void setJumpVelocity(double x); + void setGravity(double gravity); } diff --git a/src/sig/objects/weapons/KnifeSwing.java b/src/sig/objects/weapons/KnifeSwing.java index 8ec5052..bb34b78 100644 --- a/src/sig/objects/weapons/KnifeSwing.java +++ b/src/sig/objects/weapons/KnifeSwing.java @@ -4,6 +4,9 @@ import sig.engine.AnimatedSprite; import sig.engine.Panel; import sig.engine.Transform; import sig.objects.actor.AttachableObject; +import sig.objects.actor.PhysicsObject; +import sig.objects.actor.State; +import sig.engine.objects.AnimatedObject; import sig.engine.objects.Object; public class KnifeSwing extends AttachableObject{ @@ -29,6 +32,27 @@ public class KnifeSwing extends AttachableObject{ setY(getAttachedObject().getY()); } + @Override + public void collisionEvent(AnimatedObject obj) { + System.out.println("Bonk"); + if(obj instanceof PhysicsObject){ + PhysicsObject pobj = (PhysicsObject)obj; + if(pobj.state!=State.STAGGER){ + if(getSpriteTransform()==Transform.NONE){ + pobj.staggerDuration=0.3; + pobj.x_velocity = -300; + pobj.y_velocity = -300; + pobj.state = State.STAGGER; + }else{ + pobj.staggerDuration=0.3; + pobj.x_velocity = 300; + pobj.y_velocity = -300; + pobj.state = State.STAGGER; + } + } + } + } + @Override public void draw(byte[] p) { }