diff --git a/core/src/com/saltosion/gladiator/components/CCombat.java b/core/src/com/saltosion/gladiator/components/CCombat.java index a7ed16f..7243831 100644 --- a/core/src/com/saltosion/gladiator/components/CCombat.java +++ b/core/src/com/saltosion/gladiator/components/CCombat.java @@ -37,6 +37,8 @@ public class CCombat extends Component { private float swingDuration = 0.4f; public float swingCdCounter = 0; + private boolean parrying = false; + public HashMap inputs = new HashMap(); public CCombat() { @@ -93,6 +95,11 @@ public class CCombat extends Component { return this; } + public CCombat setParrying(boolean parrying) { + this.parrying = parrying; + return this; + } + public int getMaxHealth() { return this.maxHealth; } @@ -143,4 +150,8 @@ public class CCombat extends Component { public CombatListener getCombatListener() { return this.combatListener; } + + public boolean isParrying() { + return parrying; + } } diff --git a/core/src/com/saltosion/gladiator/input/IRParry.java b/core/src/com/saltosion/gladiator/input/IRParry.java new file mode 100644 index 0000000..90cf61a --- /dev/null +++ b/core/src/com/saltosion/gladiator/input/IRParry.java @@ -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 . + */ +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; + } + +} diff --git a/core/src/com/saltosion/gladiator/input/InputHandler.java b/core/src/com/saltosion/gladiator/input/InputHandler.java index 007f3d3..cfef89f 100644 --- a/core/src/com/saltosion/gladiator/input/InputHandler.java +++ b/core/src/com/saltosion/gladiator/input/InputHandler.java @@ -47,6 +47,7 @@ public class InputHandler implements InputProcessor { addInput(Keys.RIGHT, Name.SWING_RIGHT, false); addInput(Keys.UP, Name.SWING_UP, false); addInput(Keys.DOWN, Name.SWING_DOWN, false); + addInput(Keys.SHIFT_LEFT, Name.PARRY, false); addInput(Keys.F2, Name.DEBUG, true); addInput(Keys.ESCAPE, Name.SKIP_INTRO, false); addInput(Keys.F3, Name.NEXT_LEVEL, false); diff --git a/core/src/com/saltosion/gladiator/input/InputReceivers.java b/core/src/com/saltosion/gladiator/input/InputReceivers.java index 654721a..3431528 100644 --- a/core/src/com/saltosion/gladiator/input/InputReceivers.java +++ b/core/src/com/saltosion/gladiator/input/InputReceivers.java @@ -34,6 +34,7 @@ public class InputReceivers { inputreceivers.put(Name.SWING_RIGHT, new IRSwing(Direction.RIGHT)); inputreceivers.put(Name.SWING_UP, new IRSwing(Direction.UP)); inputreceivers.put(Name.SWING_DOWN, new IRSwing(Direction.DOWN)); + inputreceivers.put(Name.PARRY, new IRParry()); inputreceivers.put(Name.DEBUG, new IRDebugToggle()); inputreceivers.put(Name.SKIP_INTRO, new IRSkipIntros()); inputreceivers.put(Name.NEXT_LEVEL, new IRNextLevel()); diff --git a/core/src/com/saltosion/gladiator/level/EntityFactory.java b/core/src/com/saltosion/gladiator/level/EntityFactory.java index b844ae1..c1ec1bd 100644 --- a/core/src/com/saltosion/gladiator/level/EntityFactory.java +++ b/core/src/com/saltosion/gladiator/level/EntityFactory.java @@ -110,62 +110,28 @@ public class EntityFactory { renderedObject.addChannel("torso"); // Idle animations - SpriteSequence torsoIdleRightSequence = new SpriteSequence(IDLE_ANIMATION_SPEED).addSprite(playerSprites[0][0][0]).addSprite(playerSprites[0][1][0]); - renderedObject.addSequence("Torso-Idle-Right", torsoIdleRightSequence); - SpriteSequence legsIdleRightSquence = new SpriteSequence(IDLE_ANIMATION_SPEED).addSprite(playerSprites[1][0][0]).addSprite(playerSprites[1][1][0]); - renderedObject.addSequence("Legs-Idle-Right", legsIdleRightSquence); - 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); + addSpriteSequence(renderedObject, IDLE_ANIMATION_SPEED, "Torso-Idle-Right", playerSprites, 0, new int[]{0, 1}, 0); + addSpriteSequence(renderedObject, IDLE_ANIMATION_SPEED, "Legs-Idle-Right", playerSprites, 1, new int[]{0, 1}, 0); + addSpriteSequence(renderedObject, IDLE_ANIMATION_SPEED, "Torso-Idle-Left", playerSprites, 0, new int[]{0, 1}, 1); + addSpriteSequence(renderedObject, IDLE_ANIMATION_SPEED, "Legs-Idle-Left", playerSprites, 1, new int[]{0, 1}, 1); // Running animations - SpriteSequence torsoRunRightSequence = new SpriteSequence(RUN_ANIMATION_SPEED).addSprite(playerSprites[0][2][0]) - .addSprite(playerSprites[0][3][0]).addSprite(playerSprites[0][4][0]).addSprite(playerSprites[0][5][0]) - .addSprite(playerSprites[0][6][0]).addSprite(playerSprites[0][5][0]).addSprite(playerSprites[0][4][0]) - .addSprite(playerSprites[0][3][0]); - 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); + addSpriteSequence(renderedObject, RUN_ANIMATION_SPEED, "Torso-Run-Right", playerSprites, 0, new int[]{2, 3, 4, 5, 6, 5, 4, 3}, 0); + addSpriteSequence(renderedObject, RUN_ANIMATION_SPEED, "Legs-Run-Right", playerSprites, 1, new int[]{2, 3, 4, 5, 6, 7, 8, 9}, 0); + addSpriteSequence(renderedObject, RUN_ANIMATION_SPEED, "Torso-Run-Left", playerSprites, 0, new int[]{2, 3, 4, 5, 6, 5, 4, 3}, 1); + addSpriteSequence(renderedObject, RUN_ANIMATION_SPEED, "Legs-Run-Left", playerSprites, 1, new int[]{2, 3, 4, 5, 6, 7, 8, 9}, 1); // Jumping animation - SpriteSequence legsJumpRightSequence = new SpriteSequence(SWING_ANIMATION_SPEED).addSprite(playerSprites[1][8][0]); - renderedObject.addSequence("Legs-Jump-Right", legsJumpRightSequence); - SpriteSequence legsJumpLeftSequence = new SpriteSequence(SWING_ANIMATION_SPEED).addSprite(playerSprites[1][8][1]); - renderedObject.addSequence("Legs-Jump-Left", legsJumpLeftSequence); + addSpriteSequence(renderedObject, IDLE_ANIMATION_SPEED, "Legs-Jump-Right", playerSprites, 1, 8, 0); + addSpriteSequence(renderedObject, IDLE_ANIMATION_SPEED, "Legs-Jump-Left", playerSprites, 1, 8, 1); // Combat animations - SpriteSequence torsoCombatRightSequence = new SpriteSequence(SWING_ANIMATION_SPEED).addSprite(playerSprites[0][7][0]) - .addSprite(playerSprites[0][8][0]).addSprite(playerSprites[0][9][0]).addSprite(playerSprites[0][10][0]); - renderedObject.addSequence("Torso-Combat-Right", torsoCombatRightSequence); - SpriteSequence torsoCombatLeftSequence = new SpriteSequence(SWING_ANIMATION_SPEED).addSprite(playerSprites[0][7][1]) - .addSprite(playerSprites[0][8][1]).addSprite(playerSprites[0][9][1]).addSprite(playerSprites[0][10][1]); - renderedObject.addSequence("Torso-Combat-Left", torsoCombatLeftSequence); - 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); + addSpriteSequence(renderedObject, SWING_ANIMATION_SPEED, "Torso-Combat-Right", playerSprites, 0, new int[]{7, 8, 9, 10}, 0); + addSpriteSequence(renderedObject, SWING_ANIMATION_SPEED, "Torso-Combat-Left", playerSprites, 0, new int[]{7, 8, 9, 10}, 1); + addSpriteSequence(renderedObject, SWING_ANIMATION_SPEED, "Torso-Combat-Right-Down", playerSprites, 0, new int[]{11, 12, 13, 14}, 0); + addSpriteSequence(renderedObject, SWING_ANIMATION_SPEED, "Torso-Combat-Right-Up", playerSprites, 0, new int[]{15, 16, 17, 18}, 0); + addSpriteSequence(renderedObject, SWING_ANIMATION_SPEED, "Torso-Combat-Left-Down", playerSprites, 0, new int[]{11, 12, 13, 14}, 1); + addSpriteSequence(renderedObject, SWING_ANIMATION_SPEED, "Torso-Combat-Left-Up", playerSprites, 0, new int[]{15, 16, 17, 18}, 1); renderedObject.playAnimation("torso", "Torso-Idle-Right"); renderedObject.playAnimation("legs", "Legs-Idle-Right"); @@ -173,4 +139,33 @@ public class EntityFactory { 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); + } + } diff --git a/core/src/com/saltosion/gladiator/listeners/SwingHitboxListener.java b/core/src/com/saltosion/gladiator/listeners/SwingHitboxListener.java index e6d6150..a7d4dc9 100644 --- a/core/src/com/saltosion/gladiator/listeners/SwingHitboxListener.java +++ b/core/src/com/saltosion/gladiator/listeners/SwingHitboxListener.java @@ -50,8 +50,9 @@ public class SwingHitboxListener implements CollisionListener { } hitEntities.add(other); + CCombat sourceCombat = cm.get(source); CCombat otherCombat = cm.get(other); - if (otherCombat != null) { + if (otherCombat != null && !sourceCombat.isParrying()) { int damage = cm.get(source).getDamage(); CombatSystem.dealDamage(source, other, damage); } @@ -59,20 +60,22 @@ public class SwingHitboxListener implements CollisionListener { CPhysics otherPhysics = pm.get(other); if (otherPhysics != null && otherPhysics.getCollisionListener() != null && 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), AudioLoader.getSound(Name.SOUND_CLANG02), AudioLoader.getSound(Name.SOUND_CLANG03), AudioLoader.getSound(Name.SOUND_CLANG04)); s.play(AppUtil.sfxVolume); + + 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; + } + pm.get(source).setSimVelocity(x * sourceCombat.getSwingForce(), 0); + } } } diff --git a/core/src/com/saltosion/gladiator/state/InGameState.java b/core/src/com/saltosion/gladiator/state/InGameState.java index 2af1357..ea7a26b 100644 --- a/core/src/com/saltosion/gladiator/state/InGameState.java +++ b/core/src/com/saltosion/gladiator/state/InGameState.java @@ -81,6 +81,7 @@ public class InGameState extends BaseState { AppUtil.inputHandler.setInputEnabled(Name.SWING_LEFT, true); AppUtil.inputHandler.setInputEnabled(Name.SWING_RIGHT, true); AppUtil.inputHandler.setInputEnabled(Name.SWING_UP, true); + AppUtil.inputHandler.setInputEnabled(Name.PARRY, 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_RIGHT, false); AppUtil.inputHandler.setInputEnabled(Name.SWING_UP, false); + AppUtil.inputHandler.setInputEnabled(Name.PARRY, false); AppUtil.inputHandler.setInputEnabled(Name.NEXT_LEVEL, false); // Clear all entities that are left as they are no longer needed diff --git a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java index db92659..e17bef8 100644 --- a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java +++ b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java @@ -208,13 +208,26 @@ public class RenderingSystem extends EntitySystem { } 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); 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) { + // Swinging animation ro.playAnimation("torso", "Torso-Combat-" + dirSwing); ro.playAnimation("legs", "Legs-Idle-" + dirMove); } else if (moving) { + // Moving animation ro.playAnimation("torso", "Torso-Run-" + dirMove); ro.playAnimation("legs", "Legs-Run-" + dirMove); tryToMakeStepSound(po); @@ -223,6 +236,7 @@ public class RenderingSystem extends EntitySystem { ro.playAnimation("legs", "Legs-Idle-" + dirMove); } if (!po.isGrounded()) { + // In-air animation for legs ro.playAnimation("legs", "Legs-Jump-" + dirMove); } } diff --git a/core/src/com/saltosion/gladiator/util/Name.java b/core/src/com/saltosion/gladiator/util/Name.java index 4f21d8a..e292b98 100644 --- a/core/src/com/saltosion/gladiator/util/Name.java +++ b/core/src/com/saltosion/gladiator/util/Name.java @@ -50,6 +50,7 @@ public class Name { public static final String SWING_RIGHT = "SWING_RIGHT"; public static final String SWING_UP = "SWING_UP"; 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 NEXT_LEVEL = "NEXT_LEVEL"; public static final String DEBUG = "DEBUG";