diff --git a/README.md b/README.md index ce1fa28..09eccf7 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,8 @@ Underwater / Water Dashing (Propelling motion) Side Roll -> Slide Wall Jumping +Controller Deadzones.. + Movement Systems Collectibles Combat Systems diff --git a/RabiClone_0.0a.zip b/RabiClone_0.0a.zip index 1383cc9..ce57fc9 100644 Binary files a/RabiClone_0.0a.zip and b/RabiClone_0.0a.zip differ diff --git a/bin/RabiClone.jar b/bin/RabiClone.jar deleted file mode 100644 index 292e156..0000000 Binary files a/bin/RabiClone.jar and /dev/null differ diff --git a/bin/controls.config b/bin/controls.config new file mode 100644 index 0000000..eb3def4 Binary files /dev/null and b/bin/controls.config differ diff --git a/src/sig/RabiClone.java b/src/sig/RabiClone.java index a9c093b..a1fe908 100644 --- a/src/sig/RabiClone.java +++ b/src/sig/RabiClone.java @@ -140,6 +140,7 @@ public class RabiClone implements ControllerListener{ long dt = 0; CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().getControllers(); + ConfigureControls.LoadControls(); while (true) { dt += System.nanoTime() - lastGameTime; @@ -268,6 +269,18 @@ public class RabiClone implements ControllerListener{ continue; } if (!CONTROLLERS[i].poll()) { + if (control_settings_menu!=null) { + for (Action a : Action.values()) { + List binds = KeyBind.KEYBINDS.get(a); + for (int j=0;j=RabiClone.CONTROLLERS[port].getComponent(id).getDeadZone()&&Math.signum(RabiClone.CONTROLLERS[port].getComponent(id).getPollData())==Math.signum(val); } else { - throw new UnsupportedOperationException("Could not find proper recognition for component "+id.getName()); + return false; + //throw new UnsupportedOperationException("Could not find proper recognition for component "+id.getName()); } } diff --git a/src/sig/objects/ConfigureControls.java b/src/sig/objects/ConfigureControls.java index b176325..bfed807 100644 --- a/src/sig/objects/ConfigureControls.java +++ b/src/sig/objects/ConfigureControls.java @@ -77,7 +77,6 @@ public class ConfigureControls extends Object{ //Discard these bits of data as we didn't find a controller. readString(stream); stream.readFloat(); - continue; } else { java.lang.String componentName = readString(stream); Component c=null; @@ -97,7 +96,7 @@ public class ConfigureControls extends Object{ } } port = stream.readByte(); - } while (port!='\0'); + } while (port!=(byte)-2); } updateHighlightSections(); } catch (IOException e) { @@ -130,16 +129,18 @@ public class ConfigureControls extends Object{ for (Action a : Action.values()) { writeString(a.name(),stream); for (KeyBind k : KeyBind.KEYBINDS.get(a)) { - stream.writeByte(k.port); - if (k.port==(byte)-1) { - stream.writeInt(((Key)k.id).getKeyCode()); - } else { - writeString(RabiClone.CONTROLLERS[k.port].getName(),stream); - writeString(RabiClone.CONTROLLERS[k.port].getComponent(k.id).getName(),stream); - stream.writeFloat(k.getVal()); + if (k.port==-1||k.port()); diff --git a/src/sig/objects/LevelRenderer.java b/src/sig/objects/LevelRenderer.java index f4338ef..457596d 100644 --- a/src/sig/objects/LevelRenderer.java +++ b/src/sig/objects/LevelRenderer.java @@ -18,10 +18,18 @@ import sig.map.Background; import sig.map.DataTile; import sig.map.Map; import sig.map.Tile; +import sig.objects.actor.PhysicsObject; import sig.objects.actor.RenderedObject; +import sig.objects.actor.State; +import sig.utils.TimeUtils; public class LevelRenderer extends Object{ + final static long staggerJitterWaitTime=TimeUtils.millisToNanos(200); + + long staggerTimer=0; + int staggerOffsetX=2; + public LevelRenderer(Panel panel) { super(panel); this.setSprite(Sprite.TILE_SHEET); @@ -44,6 +52,9 @@ public class LevelRenderer extends Object{ } } } + if (RabiClone.TIME-staggerTimer>staggerJitterWaitTime) { + staggerOffsetX*=-1; + } } @Override @@ -138,7 +149,12 @@ public class LevelRenderer extends Object{ } protected void Draw_Animated_Object(AnimatedObject object, Transform transform){ - super.Draw_Animated_Sprite(object.getX()-this.getX()-object.getAnimatedSpr().getWidth()/2, Math.round(object.getY()-this.getY()-object.getAnimatedSpr().getHeight()/2), object.getAnimatedSpr(), object.getCurrentFrame(), transform); + if (object instanceof PhysicsObject) { + PhysicsObject po = (PhysicsObject)object; + super.Draw_Animated_Sprite(object.getX()-this.getX()-object.getAnimatedSpr().getWidth()/2+(po.state==State.STAGGER?staggerOffsetX:0), Math.round(object.getY()-this.getY()-object.getAnimatedSpr().getHeight()/2), object.getAnimatedSpr(), object.getCurrentFrame(), transform); + } else { + super.Draw_Animated_Sprite(object.getX()-this.getX()-object.getAnimatedSpr().getWidth()/2, Math.round(object.getY()-this.getY()-object.getAnimatedSpr().getHeight()/2), object.getAnimatedSpr(), object.getCurrentFrame(), transform); + } } private void DrawTile(double x, double y, Tile tile) { diff --git a/src/sig/objects/Player.java b/src/sig/objects/Player.java index a11a94c..47f3621 100644 --- a/src/sig/objects/Player.java +++ b/src/sig/objects/Player.java @@ -1,11 +1,15 @@ package sig.objects; +import java.util.ArrayList; +import java.util.List; + import sig.RabiClone; import sig.engine.Action; import sig.engine.Panel; import sig.engine.Rectangle; import sig.engine.Sprite; import sig.engine.Transform; +import sig.engine.objects.AnimatedObject; import sig.map.Map; import sig.map.Tile; import sig.map.View; @@ -20,7 +24,13 @@ public class Player extends PhysicsObject{ final static long jump_fall_AnimationWaitTime = TimeUtils.millisToNanos(200); final static long slide_AnimationWaitTime = TimeUtils.millisToNanos(100); final static long slide_duration = TimeUtils.millisToNanos(700); + final static long bellySlideDuration = TimeUtils.millisToNanos(400); final static long weaponSwingAnimationTime = TimeUtils.millisToNanos(333); + final static long weaponComboWaitTime = TimeUtils.millisToNanos(60); + final static double finalComboJumpBackSpeedX = -185; + final static double finalComboJumpBackSpeedY = -110; + + List collisionBatch = new ArrayList(); long weaponSwingTime = 0; @@ -32,11 +42,13 @@ public class Player extends PhysicsObject{ boolean spacebarReleased = true; boolean facing_direction = RIGHT; + boolean landedBellySlide=false; long spacebarPressed = RabiClone.TIME; long jump_slide_fall_StartAnimationTimer = -1; long slide_time = -1; long jumpHoldTime = TimeUtils.millisToNanos(150); + long bellySlideTime = -1; final static long slideBufferTime = TimeUtils.millisToNanos(200); long slidePressed = -1; @@ -68,6 +80,7 @@ public class Player extends PhysicsObject{ public void update(double updateMult) { super.update(updateMult); handleCameraRoomMovement(); + handleCollisionBatch(); switch (state) { case ATTACK: @@ -75,6 +88,16 @@ public class Player extends PhysicsObject{ state=State.IDLE; } break; + case ATTACK2: + if (RabiClone.TIME - weaponSwingTime > weaponSwingAnimationTime) { + state=State.IDLE; + } + break; + case ATTACK3: + if (RabiClone.TIME - weaponSwingTime > weaponSwingAnimationTime) { + state=State.IDLE; + } + break; case FALLING: if (prvState != State.FALLING) { jump_slide_fall_StartAnimationTimer = RabiClone.TIME; @@ -87,7 +110,7 @@ public class Player extends PhysicsObject{ } break; case IDLE: - if (RabiClone.TIME - slidePressed <= slideBufferTime) { + if (RabiClone.TIME - slidePressed <= slideBufferTime && state!=State.BELLYSLIDE) { performSlide(); break; } @@ -108,9 +131,6 @@ public class Player extends PhysicsObject{ } break; case JUMP: - if (prvState == State.SLIDE) { - // jump_velocity=-500; - } if (jump_slide_fall_StartAnimationTimer == -1) { jump_slide_fall_StartAnimationTimer = RabiClone.TIME; setAnimatedSpr(Sprite.ERINA_JUMP_RISE1); @@ -149,6 +169,36 @@ public class Player extends PhysicsObject{ } } break; + 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 (KeyHeld(Action.MOVE_LEFT)) { + facing_direction = LEFT; + } + if (KeyHeld(Action.MOVE_RIGHT)) { + facing_direction = RIGHT; + } + state = State.IDLE; + } + if (KeyHeld(Action.MOVE_LEFT) && !KeyHeld(Action.MOVE_RIGHT)) { + if (facing_direction == LEFT && x_velocity > -sliding_velocity * 1.5 || + facing_direction == RIGHT && x_velocity > sliding_velocity * 0.5) { + x_velocity -= sliding_acceleration * updateMult; + } + } else if (KeyHeld(Action.MOVE_RIGHT) && !KeyHeld(Action.MOVE_LEFT)) { + if (facing_direction == LEFT && x_velocity < -sliding_velocity * 0.5 || + facing_direction == RIGHT && x_velocity < sliding_velocity * 1.5) { + x_velocity += sliding_acceleration * updateMult; + } + } + }break; case STAGGER: break; case UNCONTROLLABLE: @@ -157,19 +207,44 @@ public class Player extends PhysicsObject{ break; } 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.BELLYSLIDE) { y_velocity = jump_velocity; } // System.out.println(state); } + private void handleCollisionBatch() { + for (int p=0;pweaponComboWaitTime) { + state=State.ATTACK2; + weaponSwingTime=RabiClone.TIME; + } + break; + case ATTACK2: + if (a==Action.ATTACK&&RabiClone.TIME-weaponSwingTime>weaponComboWaitTime) { + state=State.ATTACK3; + weaponSwingTime=RabiClone.TIME; + } + break; + case ATTACK3: + if (a==Action.ATTACK&&RabiClone.TIME-weaponSwingTime>weaponComboWaitTime) { + state=State.ATTACK4; + weaponSwingTime=RabiClone.TIME; + y_velocity = finalComboJumpBackSpeedY; + x_velocity = finalComboJumpBackSpeedX*(facing_direction?1:-1); + } break; case IDLE: if (a == Action.SLIDE || a == Action.FALL) { @@ -211,13 +304,22 @@ public class Player extends PhysicsObject{ default: break; } + if (a==Action.FALL&&(state==State.JUMP||state==State.FALLING)) { + state=State.BELLYSLIDE; + y_velocity=y_velocity_limit; + x_velocity=60*(facing_direction?1:-1); + bellySlideTime=RabiClone.TIME; + landedBellySlide=false; + spacebarPressed = 0; + } else 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)); state=State.ATTACK; weaponSwingTime=RabiClone.TIME; } if (groundCollision) { - if (spacebarReleased && (a == Action.JUMP) && jumpCount > 0) { + if (spacebarReleased && (a == Action.JUMP) && jumpCount > 0 + &&state!=State.ATTACK2&&state!=State.ATTACK3) { state = State.JUMP; jumpCount--; y_velocity = jump_velocity; @@ -226,7 +328,7 @@ public class Player extends PhysicsObject{ // System.out.println("Jump"); } } - if (state != State.SLIDE) { + if (state != State.SLIDE&&state!=State.BELLYSLIDE) { switch (a) { case MOVE_LEFT: facing_direction = LEFT; @@ -337,6 +439,18 @@ public class Player extends PhysicsObject{ RabiClone.level_renderer.setY(newY < 0 ? 0 : newY); } + @Override + public void collisionEvent(AnimatedObject obj) { + if (state==State.BELLYSLIDE) { + if(obj instanceof PhysicsObject){ + PhysicsObject pobj = (PhysicsObject)obj; + if(!pobj.isInvulnerable()){ + collisionBatch.add(pobj); + } + } + } + } + @Override public void draw(byte[] p) { } @@ -356,12 +470,12 @@ public class Player extends PhysicsObject{ @Override public boolean rightKeyHeld() { - return KeyHeld(Action.MOVE_RIGHT); + return state!=State.ATTACK2&&state!=State.ATTACK3&&KeyHeld(Action.MOVE_RIGHT); } @Override public boolean leftKeyHeld() { - return KeyHeld(Action.MOVE_LEFT); + return state!=State.ATTACK2&&state!=State.ATTACK3&&KeyHeld(Action.MOVE_LEFT); } public double getYVelocity() { diff --git a/src/sig/objects/actor/PhysicsObject.java b/src/sig/objects/actor/PhysicsObject.java index 140d7bc..d750bd7 100644 --- a/src/sig/objects/actor/PhysicsObject.java +++ b/src/sig/objects/actor/PhysicsObject.java @@ -12,10 +12,14 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj final public static double NORMAL_FRICTION = 6400; final public static double NORMAL_JUMP_VELOCITY = -300; final public static double WALKING_SPEED_LIMIT = 164; + final public static double FALLING_SPEED_LIMIT = 500; 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; + protected double invulnerabilityDuration = 0; public double y_velocity; protected double gravity = GRAVITY; protected double x_acceleration,y_acceleration; @@ -42,14 +46,26 @@ 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; + } + if (invulnerabilityDuration>0) { + invulnerabilityDuration-=updateMult; } } protected void handleMovementPhysics(double updateMult) { + if (state==State.STAGGER||state==State.UNCONTROLLABLE) { + return; + } int right = rightKeyHeld()?1:0; int left = leftKeyHeld()?1:0; - if(state==State.SLIDE){ + if(state==State.SLIDE||state==State.BELLYSLIDE){ right=0; left=0; } @@ -93,7 +109,7 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj y_acceleration = 0; y_velocity = 0; groundCollision = true; - if (state != State.SLIDE) { + if (state != State.SLIDE&&state!=State.BELLYSLIDE) { state = State.IDLE; } break; @@ -125,7 +141,7 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj if (!groundCollision){ this.setY(this.getY()+displacement_y); y_acceleration = gravity; - if(y_velocity>0 && state!=State.SLIDE){ + if(y_velocity>0 && state!=State.SLIDE&&state!=State.BELLYSLIDE){ state = State.FALLING; } if (!sideCollision) { @@ -198,6 +214,46 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj 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. + * 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; + if (state!=State.STAGGER) { + resumeState=state; + } + state=State.STAGGER; + } + + /** + * Sets how long this object will remain in the uncontrollable state. + * Automatically resets the state to the previous state the object + * was in when the uncontrollable state completes. + * @param duration Amount of time in seconds. + * */ + public void setUncontrollable(double duration) { + uncontrollableDuration=duration; + if (state!=State.UNCONTROLLABLE) { + 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&&indexframeCount) { + setMarkedForDeletion(true); + return; + } + if (getSpriteTransform()==Transform.HORIZONTAL) { + setX(getAttachedObject().getX()+getAnimatedSpr().getWidth()/2); + } else { + setX(getAttachedObject().getX()-getAnimatedSpr().getWidth()/2); + } + setY(getAttachedObject().getY()); + } + + @Override + public void collisionEvent(AnimatedObject obj) { + if(obj instanceof PhysicsObject){ + PhysicsObject pobj = (PhysicsObject)obj; + if(!pobj.isInvulnerable()){ + if(getSpriteTransform()==Transform.NONE){ + pobj.setStagger(0.3); + pobj.x_velocity = -500; + pobj.y_velocity = -300; + }else{ + pobj.setStagger(0.3); + pobj.x_velocity = 500; + pobj.y_velocity = -300; + } + } + } + } + + @Override + public void draw(byte[] p) { + } + + @Override + public Transform getSpriteTransform() { + return getAttached().getSpriteTransform(); + } + + @Override + public boolean isFriendlyObject() { + return true; + } +}