Compare commits

...

2 Commits

Author SHA1 Message Date
Jeasonfire c5a3ccd861 Parrying added. (Sans animations) 2015-05-27 15:50:26 +03:00
Jeasonfire f5e0a40be7 Parrying (WIP) & animation loading cleanup. 2015-05-27 15:22:30 +03:00
11 changed files with 150 additions and 63 deletions

View File

@ -29,13 +29,16 @@ public class CCombat extends Component {
public int health = 0; public int health = 0;
private int maxHealth = 0; private int maxHealth = 0;
private int damage = 0; private int damage = 0;
private float swingForce = 20f; private float swingForce = 15f;
private Vector2 swingsize = new Vector2(3, 3); private Vector2 swingsize = new Vector2(3, 3);
private CombatListener combatListener; private CombatListener combatListener;
private Vector2 swinging = new Vector2(); private Vector2 swinging = new Vector2();
private float swingDuration = 0.4f; private float swingDuration = 0.4f;
public float swingCdCounter = 0; public float swingCdCounter = 0;
public float stunCounter = 0;
private boolean parrying = false;
public HashMap<Direction, Boolean> inputs = new HashMap<Direction, Boolean>(); public HashMap<Direction, Boolean> inputs = new HashMap<Direction, Boolean>();
@ -93,6 +96,11 @@ public class CCombat extends Component {
return this; return this;
} }
public CCombat setParrying(boolean parrying) {
this.parrying = parrying;
return this;
}
public int getMaxHealth() { public int getMaxHealth() {
return this.maxHealth; return this.maxHealth;
} }
@ -143,4 +151,8 @@ public class CCombat extends Component {
public CombatListener getCombatListener() { public CombatListener getCombatListener() {
return this.combatListener; return this.combatListener;
} }
public boolean isParrying() {
return parrying;
}
} }

View File

@ -0,0 +1,39 @@
/**
* GladiatorBrawler is a 2D swordfighting game.
* Copyright (C) 2015 Jeasonfire/Allexit
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.saltosion.gladiator.input;
import com.saltosion.gladiator.components.CCombat;
import com.saltosion.gladiator.util.AppUtil;
public class IRParry implements InputReceiver {
@Override
public boolean pressed() {
CCombat combat = AppUtil.player.getComponent(CCombat.class);
combat.setParrying(true);
return true;
}
@Override
public boolean released() {
CCombat combat = AppUtil.player.getComponent(CCombat.class);
combat.setParrying(false);
return true;
}
}

View File

@ -47,6 +47,7 @@ public class InputHandler implements InputProcessor {
addInput(Keys.RIGHT, Name.SWING_RIGHT, false); addInput(Keys.RIGHT, Name.SWING_RIGHT, false);
addInput(Keys.UP, Name.SWING_UP, false); addInput(Keys.UP, Name.SWING_UP, false);
addInput(Keys.DOWN, Name.SWING_DOWN, false); addInput(Keys.DOWN, Name.SWING_DOWN, false);
addInput(Keys.SHIFT_LEFT, Name.PARRY, false);
addInput(Keys.F2, Name.DEBUG, true); addInput(Keys.F2, Name.DEBUG, true);
addInput(Keys.ESCAPE, Name.SKIP_INTRO, false); addInput(Keys.ESCAPE, Name.SKIP_INTRO, false);
addInput(Keys.F3, Name.NEXT_LEVEL, false); addInput(Keys.F3, Name.NEXT_LEVEL, false);

View File

@ -34,6 +34,7 @@ public class InputReceivers {
inputreceivers.put(Name.SWING_RIGHT, new IRSwing(Direction.RIGHT)); inputreceivers.put(Name.SWING_RIGHT, new IRSwing(Direction.RIGHT));
inputreceivers.put(Name.SWING_UP, new IRSwing(Direction.UP)); inputreceivers.put(Name.SWING_UP, new IRSwing(Direction.UP));
inputreceivers.put(Name.SWING_DOWN, new IRSwing(Direction.DOWN)); inputreceivers.put(Name.SWING_DOWN, new IRSwing(Direction.DOWN));
inputreceivers.put(Name.PARRY, new IRParry());
inputreceivers.put(Name.DEBUG, new IRDebugToggle()); inputreceivers.put(Name.DEBUG, new IRDebugToggle());
inputreceivers.put(Name.SKIP_INTRO, new IRSkipIntros()); inputreceivers.put(Name.SKIP_INTRO, new IRSkipIntros());
inputreceivers.put(Name.NEXT_LEVEL, new IRNextLevel()); inputreceivers.put(Name.NEXT_LEVEL, new IRNextLevel());

View File

@ -110,62 +110,28 @@ public class EntityFactory {
renderedObject.addChannel("torso"); renderedObject.addChannel("torso");
// Idle animations // Idle animations
SpriteSequence torsoIdleRightSequence = new SpriteSequence(IDLE_ANIMATION_SPEED).addSprite(playerSprites[0][0][0]).addSprite(playerSprites[0][1][0]); addSpriteSequence(renderedObject, IDLE_ANIMATION_SPEED, "Torso-Idle-Right", playerSprites, 0, new int[]{0, 1}, 0);
renderedObject.addSequence("Torso-Idle-Right", torsoIdleRightSequence); addSpriteSequence(renderedObject, IDLE_ANIMATION_SPEED, "Legs-Idle-Right", playerSprites, 1, new int[]{0, 1}, 0);
SpriteSequence legsIdleRightSquence = new SpriteSequence(IDLE_ANIMATION_SPEED).addSprite(playerSprites[1][0][0]).addSprite(playerSprites[1][1][0]); addSpriteSequence(renderedObject, IDLE_ANIMATION_SPEED, "Torso-Idle-Left", playerSprites, 0, new int[]{0, 1}, 1);
renderedObject.addSequence("Legs-Idle-Right", legsIdleRightSquence); addSpriteSequence(renderedObject, IDLE_ANIMATION_SPEED, "Legs-Idle-Left", playerSprites, 1, new int[]{0, 1}, 1);
SpriteSequence torsoIdleLeftSequence = new SpriteSequence(IDLE_ANIMATION_SPEED).addSprite(playerSprites[0][0][1]).addSprite(playerSprites[0][1][1]);
renderedObject.addSequence("Torso-Idle-Left", torsoIdleLeftSequence);
SpriteSequence legsIdleLeftSquence = new SpriteSequence(IDLE_ANIMATION_SPEED).addSprite(playerSprites[1][0][1]).addSprite(playerSprites[1][1][1]);
renderedObject.addSequence("Legs-Idle-Left", legsIdleLeftSquence);
// Running animations // Running animations
SpriteSequence torsoRunRightSequence = new SpriteSequence(RUN_ANIMATION_SPEED).addSprite(playerSprites[0][2][0]) addSpriteSequence(renderedObject, RUN_ANIMATION_SPEED, "Torso-Run-Right", playerSprites, 0, new int[]{2, 3, 4, 5, 6, 5, 4, 3}, 0);
.addSprite(playerSprites[0][3][0]).addSprite(playerSprites[0][4][0]).addSprite(playerSprites[0][5][0]) addSpriteSequence(renderedObject, RUN_ANIMATION_SPEED, "Legs-Run-Right", playerSprites, 1, new int[]{2, 3, 4, 5, 6, 7, 8, 9}, 0);
.addSprite(playerSprites[0][6][0]).addSprite(playerSprites[0][5][0]).addSprite(playerSprites[0][4][0]) addSpriteSequence(renderedObject, RUN_ANIMATION_SPEED, "Torso-Run-Left", playerSprites, 0, new int[]{2, 3, 4, 5, 6, 5, 4, 3}, 1);
.addSprite(playerSprites[0][3][0]); addSpriteSequence(renderedObject, RUN_ANIMATION_SPEED, "Legs-Run-Left", playerSprites, 1, new int[]{2, 3, 4, 5, 6, 7, 8, 9}, 1);
renderedObject.addSequence("Torso-Run-Right", torsoRunRightSequence);
SpriteSequence legsRunRightSequence = new SpriteSequence(RUN_ANIMATION_SPEED).addSprite(playerSprites[1][2][0])
.addSprite(playerSprites[1][3][0]).addSprite(playerSprites[1][4][0]).addSprite(playerSprites[1][5][0])
.addSprite(playerSprites[1][6][0]).addSprite(playerSprites[1][7][0]).addSprite(playerSprites[1][8][0])
.addSprite(playerSprites[1][9][0]);
renderedObject.addSequence("Legs-Run-Right", legsRunRightSequence);
SpriteSequence torsoRunLeftSequence = new SpriteSequence(RUN_ANIMATION_SPEED).addSprite(playerSprites[0][2][1])
.addSprite(playerSprites[0][3][1]).addSprite(playerSprites[0][4][1]).addSprite(playerSprites[0][5][1])
.addSprite(playerSprites[0][6][1]).addSprite(playerSprites[0][5][1]).addSprite(playerSprites[0][4][1])
.addSprite(playerSprites[0][3][1]);
renderedObject.addSequence("Torso-Run-Left", torsoRunLeftSequence);
SpriteSequence legsRunLeftSequence = new SpriteSequence(RUN_ANIMATION_SPEED).addSprite(playerSprites[1][2][1])
.addSprite(playerSprites[1][3][1]).addSprite(playerSprites[1][4][1]).addSprite(playerSprites[1][5][1])
.addSprite(playerSprites[1][6][1]).addSprite(playerSprites[1][7][1]).addSprite(playerSprites[1][8][1])
.addSprite(playerSprites[1][9][1]);
renderedObject.addSequence("Legs-Run-Left", legsRunLeftSequence);
// Jumping animation // Jumping animation
SpriteSequence legsJumpRightSequence = new SpriteSequence(SWING_ANIMATION_SPEED).addSprite(playerSprites[1][8][0]); addSpriteSequence(renderedObject, IDLE_ANIMATION_SPEED, "Legs-Jump-Right", playerSprites, 1, 8, 0);
renderedObject.addSequence("Legs-Jump-Right", legsJumpRightSequence); addSpriteSequence(renderedObject, IDLE_ANIMATION_SPEED, "Legs-Jump-Left", playerSprites, 1, 8, 1);
SpriteSequence legsJumpLeftSequence = new SpriteSequence(SWING_ANIMATION_SPEED).addSprite(playerSprites[1][8][1]);
renderedObject.addSequence("Legs-Jump-Left", legsJumpLeftSequence);
// Combat animations // Combat animations
SpriteSequence torsoCombatRightSequence = new SpriteSequence(SWING_ANIMATION_SPEED).addSprite(playerSprites[0][7][0]) addSpriteSequence(renderedObject, SWING_ANIMATION_SPEED, "Torso-Combat-Right", playerSprites, 0, new int[]{7, 8, 9, 10}, 0);
.addSprite(playerSprites[0][8][0]).addSprite(playerSprites[0][9][0]).addSprite(playerSprites[0][10][0]); addSpriteSequence(renderedObject, SWING_ANIMATION_SPEED, "Torso-Combat-Left", playerSprites, 0, new int[]{7, 8, 9, 10}, 1);
renderedObject.addSequence("Torso-Combat-Right", torsoCombatRightSequence); addSpriteSequence(renderedObject, SWING_ANIMATION_SPEED, "Torso-Combat-Right-Down", playerSprites, 0, new int[]{11, 12, 13, 14}, 0);
SpriteSequence torsoCombatLeftSequence = new SpriteSequence(SWING_ANIMATION_SPEED).addSprite(playerSprites[0][7][1]) addSpriteSequence(renderedObject, SWING_ANIMATION_SPEED, "Torso-Combat-Right-Up", playerSprites, 0, new int[]{15, 16, 17, 18}, 0);
.addSprite(playerSprites[0][8][1]).addSprite(playerSprites[0][9][1]).addSprite(playerSprites[0][10][1]); addSpriteSequence(renderedObject, SWING_ANIMATION_SPEED, "Torso-Combat-Left-Down", playerSprites, 0, new int[]{11, 12, 13, 14}, 1);
renderedObject.addSequence("Torso-Combat-Left", torsoCombatLeftSequence); addSpriteSequence(renderedObject, SWING_ANIMATION_SPEED, "Torso-Combat-Left-Up", playerSprites, 0, new int[]{15, 16, 17, 18}, 1);
SpriteSequence torsoCombatRightDownSequence = new SpriteSequence(SWING_ANIMATION_SPEED).addSprite(playerSprites[0][11][0])
.addSprite(playerSprites[0][12][0]).addSprite(playerSprites[0][13][0]).addSprite(playerSprites[0][14][0]);
renderedObject.addSequence("Torso-Combat-Right-Down", torsoCombatRightDownSequence);
SpriteSequence torsoCombatRightUpSequence = new SpriteSequence(SWING_ANIMATION_SPEED).addSprite(playerSprites[0][15][0])
.addSprite(playerSprites[0][16][0]).addSprite(playerSprites[0][17][0]).addSprite(playerSprites[0][18][0]);
renderedObject.addSequence("Torso-Combat-Right-Up", torsoCombatRightUpSequence);
SpriteSequence torsoCombatLeftDownSequence = new SpriteSequence(SWING_ANIMATION_SPEED).addSprite(playerSprites[0][11][1])
.addSprite(playerSprites[0][12][1]).addSprite(playerSprites[0][13][1]).addSprite(playerSprites[0][14][1]);
renderedObject.addSequence("Torso-Combat-Left-Down", torsoCombatLeftDownSequence);
SpriteSequence torsoCombatLeftUpSequence = new SpriteSequence(SWING_ANIMATION_SPEED).addSprite(playerSprites[0][15][1])
.addSprite(playerSprites[0][16][1]).addSprite(playerSprites[0][17][1]).addSprite(playerSprites[0][18][1]);
renderedObject.addSequence("Torso-Combat-Left-Up", torsoCombatLeftUpSequence);
renderedObject.playAnimation("torso", "Torso-Idle-Right"); renderedObject.playAnimation("torso", "Torso-Idle-Right");
renderedObject.playAnimation("legs", "Legs-Idle-Right"); renderedObject.playAnimation("legs", "Legs-Idle-Right");
@ -173,4 +139,33 @@ public class EntityFactory {
return renderedObject; return renderedObject;
} }
// Don't mind these
private void addSpriteSequence(CRenderedObject target, int speed, String name, Sprite[][][] sheet, int xVal, int yVal, int flipVal) {
addSpriteSequence(target, speed, name, sheet, new int[]{xVal}, new int[]{yVal}, new int[]{flipVal});
}
private void addSpriteSequence(CRenderedObject target, int speed, String name, Sprite[][][] sheet, int xVal, int[] yVals, int flipVal) {
addSpriteSequence(target, speed, name, sheet, new int[]{xVal}, yVals, new int[]{flipVal});
}
private void addSpriteSequence(CRenderedObject target, int speed, String name, Sprite[][][] sheet, int[] xVals, int yVal, int flipVal) {
addSpriteSequence(target, speed, name, sheet, xVals, new int[]{yVal}, new int[]{flipVal});
}
private void addSpriteSequence(CRenderedObject target, int speed, String name, Sprite[][][] sheet, int[] xVals, int[] yVals, int flipVal) {
addSpriteSequence(target, speed, name, sheet, xVals, yVals, new int[]{flipVal});
}
private void addSpriteSequence(CRenderedObject target, int speed, String name, Sprite[][][] sheet, int[] xVals, int[] yVals, int[] flipVals) {
SpriteSequence sequence = new SpriteSequence(speed);
for (int x : xVals) {
for (int y : yVals) {
for (int f : flipVals) {
sequence.addSprite(sheet[x][y][f]);
}
}
}
target.addSequence(name, sequence);
}
} }

View File

@ -43,6 +43,10 @@ public class SwingHitboxListener implements CollisionListener {
this.direction = direction; this.direction = direction;
} }
public CCombat getSourceCombat() {
return cm.get(source);
}
@Override @Override
public void collision(Direction side, Entity host, Entity other) { public void collision(Direction side, Entity host, Entity other) {
if (other.equals(source) || hitEntities.contains(other)) { if (other.equals(source) || hitEntities.contains(other)) {
@ -50,8 +54,8 @@ public class SwingHitboxListener implements CollisionListener {
} }
hitEntities.add(other); hitEntities.add(other);
CCombat otherCombat = cm.get(other); CCombat sourceCombat = cm.get(source);
if (otherCombat != null) { if (cm.get(other) != null && !sourceCombat.isParrying()) {
int damage = cm.get(source).getDamage(); int damage = cm.get(source).getDamage();
CombatSystem.dealDamage(source, other, damage); CombatSystem.dealDamage(source, other, damage);
} }
@ -59,20 +63,28 @@ public class SwingHitboxListener implements CollisionListener {
CPhysics otherPhysics = pm.get(other); CPhysics otherPhysics = pm.get(other);
if (otherPhysics != null && otherPhysics.getCollisionListener() != null if (otherPhysics != null && otherPhysics.getCollisionListener() != null
&& otherPhysics.getCollisionListener() instanceof SwingHitboxListener) { && otherPhysics.getCollisionListener() instanceof SwingHitboxListener) {
float x = 0;
if (direction == Direction.LEFT) {
x = 1;
} else if (direction == Direction.RIGHT) {
x = -1;
}
float force = cm.get(source).getSwingForce();
pm.get(source).setSimVelocity(x * force, 0);
Sound s = AppUtil.jukebox.returnRandomSound(AudioLoader.getSound(Name.SOUND_CLANG01), Sound s = AppUtil.jukebox.returnRandomSound(AudioLoader.getSound(Name.SOUND_CLANG01),
AudioLoader.getSound(Name.SOUND_CLANG02), AudioLoader.getSound(Name.SOUND_CLANG02),
AudioLoader.getSound(Name.SOUND_CLANG03), AudioLoader.getSound(Name.SOUND_CLANG03),
AudioLoader.getSound(Name.SOUND_CLANG04)); AudioLoader.getSound(Name.SOUND_CLANG04));
s.play(AppUtil.sfxVolume); s.play(AppUtil.sfxVolume);
SwingHitboxListener otherListener = (SwingHitboxListener) otherPhysics.getCollisionListener();
if (!sourceCombat.isParrying()) {
// Source isn't parrying, throw back
float x = 0;
if (direction == Direction.LEFT) {
x = 1;
} else if (direction == Direction.RIGHT) {
x = -1;
}
CCombat otherCombat = otherListener.getSourceCombat();
if (otherCombat != null && otherCombat.isParrying()) {
x *= 1.75f;
sourceCombat.stunCounter = otherCombat.getSwingForce() / 10f;
}
pm.get(source).setSimVelocity(x * sourceCombat.getSwingForce(), 0);
}
} }
} }

View File

@ -81,6 +81,7 @@ public class InGameState extends BaseState {
AppUtil.inputHandler.setInputEnabled(Name.SWING_LEFT, true); AppUtil.inputHandler.setInputEnabled(Name.SWING_LEFT, true);
AppUtil.inputHandler.setInputEnabled(Name.SWING_RIGHT, true); AppUtil.inputHandler.setInputEnabled(Name.SWING_RIGHT, true);
AppUtil.inputHandler.setInputEnabled(Name.SWING_UP, true); AppUtil.inputHandler.setInputEnabled(Name.SWING_UP, true);
AppUtil.inputHandler.setInputEnabled(Name.PARRY, true);
AppUtil.inputHandler.setInputEnabled(Name.NEXT_LEVEL, true); AppUtil.inputHandler.setInputEnabled(Name.NEXT_LEVEL, true);
} }
@ -141,6 +142,7 @@ public class InGameState extends BaseState {
AppUtil.inputHandler.setInputEnabled(Name.SWING_LEFT, false); AppUtil.inputHandler.setInputEnabled(Name.SWING_LEFT, false);
AppUtil.inputHandler.setInputEnabled(Name.SWING_RIGHT, false); AppUtil.inputHandler.setInputEnabled(Name.SWING_RIGHT, false);
AppUtil.inputHandler.setInputEnabled(Name.SWING_UP, false); AppUtil.inputHandler.setInputEnabled(Name.SWING_UP, false);
AppUtil.inputHandler.setInputEnabled(Name.PARRY, false);
AppUtil.inputHandler.setInputEnabled(Name.NEXT_LEVEL, false); AppUtil.inputHandler.setInputEnabled(Name.NEXT_LEVEL, false);
// Clear all entities that are left as they are no longer needed // Clear all entities that are left as they are no longer needed

View File

@ -58,6 +58,10 @@ public class CombatSystem extends EntitySystem {
combat.swingCdCounter -= deltaTime; combat.swingCdCounter -= deltaTime;
continue; continue;
} }
if (combat.stunCounter > 0) {
combat.stunCounter -= deltaTime;
continue;
}
// Ready to swing ! // Ready to swing !
combat.getSwing().setZero(); combat.getSwing().setZero();

View File

@ -74,6 +74,12 @@ public class PhysicsSystem extends EntitySystem {
if (combat.swingCdCounter > 0) { if (combat.swingCdCounter > 0) {
obj.getVelocity().x /= 2; obj.getVelocity().x /= 2;
} }
if (combat.isParrying()) {
obj.getVelocity().x /= 2;
}
if (combat.stunCounter > 0) {
obj.getVelocity().x = 0;
}
} }
if (obj.jumping && obj.isGrounded()) { if (obj.jumping && obj.isGrounded()) {
obj.setGrounded(false); obj.setGrounded(false);

View File

@ -208,13 +208,26 @@ public class RenderingSystem extends EntitySystem {
} }
if (moving && combat) { if (moving && combat) {
ro.playAnimation("torso", "Torso-Combat-" + dirSwing); if (co.isParrying()) {
// Parrying animation
ro.playAnimation("torso", "Torso-Combat-" + dirSwing); // Change this to parrying anim
} else {
// Swinging animation
ro.playAnimation("torso", "Torso-Combat-" + dirSwing);
}
// Moving animation
ro.playAnimation("legs", "Legs-Run-" + dirMove); ro.playAnimation("legs", "Legs-Run-" + dirMove);
tryToMakeStepSound(po); tryToMakeStepSound(po);
} else if (combat && co.isParrying()) {
// Parrying animation
ro.playAnimation("torso", "Torso-Combat-" + dirSwing); // Change this to parrying anim
ro.playAnimation("legs", "Legs-Idle-" + dirMove);
} else if (combat) { } else if (combat) {
// Swinging animation
ro.playAnimation("torso", "Torso-Combat-" + dirSwing); ro.playAnimation("torso", "Torso-Combat-" + dirSwing);
ro.playAnimation("legs", "Legs-Idle-" + dirMove); ro.playAnimation("legs", "Legs-Idle-" + dirMove);
} else if (moving) { } else if (moving) {
// Moving animation
ro.playAnimation("torso", "Torso-Run-" + dirMove); ro.playAnimation("torso", "Torso-Run-" + dirMove);
ro.playAnimation("legs", "Legs-Run-" + dirMove); ro.playAnimation("legs", "Legs-Run-" + dirMove);
tryToMakeStepSound(po); tryToMakeStepSound(po);
@ -223,6 +236,7 @@ public class RenderingSystem extends EntitySystem {
ro.playAnimation("legs", "Legs-Idle-" + dirMove); ro.playAnimation("legs", "Legs-Idle-" + dirMove);
} }
if (!po.isGrounded()) { if (!po.isGrounded()) {
// In-air animation for legs
ro.playAnimation("legs", "Legs-Jump-" + dirMove); ro.playAnimation("legs", "Legs-Jump-" + dirMove);
} }
} }

View File

@ -50,6 +50,7 @@ public class Name {
public static final String SWING_RIGHT = "SWING_RIGHT"; public static final String SWING_RIGHT = "SWING_RIGHT";
public static final String SWING_UP = "SWING_UP"; public static final String SWING_UP = "SWING_UP";
public static final String SWING_DOWN = "SWING_DOWN"; public static final String SWING_DOWN = "SWING_DOWN";
public static final String PARRY = "PARRY";
public static final String SKIP_INTRO = "SKIP_INTRO"; public static final String SKIP_INTRO = "SKIP_INTRO";
public static final String NEXT_LEVEL = "NEXT_LEVEL"; public static final String NEXT_LEVEL = "NEXT_LEVEL";
public static final String DEBUG = "DEBUG"; public static final String DEBUG = "DEBUG";