Added CollisionListener for Swings
This commit is contained in:
parent
07c2babe96
commit
1a2f541390
@ -1,6 +1,7 @@
|
||||
package com.saltosion.gladiator.util;
|
||||
package com.saltosion.gladiator.collisionlisteners;
|
||||
|
||||
import com.badlogic.ashley.core.Entity;
|
||||
import com.saltosion.gladiator.util.Direction;
|
||||
|
||||
/**
|
||||
*
|
@ -0,0 +1,37 @@
|
||||
package com.saltosion.gladiator.collisionlisteners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.badlogic.ashley.core.ComponentMapper;
|
||||
import com.badlogic.ashley.core.Entity;
|
||||
import com.saltosion.gladiator.components.CCombat;
|
||||
import com.saltosion.gladiator.util.Direction;
|
||||
|
||||
public class SwingHitboxListener implements CollisionListener {
|
||||
|
||||
private ArrayList<Entity> hitEntities = new ArrayList<Entity>();
|
||||
private ComponentMapper<CCombat> cm = ComponentMapper.getFor(CCombat.class);
|
||||
private Entity source;
|
||||
|
||||
public SwingHitboxListener(Entity source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collision(Direction side, Entity host, Entity other) {
|
||||
if (other.equals(source) || hitEntities.contains(other)) {
|
||||
return; // These entities don't need to take damage
|
||||
}
|
||||
hitEntities.add(other);
|
||||
|
||||
CCombat otherCombat = cm.get(other);
|
||||
if (otherCombat == null) {
|
||||
System.out.println("This entity doesn't have combat!");
|
||||
return;
|
||||
}
|
||||
int damage = cm.get(source).getDamage();
|
||||
otherCombat.health -= damage;
|
||||
System.out.println("Entity was hit for " + damage + " damage!");
|
||||
}
|
||||
|
||||
}
|
@ -2,7 +2,7 @@ package com.saltosion.gladiator.components;
|
||||
|
||||
import com.badlogic.ashley.core.Component;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.saltosion.gladiator.util.CollisionListener;
|
||||
import com.saltosion.gladiator.collisionlisteners.CollisionListener;
|
||||
|
||||
public class CPhysics extends Component {
|
||||
|
||||
|
@ -8,6 +8,7 @@ import com.badlogic.ashley.core.Family;
|
||||
import com.badlogic.ashley.utils.ImmutableArray;
|
||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.saltosion.gladiator.collisionlisteners.SwingHitboxListener;
|
||||
import com.saltosion.gladiator.components.CCombat;
|
||||
import com.saltosion.gladiator.components.CDestructive;
|
||||
import com.saltosion.gladiator.components.CPhysics;
|
||||
@ -40,7 +41,6 @@ public class CombatSystem extends EntitySystem {
|
||||
} if (combat.swingCdCounter > 0) { return; }
|
||||
|
||||
// Ready to swing !
|
||||
System.out.println("Ready to swing!");
|
||||
|
||||
combat.getSwing().setZero();
|
||||
if (combat.inputs.get(Direction.LEFT)) {
|
||||
@ -67,7 +67,6 @@ public class CombatSystem extends EntitySystem {
|
||||
}
|
||||
createSwingHitbox(e, pos);
|
||||
|
||||
System.out.println("Swing to " + combat.getSwingDirection().toString());
|
||||
combat.swingCdCounter = combat.getSwingCD();
|
||||
}
|
||||
}
|
||||
@ -80,7 +79,7 @@ public class CombatSystem extends EntitySystem {
|
||||
e.add(new CRenderedObject(s));
|
||||
e.add(new CPhysics().setGhost(true).setGravityApplied(false).setMovable(false)
|
||||
.setSize(combat.getSwingSize()));
|
||||
e.getComponent(CPhysics.class).setPosition(position);
|
||||
e.getComponent(CPhysics.class).setPosition(position).setCollisionListener(new SwingHitboxListener(source));
|
||||
e.add(new CDestructive(.1f));
|
||||
AppUtil.engine.addEntity(e);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user