Changed a variable name and cleaned up CPhysics.

This commit is contained in:
Jeasonfire 2015-05-10 20:42:18 +03:00
parent 36e3214758
commit 07c2babe96
3 changed files with 44 additions and 28 deletions

View File

@ -101,7 +101,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
Sprite groundSprite = SpriteLoader.loadSprite(Name.GROUNDIMG);
CRenderedObject renderedObject = new CRenderedObject(groundSprite);
ground.add(renderedObject);
CPhysics physics = new CPhysics().setMovable(false).setGravityApplied(false).setDynamic(false)
CPhysics physics = new CPhysics().setMovable(false).setGravityApplied(false).setProcessCollisions(false)
.setSize(groundSprite.getRegionWidth() * Global.SPRITE_SCALE,
groundSprite.getRegionHeight() * Global.SPRITE_SCALE);
physics.getPosition().set(new Vector2(0, -4));
@ -111,7 +111,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
Entity wall0 = new Entity();
CRenderedObject wall0RenderedObject = new CRenderedObject(wallSprite);
CPhysics wall0Physics = new CPhysics().setMovable(false).setGravityApplied(false).setDynamic(false)
CPhysics wall0Physics = new CPhysics().setMovable(false).setGravityApplied(false).setProcessCollisions(false)
.setSize(wallSprite.getRegionWidth() * Global.SPRITE_SCALE,
wallSprite.getRegionHeight() * Global.SPRITE_SCALE);
wall0Physics.getPosition().set(new Vector2(6, 0));
@ -120,7 +120,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
Entity wall1 = new Entity();
CRenderedObject wall1RenderedObject = new CRenderedObject(wallSprite);
CPhysics wall1Physics = new CPhysics().setMovable(false).setGravityApplied(false).setDynamic(false)
CPhysics wall1Physics = new CPhysics().setMovable(false).setGravityApplied(false).setProcessCollisions(false)
.setSize(wallSprite.getRegionWidth() * Global.SPRITE_SCALE,
wallSprite.getRegionHeight() * Global.SPRITE_SCALE);
wall1Physics.getPosition().set(new Vector2(-6, 0));

View File

@ -6,15 +6,15 @@ import com.saltosion.gladiator.util.CollisionListener;
public class CPhysics extends Component {
private Vector2 position = new Vector2();
private Vector2 velocity = new Vector2();
private Vector2 size = new Vector2();
private final Vector2 position = new Vector2();
private final Vector2 velocity = new Vector2();
private final Vector2 size = new Vector2();
private float movespeed = 5f, jumpForce = 0.5f, gravity = 1f;
private CollisionListener collisionListener = null;
private boolean movable = true;
private boolean gravityApplied = true;
private boolean dynamic = true;
private boolean processCollisions = true;
private boolean ghost = false;
private boolean grounded = true;
@ -42,11 +42,11 @@ public class CPhysics extends Component {
}
/**
* @param dynamic Toggles if the entity processes collisions
* @param processCollisions Toggles if the entity processes collisions
* @return Returns the instance this methdod was called from
*/
public CPhysics setDynamic(boolean dynamic) {
this.dynamic = dynamic;
public CPhysics setProcessCollisions(boolean processCollisions) {
this.processCollisions = processCollisions;
return this;
}
@ -80,6 +80,22 @@ public class CPhysics extends Component {
return this;
}
public CPhysics setMoveSpeed(float movespeed) {
this.movespeed = movespeed;
return this;
}
public CPhysics setJumpForce(float jumpForce) {
this.jumpForce = jumpForce;
return this;
}
public CPhysics setGravity(float gravity) {
this.gravity = gravity;
return this;
}
public CPhysics setCollisionListener(CollisionListener collisionListener) {
this.collisionListener = collisionListener;
return this;
@ -126,8 +142,8 @@ public class CPhysics extends Component {
return this.gravityApplied;
}
public boolean isDynamic() {
return this.dynamic;
public boolean isProcessCollisions() {
return this.processCollisions;
}
public boolean isGhost() {

View File

@ -57,7 +57,7 @@ public class PhysicsSystem extends EntitySystem {
obj.getVelocity().y = Math.max(Math.min(obj.getVelocity().y, MAX_VEL), -MAX_VEL);
// Collisions
if (obj.isDynamic()) {
if (obj.isProcessCollisions()) {
for (int j = 0; j < entities.size(); j++) {
if (i == j) {
continue;