From 07c2babe96727839099748146c5fa540d44d4bf5 Mon Sep 17 00:00:00 2001 From: Jeasonfire Date: Sun, 10 May 2015 20:42:18 +0300 Subject: [PATCH] Changed a variable name and cleaned up CPhysics. --- .../saltosion/gladiator/GladiatorBrawler.java | 6 +- .../gladiator/components/CPhysics.java | 64 ++++++++++++------- .../gladiator/systems/PhysicsSystem.java | 2 +- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/core/src/com/saltosion/gladiator/GladiatorBrawler.java b/core/src/com/saltosion/gladiator/GladiatorBrawler.java index 9542e30..9f9bab5 100644 --- a/core/src/com/saltosion/gladiator/GladiatorBrawler.java +++ b/core/src/com/saltosion/gladiator/GladiatorBrawler.java @@ -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)); diff --git a/core/src/com/saltosion/gladiator/components/CPhysics.java b/core/src/com/saltosion/gladiator/components/CPhysics.java index 51571b0..f20c462 100644 --- a/core/src/com/saltosion/gladiator/components/CPhysics.java +++ b/core/src/com/saltosion/gladiator/components/CPhysics.java @@ -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; } @@ -64,7 +64,7 @@ public class CPhysics extends Component { this.size.set(w, h); return this; } - + public CPhysics setSize(Vector2 size) { this.size.set(size); return this; @@ -74,66 +74,82 @@ public class CPhysics extends Component { this.position.set(x, y); return this; } - + public CPhysics setPosition(Vector2 pos) { this.position.set(pos); 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; } - + public CPhysics setGrounded(boolean grounded) { this.grounded = grounded; return this; } - + public Vector2 getPosition() { return this.position; } - + public Vector2 getVelocity() { return this.velocity; } - + public Vector2 getSize() { return this.size; } - + public float getMovespeed() { return this.movespeed; } - + public float getJumpForce() { return this.jumpForce; } - + public float getGravity() { return this.gravity; } - + public CollisionListener getCollisionListener() { return this.collisionListener; } - + public boolean isMovable() { return this.movable; } - + public boolean isGravityApplied() { return this.gravityApplied; } - - public boolean isDynamic() { - return this.dynamic; + + public boolean isProcessCollisions() { + return this.processCollisions; } - + public boolean isGhost() { return this.ghost; } - + public boolean isGrounded() { return this.grounded; } diff --git a/core/src/com/saltosion/gladiator/systems/PhysicsSystem.java b/core/src/com/saltosion/gladiator/systems/PhysicsSystem.java index 68a607c..b14fedc 100644 --- a/core/src/com/saltosion/gladiator/systems/PhysicsSystem.java +++ b/core/src/com/saltosion/gladiator/systems/PhysicsSystem.java @@ -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;