Added ghost variable, resized player hitbox & cleaned docs.
This commit is contained in:
parent
1136a9b8b8
commit
543ef101e3
@ -84,8 +84,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
|
||||
renderedObject.addSequence("Idle", sequence);
|
||||
renderedObject.playAnimation("Idle");
|
||||
player.add(renderedObject);
|
||||
player.add(new CPhysics().setSize(player1.getRegionWidth() * Global.SPRITE_SCALE,
|
||||
player1.getRegionHeight() * Global.SPRITE_SCALE).setPosition(0, 5));
|
||||
player.add(new CPhysics().setSize(2, 4).setPosition(0, 5));
|
||||
|
||||
engine.addEntity(player);
|
||||
|
||||
|
@ -13,33 +13,53 @@ public class CPhysics extends Component {
|
||||
public boolean grounded = true;
|
||||
public CollisionListener collisionListener = null;
|
||||
|
||||
// Movable toggles if the entity can move by itself
|
||||
public boolean movable = true;
|
||||
// GravityApplied toggles if the entity is affected by gravity
|
||||
public boolean gravityApplied = true;
|
||||
// Dynamic toggles if the entity processes collisions
|
||||
public boolean dynamic = true;
|
||||
public boolean ghost = false;
|
||||
|
||||
// Movement (/input) vars
|
||||
public boolean movingLeft = false;
|
||||
public boolean movingRight = false;
|
||||
public boolean jumping = false;
|
||||
|
||||
/**
|
||||
* @param movable Toggles if the entity can move by itself
|
||||
* @return Returns the instance this methdod was called from
|
||||
*/
|
||||
public CPhysics setMovable(boolean movable) {
|
||||
this.movable = movable;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param gravityApplied Toggles if the entity is affected by gravity
|
||||
* @return Returns the instance this methdod was called from
|
||||
*/
|
||||
public CPhysics setGravityApplied(boolean gravityApplied) {
|
||||
this.gravityApplied = gravityApplied;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dynamic Toggles if the entity processes collisions
|
||||
* @return Returns the instance this methdod was called from
|
||||
*/
|
||||
public CPhysics setDynamic(boolean dynamic) {
|
||||
this.dynamic = dynamic;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ghost Toggles if the entity is affected by collisions (will call
|
||||
* collision listener anyway if dynamic == true)
|
||||
* @return Returns the instance this methdod was called from
|
||||
*/
|
||||
public CPhysics setGhost(boolean ghost) {
|
||||
this.ghost = ghost;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CPhysics setSize(float w, float h) {
|
||||
this.size.set(w, h);
|
||||
return this;
|
||||
|
@ -89,9 +89,11 @@ public class PhysicsSystem extends EntitySystem {
|
||||
|
||||
if (x00 <= x11 && Math.abs(x00 - x11) < (cp0.size.x + cp1.size.x) / 16) {
|
||||
// cp0's left side is colliding with cp1's right side
|
||||
if (cp0.velocity.x < 0) {
|
||||
// cp0 is going left, stop
|
||||
cp0.velocity.x = 0;
|
||||
if (!cp0.ghost && !cp1.ghost) {
|
||||
if (cp0.velocity.x < 0) {
|
||||
// cp0 is going left, stop
|
||||
cp0.velocity.x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (cp0.collisionListener != null) {
|
||||
@ -100,9 +102,11 @@ public class PhysicsSystem extends EntitySystem {
|
||||
}
|
||||
if (x01 > x10 && Math.abs(x01 - x10) < (cp0.size.x + cp1.size.x) / 16) {
|
||||
// cp0's right side is colliding with cp1's left side
|
||||
if (cp0.velocity.x > 0) {
|
||||
// cp0 is going right, stop
|
||||
cp0.velocity.x = 0;
|
||||
if (!cp0.ghost && !cp1.ghost) {
|
||||
if (cp0.velocity.x > 0) {
|
||||
// cp0 is going right, stop
|
||||
cp0.velocity.x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (cp0.collisionListener != null) {
|
||||
@ -111,12 +115,14 @@ public class PhysicsSystem extends EntitySystem {
|
||||
}
|
||||
if (y00 <= y11 && Math.abs(y00 - y11) < (cp0.size.y + cp1.size.y) / 16) {
|
||||
// cp0's bottom side is colliding with cp1's top side
|
||||
if (cp0.velocity.y < 0) {
|
||||
// cp0 is going down, stop
|
||||
cp0.velocity.y = 0;
|
||||
if (!cp0.ghost && !cp1.ghost) {
|
||||
if (cp0.velocity.y < 0) {
|
||||
// cp0 is going down, stop
|
||||
cp0.velocity.y = 0;
|
||||
}
|
||||
cp0.grounded = true;
|
||||
cp0.position.y += y11 - y00;
|
||||
}
|
||||
cp0.grounded = true;
|
||||
cp0.position.y += y11 - y00;
|
||||
|
||||
if (cp0.collisionListener != null) {
|
||||
cp0.collisionListener.collision(CollisionSide.BOTTOM, entity0, entity1);
|
||||
@ -124,9 +130,11 @@ public class PhysicsSystem extends EntitySystem {
|
||||
}
|
||||
if (y01 > y10 && Math.abs(y01 - y10) < (cp0.size.y + cp1.size.y) / 16) {
|
||||
// cp0's top side is colliding with cp1's bottom side
|
||||
if (cp0.velocity.y > 0) {
|
||||
// cp0 is going up, stop
|
||||
cp0.velocity.y = 0;
|
||||
if (!cp0.ghost && !cp1.ghost) {
|
||||
if (cp0.velocity.y > 0) {
|
||||
// cp0 is going up, stop
|
||||
cp0.velocity.y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (cp0.collisionListener != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user