sigonasr2, Sig, Sigo 2 years ago committed by GitHub
commit 94bf7406e6
  1. 2
      README.md
  2. BIN
      RabiClone_0.0a.zip
  3. BIN
      bin/RabiClone.jar
  4. BIN
      bin/controls.config
  5. 13
      src/sig/RabiClone.java
  6. 3
      src/sig/engine/KeyBind.java
  7. 23
      src/sig/objects/ConfigureControls.java
  8. 18
      src/sig/objects/LevelRenderer.java
  9. 134
      src/sig/objects/Player.java
  10. 66
      src/sig/objects/actor/PhysicsObject.java
  11. 4
      src/sig/objects/actor/State.java
  12. 9
      src/sig/objects/weapons/KnifeSwing.java
  13. 66
      src/sig/objects/weapons/KnifeSwing2.java

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -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<KeyBind> binds = KeyBind.KEYBINDS.get(a);
for (int j=0;j<binds.size();j++) {
if (binds.get(j).port==i) {
binds.remove(j--);
}
}
KeyBind.KEYBINDS.put(a,binds);
ConfigureControls.updateHighlightSections();
}
}
Controller[] newArr = new Controller[CONTROLLERS.length - 1];
for (int j = 0; j < CONTROLLERS.length; j++) {
if (j != i) {

@ -65,7 +65,8 @@ public class KeyBind {
return Math.abs(RabiClone.CONTROLLERS[port].getComponent(id).getPollData())>=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());
}
}

@ -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<RabiClone.CONTROLLERS.length) {
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());
}
}
}
stream.writeByte('\0');
stream.writeByte((byte)-2);
}
stream.close();
} catch (IOException e) {
@ -152,7 +153,7 @@ public class ConfigureControls extends Object{
stream.writeChar('\0');
}
private static void updateHighlightSections() {
public static void updateHighlightSections() {
for (int i=0;i<Action.values().length;i++) {
Action a = Action.values()[i];
actionHighlightSections.add(new ArrayList<Integer>());

@ -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) {

@ -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<PhysicsObject> collisionBatch = new ArrayList<PhysicsObject>();
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;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
public void KeyReleased(Action a) {
if (a == Action.JUMP) {
spacebarPressed = 0;
spacebarReleased = true;
}
if (state != State.SLIDE) {
if (state != State.SLIDE&&state!=State.BELLYSLIDE) {
if ((a == Action.MOVE_LEFT) && (KeyHeld(Action.MOVE_RIGHT))) {
facing_direction = RIGHT;
} else if ((a == Action.MOVE_RIGHT) && (KeyHeld(Action.MOVE_LEFT))) {
@ -183,6 +258,24 @@ public class Player extends PhysicsObject{
public void KeyPressed(Action a) {
switch (state) {
case ATTACK:
if (a==Action.ATTACK&&RabiClone.TIME-weaponSwingTime>weaponComboWaitTime) {
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() {

@ -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&&index<RabiClone.COLLISION.length) {

@ -3,9 +3,13 @@ package sig.objects.actor;
public enum State{
IDLE,
SLIDE,
BELLYSLIDE,
JUMP,
FALLING,
ATTACK,
ATTACK2,
ATTACK3,
ATTACK4,
STAGGER,
UNCONTROLLABLE
}

@ -34,20 +34,17 @@ public class KnifeSwing extends AttachableObject{
@Override
public void collisionEvent(AnimatedObject obj) {
System.out.println("Bonk");
if(obj instanceof PhysicsObject){
PhysicsObject pobj = (PhysicsObject)obj;
if(pobj.state!=State.STAGGER){
if(!pobj.isInvulnerable()){
if(getSpriteTransform()==Transform.NONE){
pobj.staggerDuration=0.3;
pobj.setStagger(0.3);
pobj.x_velocity = -500;
pobj.y_velocity = -300;
pobj.state = State.STAGGER;
}else{
pobj.staggerDuration=0.3;
pobj.setStagger(0.3);
pobj.x_velocity = 500;
pobj.y_velocity = -300;
pobj.state = State.STAGGER;
}
}
}

@ -0,0 +1,66 @@
package sig.objects.weapons;
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 KnifeSwing2 extends AttachableObject{
final byte frameCount = 5; //Number of frames before animation ends.
public KnifeSwing2(AnimatedSprite spr, double animationSpd, Panel panel, Object attachedObj) {
super(spr, animationSpd, panel, attachedObj);
}
@Override
public void update(double updateMult) {
super.update(updateMult);
if (getCurrentFrame()>frameCount) {
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;
}
}
Loading…
Cancel
Save