Knockback on sword collision added.
This commit is contained in:
parent
2c4f2dbfa3
commit
71d1001bbd
@ -8,33 +8,35 @@ import com.saltosion.gladiator.listeners.CombatListener;
|
|||||||
import com.saltosion.gladiator.util.Direction;
|
import com.saltosion.gladiator.util.Direction;
|
||||||
|
|
||||||
public class CCombat extends Component {
|
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 Vector2 swingsize = new Vector2(4, 3);
|
private Vector2 swingsize = new Vector2(4, 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 HashMap<Direction, Boolean> inputs = new HashMap<Direction, Boolean>();
|
public HashMap<Direction, Boolean> inputs = new HashMap<Direction, Boolean>();
|
||||||
|
|
||||||
public CCombat() {
|
public CCombat() {
|
||||||
this.inputs.put(Direction.UP, false);
|
this.inputs.put(Direction.UP, false);
|
||||||
this.inputs.put(Direction.DOWN, false);
|
this.inputs.put(Direction.DOWN, false);
|
||||||
this.inputs.put(Direction.LEFT, false);
|
this.inputs.put(Direction.LEFT, false);
|
||||||
this.inputs.put(Direction.RIGHT, false);
|
this.inputs.put(Direction.RIGHT, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CCombat setBaseDamage(int basedmg) {
|
public CCombat setBaseDamage(int basedmg) {
|
||||||
this.damage = basedmg;
|
this.damage = basedmg;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets max health for entity and replenishes health.
|
* Sets max health for entity and replenishes health.
|
||||||
|
*
|
||||||
* @param health
|
* @param health
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -43,54 +45,63 @@ public class CCombat extends Component {
|
|||||||
this.maxHealth = health;
|
this.maxHealth = health;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CCombat setMaxHealth(int maxHealth) {
|
public CCombat setMaxHealth(int maxHealth) {
|
||||||
this.maxHealth = maxHealth;
|
this.maxHealth = maxHealth;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CCombat setSwingForce(float force) {
|
||||||
|
this.swingForce = force;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public CCombat setSwingCD(float cd) {
|
public CCombat setSwingCD(float cd) {
|
||||||
this.swingDuration = cd;
|
this.swingDuration = cd;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CCombat setSwinging(Vector2 swingdir) {
|
public CCombat setSwinging(Vector2 swingdir) {
|
||||||
this.swinging = swingdir;
|
this.swinging = swingdir;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CCombat setSwingSize(Vector2 swingsize) {
|
public CCombat setSwingSize(Vector2 swingsize) {
|
||||||
this.swingsize = swingsize;
|
this.swingsize = swingsize;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CCombat setCombatListener(CombatListener listener) {
|
public CCombat setCombatListener(CombatListener listener) {
|
||||||
this.combatListener = listener;
|
this.combatListener = listener;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxHealth() {
|
public int getMaxHealth() {
|
||||||
return this.maxHealth;
|
return this.maxHealth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDamage() {
|
public int getDamage() {
|
||||||
float minDmg = damage*0.9f;
|
float minDmg = damage * 0.9f;
|
||||||
float maxDmg = damage*1.1f;
|
float maxDmg = damage * 1.1f;
|
||||||
int randomdamage = (int) (Math.random()*(maxDmg-minDmg)+minDmg);
|
int randomdamage = (int) (Math.random() * (maxDmg - minDmg) + minDmg);
|
||||||
if (Math.random() > 0.7) {
|
if (Math.random() > 0.7) {
|
||||||
randomdamage *= 1.5;
|
randomdamage *= 1.5;
|
||||||
}
|
}
|
||||||
return randomdamage;
|
return randomdamage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getSwingForce() {
|
||||||
|
return swingForce;
|
||||||
|
}
|
||||||
|
|
||||||
public float getSwingDuration() {
|
public float getSwingDuration() {
|
||||||
return this.swingDuration;
|
return this.swingDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2 getSwing() {
|
public Vector2 getSwing() {
|
||||||
return this.swinging;
|
return this.swinging;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Direction getSwingDirection() {
|
public Direction getSwingDirection() {
|
||||||
if (swinging.x > 0) {
|
if (swinging.x > 0) {
|
||||||
return Direction.RIGHT;
|
return Direction.RIGHT;
|
||||||
@ -103,11 +114,11 @@ public class CCombat extends Component {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2 getSwingSize() {
|
public Vector2 getSwingSize() {
|
||||||
return this.swingsize;
|
return this.swingsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CombatListener getCombatListener() {
|
public CombatListener getCombatListener() {
|
||||||
return this.combatListener;
|
return this.combatListener;
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,9 @@ public class CPhysics extends Component {
|
|||||||
|
|
||||||
private final Vector2 position = new Vector2();
|
private final Vector2 position = new Vector2();
|
||||||
private final Vector2 velocity = new Vector2();
|
private final Vector2 velocity = new Vector2();
|
||||||
|
private final Vector2 simVelocity = new Vector2();
|
||||||
private final Vector2 size = new Vector2();
|
private final Vector2 size = new Vector2();
|
||||||
private float movespeed = 15f, jumpForce = 35f, gravity = 100f;
|
private float movespeed = 15f, jumpForce = 35f, gravity = 100f, drag = 30f;
|
||||||
private CollisionListener collisionListener = null;
|
private CollisionListener collisionListener = null;
|
||||||
private float zParallax = 1;
|
private float zParallax = 1;
|
||||||
|
|
||||||
@ -90,8 +91,33 @@ public class CPhysics extends Component {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CPhysics setVelocity(Vector2 pos) {
|
public CPhysics setVelocity(Vector2 vel) {
|
||||||
this.velocity.set(pos);
|
this.velocity.set(vel);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This velocity can be set externally and will always end up being 0 after
|
||||||
|
* some time that depends on the value of the drag variable
|
||||||
|
*
|
||||||
|
* @param x The x part of the new sim velocity
|
||||||
|
* @param y The y part of the new sim velocity
|
||||||
|
* @return The host component
|
||||||
|
*/
|
||||||
|
public CPhysics setSimVelocity(float x, float y) {
|
||||||
|
this.simVelocity.set(x, y);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This velocity can be set externally and will always end up being 0 after
|
||||||
|
* some time that depends on the value of the drag variable
|
||||||
|
*
|
||||||
|
* @param simVel The new sim velocity
|
||||||
|
* @return The host component
|
||||||
|
*/
|
||||||
|
public CPhysics setSimVelocity(Vector2 simVel) {
|
||||||
|
this.simVelocity.set(simVel);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +134,11 @@ public class CPhysics extends Component {
|
|||||||
public CPhysics setGravity(float gravity) {
|
public CPhysics setGravity(float gravity) {
|
||||||
this.gravity = gravity;
|
this.gravity = gravity;
|
||||||
return this;
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CPhysics setDrag(float drag) {
|
||||||
|
this.drag = drag;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CPhysics setCollisionListener(CollisionListener collisionListener) {
|
public CPhysics setCollisionListener(CollisionListener collisionListener) {
|
||||||
@ -139,6 +169,10 @@ public class CPhysics extends Component {
|
|||||||
return this.velocity;
|
return this.velocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector2 getSimVelocity() {
|
||||||
|
return this.simVelocity;
|
||||||
|
}
|
||||||
|
|
||||||
public Vector2 getSize() {
|
public Vector2 getSize() {
|
||||||
return this.size;
|
return this.size;
|
||||||
}
|
}
|
||||||
@ -155,6 +189,10 @@ public class CPhysics extends Component {
|
|||||||
return this.gravity;
|
return this.gravity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getDrag() {
|
||||||
|
return this.drag;
|
||||||
|
}
|
||||||
|
|
||||||
public CollisionListener getCollisionListener() {
|
public CollisionListener getCollisionListener() {
|
||||||
return this.collisionListener;
|
return this.collisionListener;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import com.saltosion.gladiator.level.Level;
|
|||||||
import com.saltosion.gladiator.util.AppUtil;
|
import com.saltosion.gladiator.util.AppUtil;
|
||||||
import com.saltosion.gladiator.util.Direction;
|
import com.saltosion.gladiator.util.Direction;
|
||||||
import com.saltosion.gladiator.util.Global;
|
import com.saltosion.gladiator.util.Global;
|
||||||
|
import com.saltosion.gladiator.util.Log;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Round1Level implements Level {
|
public class Round1Level implements Level {
|
||||||
|
@ -39,14 +39,16 @@ 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) {
|
||||||
Log.info("Clash!");
|
float x = 0, y = 0;
|
||||||
float x = 0;
|
|
||||||
if (direction == Direction.LEFT) {
|
if (direction == Direction.LEFT) {
|
||||||
x = -1;
|
|
||||||
}
|
|
||||||
if (direction == Direction.RIGHT) {
|
|
||||||
x = 1;
|
x = 1;
|
||||||
|
} else if (direction == Direction.RIGHT) {
|
||||||
|
x = -1;
|
||||||
|
} else if (direction == Direction.DOWN) {
|
||||||
|
y = 1;
|
||||||
}
|
}
|
||||||
|
float force = cm.get(source).getSwingForce();
|
||||||
|
pm.get(source).setSimVelocity(x * force, y * force / 8f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,6 +58,12 @@ public class PhysicsSystem extends EntitySystem {
|
|||||||
obj.setGrounded(false);
|
obj.setGrounded(false);
|
||||||
obj.getVelocity().y = obj.getJumpForce();
|
obj.getVelocity().y = obj.getJumpForce();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
obj.getVelocity().x += obj.getSimVelocity().x;
|
||||||
|
obj.getVelocity().y += obj.getSimVelocity().y;
|
||||||
|
|
||||||
|
obj.getSimVelocity().x -= obj.getDrag() * deltaTime * Math.signum(obj.getSimVelocity().x);
|
||||||
|
obj.getSimVelocity().y -= obj.getDrag() * deltaTime * Math.signum(obj.getSimVelocity().y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gravity
|
// Gravity
|
||||||
|
Loading…
Reference in New Issue
Block a user