Physics updates and prepare new moveset setups

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent e589a8585e
commit ec3ff72934
  1. 2
      README.md
  2. 7
      src/sig/objects/ConfigureControls.java
  3. 60
      src/sig/objects/Player.java
  4. 38
      src/sig/objects/actor/PhysicsObject.java
  5. 2
      src/sig/objects/weapons/KnifeSwing.java
  6. 2
      src/sig/objects/weapons/KnifeSwing2.java

@ -37,6 +37,8 @@ Underwater / Water Dashing (Propelling motion)
Side Roll -> Slide Side Roll -> Slide
Wall Jumping Wall Jumping
Controller Deadzones..
Movement Systems Movement Systems
Collectibles Collectibles
Combat Systems Combat Systems

@ -56,7 +56,6 @@ public class ConfigureControls extends Object{
while (stream.available()>0) { while (stream.available()>0) {
Action a = Action.valueOf(readString(stream)); Action a = Action.valueOf(readString(stream));
byte port = stream.readByte(); byte port = stream.readByte();
System.out.println("PI:"+port);
do { do {
if (port==(byte)-1) { if (port==(byte)-1) {
int keycode = stream.readInt(); int keycode = stream.readInt();
@ -64,7 +63,6 @@ public class ConfigureControls extends Object{
appendToKeybind(a,kb); appendToKeybind(a,kb);
} else { } else {
java.lang.String controllerName = readString(stream); java.lang.String controllerName = readString(stream);
System.out.println("CONT:"+controllerName);
Controller controller=null; Controller controller=null;
for (int i = 0; i < RabiClone.CONTROLLERS.length; i++) { for (int i = 0; i < RabiClone.CONTROLLERS.length; i++) {
if (RabiClone.CONTROLLERS[i].getType() == Controller.Type.KEYBOARD if (RabiClone.CONTROLLERS[i].getType() == Controller.Type.KEYBOARD
@ -77,12 +75,10 @@ public class ConfigureControls extends Object{
} }
if (controller==null) { if (controller==null) {
//Discard these bits of data as we didn't find a controller. //Discard these bits of data as we didn't find a controller.
java.lang.String comName = readString(stream); readString(stream);
System.out.println("NULL:"+comName);
stream.readFloat(); stream.readFloat();
} else { } else {
java.lang.String componentName = readString(stream); java.lang.String componentName = readString(stream);
System.out.println("COM:"+componentName);
Component c=null; Component c=null;
for (Component cc : controller.getComponents()) { for (Component cc : controller.getComponents()) {
if (cc.getName().equals(componentName)) { if (cc.getName().equals(componentName)) {
@ -100,7 +96,6 @@ public class ConfigureControls extends Object{
} }
} }
port = stream.readByte(); port = stream.readByte();
System.out.println("P:"+port);
} while (port!=(byte)-2); } while (port!=(byte)-2);
} }
updateHighlightSections(); updateHighlightSections();

@ -1,5 +1,8 @@
package sig.objects; package sig.objects;
import java.util.ArrayList;
import java.util.List;
import sig.RabiClone; import sig.RabiClone;
import sig.engine.Action; import sig.engine.Action;
import sig.engine.Panel; import sig.engine.Panel;
@ -21,12 +24,14 @@ public class Player extends PhysicsObject{
final static long jump_fall_AnimationWaitTime = TimeUtils.millisToNanos(200); final static long jump_fall_AnimationWaitTime = TimeUtils.millisToNanos(200);
final static long slide_AnimationWaitTime = TimeUtils.millisToNanos(100); final static long slide_AnimationWaitTime = TimeUtils.millisToNanos(100);
final static long slide_duration = TimeUtils.millisToNanos(700); final static long slide_duration = TimeUtils.millisToNanos(700);
final static long bellySlideDuration = TimeUtils.millisToNanos(1000); final static long bellySlideDuration = TimeUtils.millisToNanos(400);
final static long weaponSwingAnimationTime = TimeUtils.millisToNanos(333); final static long weaponSwingAnimationTime = TimeUtils.millisToNanos(333);
final static long weaponComboWaitTime = TimeUtils.millisToNanos(60); final static long weaponComboWaitTime = TimeUtils.millisToNanos(60);
final static double finalComboJumpBackSpeedX = -185; final static double finalComboJumpBackSpeedX = -185;
final static double finalComboJumpBackSpeedY = -110; final static double finalComboJumpBackSpeedY = -110;
List<PhysicsObject> collisionBatch = new ArrayList<PhysicsObject>();
long weaponSwingTime = 0; long weaponSwingTime = 0;
State prvState = state; State prvState = state;
@ -37,6 +42,7 @@ public class Player extends PhysicsObject{
boolean spacebarReleased = true; boolean spacebarReleased = true;
boolean facing_direction = RIGHT; boolean facing_direction = RIGHT;
boolean landedBellySlide=false;
long spacebarPressed = RabiClone.TIME; long spacebarPressed = RabiClone.TIME;
long jump_slide_fall_StartAnimationTimer = -1; long jump_slide_fall_StartAnimationTimer = -1;
@ -74,6 +80,7 @@ public class Player extends PhysicsObject{
public void update(double updateMult) { public void update(double updateMult) {
super.update(updateMult); super.update(updateMult);
handleCameraRoomMovement(); handleCameraRoomMovement();
handleCollisionBatch();
switch (state) { switch (state) {
case ATTACK: case ATTACK:
@ -163,6 +170,14 @@ public class Player extends PhysicsObject{
} }
break; break;
case BELLYSLIDE:{ case BELLYSLIDE:{
horizontal_friction = 0;
if (y_velocity>0) {
bellySlideTime=RabiClone.TIME;
}
if (groundCollision&&!landedBellySlide){
landedBellySlide=true;
x_velocity = sliding_velocity*(facing_direction?1:-1);
}
if (RabiClone.TIME - bellySlideTime > bellySlideDuration) { if (RabiClone.TIME - bellySlideTime > bellySlideDuration) {
if (KeyHeld(Action.MOVE_LEFT)) { if (KeyHeld(Action.MOVE_LEFT)) {
facing_direction = LEFT; facing_direction = LEFT;
@ -193,12 +208,36 @@ public class Player extends PhysicsObject{
} }
prvState = state; prvState = state;
if (KeyHeld(Action.JUMP) && RabiClone.TIME - spacebarPressed < jumpHoldTime if (KeyHeld(Action.JUMP) && RabiClone.TIME - spacebarPressed < jumpHoldTime
&& state!=State.ATTACK2&&state!=State.ATTACK3) { && state!=State.ATTACK2&&state!=State.ATTACK3&&state!=State.BELLYSLIDE) {
y_velocity = jump_velocity; y_velocity = jump_velocity;
} }
// System.out.println(state); // System.out.println(state);
} }
private void handleCollisionBatch() {
for (int p=0;p<collisionBatch.size();p++) {
PhysicsObject pobj = collisionBatch.get(p);
if(facing_direction){
if (state!=State.UNCONTROLLABLE) {
setUncontrollable(0.2);
}
pobj.setStagger(0.3);
pobj.setInvulnerability(1);
pobj.x_velocity = -300;
pobj.y_velocity = -120;
}else{
if (state!=State.UNCONTROLLABLE) {
setUncontrollable(0.2);
}
pobj.setStagger(0.3);
pobj.setInvulnerability(1);
pobj.x_velocity = 300;
pobj.y_velocity = -120;
}
}
collisionBatch.clear();
}
@Override @Override
public void KeyReleased(Action a) { public void KeyReleased(Action a) {
if (a == Action.JUMP) { if (a == Action.JUMP) {
@ -269,6 +308,9 @@ public class Player extends PhysicsObject{
state=State.BELLYSLIDE; state=State.BELLYSLIDE;
y_velocity=y_velocity_limit; y_velocity=y_velocity_limit;
x_velocity=60*(facing_direction?1:-1); x_velocity=60*(facing_direction?1:-1);
bellySlideTime=RabiClone.TIME;
landedBellySlide=false;
spacebarPressed = 0;
} else } else
if (a == Action.ATTACK&&(state==State.IDLE||state==State.FALLING||state==State.JUMP)&&(RabiClone.TIME-weaponSwingTime>=weaponSwingAnimationTime)) { if (a == Action.ATTACK&&(state==State.IDLE||state==State.FALLING||state==State.JUMP)&&(RabiClone.TIME-weaponSwingTime>=weaponSwingAnimationTime)) {
RabiClone.OBJ.add(new KnifeSwing(Sprite.KNIFE_SWING,40,RabiClone.p,this)); RabiClone.OBJ.add(new KnifeSwing(Sprite.KNIFE_SWING,40,RabiClone.p,this));
@ -402,18 +444,8 @@ public class Player extends PhysicsObject{
if (state==State.BELLYSLIDE) { if (state==State.BELLYSLIDE) {
if(obj instanceof PhysicsObject){ if(obj instanceof PhysicsObject){
PhysicsObject pobj = (PhysicsObject)obj; PhysicsObject pobj = (PhysicsObject)obj;
if(pobj.state!=State.STAGGER){ if(!pobj.isInvulnerable()){
if(facing_direction){ collisionBatch.add(pobj);
setUncontrollable(0.2);
pobj.setStagger(0.3);
pobj.x_velocity = -300;
pobj.y_velocity = -120;
}else{
setUncontrollable(0.2);
pobj.setStagger(0.3);
pobj.x_velocity = 300;
pobj.y_velocity = -120;
}
} }
} }
} }

@ -19,6 +19,7 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj
protected double staggerDuration = 0; protected double staggerDuration = 0;
protected State resumeState=null; protected State resumeState=null;
protected double uncontrollableDuration = 0; protected double uncontrollableDuration = 0;
protected double invulnerabilityDuration = 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;
@ -53,6 +54,9 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj
if(state==State.UNCONTROLLABLE && uncontrollableDuration<=0){ if(state==State.UNCONTROLLABLE && uncontrollableDuration<=0){
state=resumeState; state=resumeState;
} }
if (invulnerabilityDuration>0) {
invulnerabilityDuration-=updateMult;
}
} }
protected void handleMovementPhysics(double updateMult) { protected void handleMovementPhysics(double updateMult) {
@ -61,7 +65,7 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj
} }
int right = rightKeyHeld()?1:0; int right = rightKeyHeld()?1:0;
int left = leftKeyHeld()?1:0; int left = leftKeyHeld()?1:0;
if(state==State.SLIDE){ if(state==State.SLIDE||state==State.BELLYSLIDE){
right=0; right=0;
left=0; left=0;
} }
@ -69,12 +73,10 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj
Math.abs(x_velocity+x_acceleration*updateMult)>x_velocity_limit Math.abs(x_velocity+x_acceleration*updateMult)>x_velocity_limit
?Math.signum(x_velocity+x_acceleration*updateMult)*x_velocity_limit ?Math.signum(x_velocity+x_acceleration*updateMult)*x_velocity_limit
:x_velocity+x_acceleration*updateMult; :x_velocity+x_acceleration*updateMult;
if (state!=State.BELLYSLIDE) { y_velocity =
y_velocity = Math.abs(y_velocity+y_acceleration*updateMult)>y_velocity_limit
Math.abs(y_velocity+y_acceleration*updateMult)>y_velocity_limit ?Math.signum(y_velocity+y_acceleration*updateMult)*y_velocity_limit
?Math.signum(y_velocity+y_acceleration*updateMult)*y_velocity_limit :y_velocity+y_acceleration*updateMult;
:y_velocity+y_acceleration*updateMult;
}
double displacement_y = y_velocity*updateMult; double displacement_y = y_velocity*updateMult;
double displacement_x = x_velocity*updateMult; double displacement_x = x_velocity*updateMult;
@ -107,7 +109,7 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj
y_acceleration = 0; y_acceleration = 0;
y_velocity = 0; y_velocity = 0;
groundCollision = true; groundCollision = true;
if (state != State.SLIDE) { if (state != State.SLIDE&&state!=State.BELLYSLIDE) {
state = State.IDLE; state = State.IDLE;
} }
break; break;
@ -212,6 +214,18 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj
return sideCollision; return sideCollision;
} }
/**
* How long to set invincibility for this object.
* @param duration Amount of time in seconds.
*/
public void setInvulnerability(double duration) {
this.invulnerabilityDuration = duration;
}
public boolean isInvulnerable() {
return this.invulnerabilityDuration>0;
}
/** /**
* Sets how long this object will remain in the stagger state. * Sets how long this object will remain in the stagger state.
* Automatically resets the state to the previous state the object * Automatically resets the state to the previous state the object
@ -220,7 +234,9 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj
* */ * */
public void setStagger(double duration) { public void setStagger(double duration) {
staggerDuration=duration; staggerDuration=duration;
resumeState=state; if (state!=State.STAGGER) {
resumeState=state;
}
state=State.STAGGER; state=State.STAGGER;
} }
@ -232,7 +248,9 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj
* */ * */
public void setUncontrollable(double duration) { public void setUncontrollable(double duration) {
uncontrollableDuration=duration; uncontrollableDuration=duration;
resumeState=state; if (state!=State.UNCONTROLLABLE) {
resumeState=state;
}
state=State.UNCONTROLLABLE; state=State.UNCONTROLLABLE;
} }

@ -36,7 +36,7 @@ public class KnifeSwing extends AttachableObject{
public void collisionEvent(AnimatedObject obj) { public void collisionEvent(AnimatedObject obj) {
if(obj instanceof PhysicsObject){ if(obj instanceof PhysicsObject){
PhysicsObject pobj = (PhysicsObject)obj; PhysicsObject pobj = (PhysicsObject)obj;
if(pobj.state!=State.STAGGER){ if(!pobj.isInvulnerable()){
if(getSpriteTransform()==Transform.NONE){ if(getSpriteTransform()==Transform.NONE){
pobj.setStagger(0.3); pobj.setStagger(0.3);
pobj.x_velocity = -500; pobj.x_velocity = -500;

@ -36,7 +36,7 @@ public class KnifeSwing2 extends AttachableObject{
public void collisionEvent(AnimatedObject obj) { public void collisionEvent(AnimatedObject obj) {
if(obj instanceof PhysicsObject){ if(obj instanceof PhysicsObject){
PhysicsObject pobj = (PhysicsObject)obj; PhysicsObject pobj = (PhysicsObject)obj;
if(pobj.state!=State.STAGGER){ if(!pobj.isInvulnerable()){
if(getSpriteTransform()==Transform.NONE){ if(getSpriteTransform()==Transform.NONE){
pobj.setStagger(0.3); pobj.setStagger(0.3);
pobj.x_velocity = -500; pobj.x_velocity = -500;

Loading…
Cancel
Save