Parrying added. (Sans animations)

This commit is contained in:
Jeasonfire 2015-05-27 15:50:26 +03:00
parent f5e0a40be7
commit c5a3ccd861
4 changed files with 23 additions and 3 deletions

View File

@ -29,13 +29,14 @@ public class CCombat extends Component {
public int health = 0;
private int maxHealth = 0;
private int damage = 0;
private float swingForce = 20f;
private float swingForce = 15f;
private Vector2 swingsize = new Vector2(3, 3);
private CombatListener combatListener;
private Vector2 swinging = new Vector2();
private float swingDuration = 0.4f;
public float swingCdCounter = 0;
public float stunCounter = 0;
private boolean parrying = false;

View File

@ -43,6 +43,10 @@ public class SwingHitboxListener implements CollisionListener {
this.direction = direction;
}
public CCombat getSourceCombat() {
return cm.get(source);
}
@Override
public void collision(Direction side, Entity host, Entity other) {
if (other.equals(source) || hitEntities.contains(other)) {
@ -51,8 +55,7 @@ public class SwingHitboxListener implements CollisionListener {
hitEntities.add(other);
CCombat sourceCombat = cm.get(source);
CCombat otherCombat = cm.get(other);
if (otherCombat != null && !sourceCombat.isParrying()) {
if (cm.get(other) != null && !sourceCombat.isParrying()) {
int damage = cm.get(source).getDamage();
CombatSystem.dealDamage(source, other, damage);
}
@ -66,6 +69,7 @@ public class SwingHitboxListener implements CollisionListener {
AudioLoader.getSound(Name.SOUND_CLANG04));
s.play(AppUtil.sfxVolume);
SwingHitboxListener otherListener = (SwingHitboxListener) otherPhysics.getCollisionListener();
if (!sourceCombat.isParrying()) {
// Source isn't parrying, throw back
float x = 0;
@ -74,6 +78,11 @@ public class SwingHitboxListener implements CollisionListener {
} 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

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

View File

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