Changed a variable name and cleaned up CPhysics.
This commit is contained in:
parent
36e3214758
commit
07c2babe96
@ -101,7 +101,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
|
|||||||
Sprite groundSprite = SpriteLoader.loadSprite(Name.GROUNDIMG);
|
Sprite groundSprite = SpriteLoader.loadSprite(Name.GROUNDIMG);
|
||||||
CRenderedObject renderedObject = new CRenderedObject(groundSprite);
|
CRenderedObject renderedObject = new CRenderedObject(groundSprite);
|
||||||
ground.add(renderedObject);
|
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,
|
.setSize(groundSprite.getRegionWidth() * Global.SPRITE_SCALE,
|
||||||
groundSprite.getRegionHeight() * Global.SPRITE_SCALE);
|
groundSprite.getRegionHeight() * Global.SPRITE_SCALE);
|
||||||
physics.getPosition().set(new Vector2(0, -4));
|
physics.getPosition().set(new Vector2(0, -4));
|
||||||
@ -111,7 +111,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
|
|||||||
|
|
||||||
Entity wall0 = new Entity();
|
Entity wall0 = new Entity();
|
||||||
CRenderedObject wall0RenderedObject = new CRenderedObject(wallSprite);
|
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,
|
.setSize(wallSprite.getRegionWidth() * Global.SPRITE_SCALE,
|
||||||
wallSprite.getRegionHeight() * Global.SPRITE_SCALE);
|
wallSprite.getRegionHeight() * Global.SPRITE_SCALE);
|
||||||
wall0Physics.getPosition().set(new Vector2(6, 0));
|
wall0Physics.getPosition().set(new Vector2(6, 0));
|
||||||
@ -120,7 +120,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
|
|||||||
|
|
||||||
Entity wall1 = new Entity();
|
Entity wall1 = new Entity();
|
||||||
CRenderedObject wall1RenderedObject = new CRenderedObject(wallSprite);
|
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,
|
.setSize(wallSprite.getRegionWidth() * Global.SPRITE_SCALE,
|
||||||
wallSprite.getRegionHeight() * Global.SPRITE_SCALE);
|
wallSprite.getRegionHeight() * Global.SPRITE_SCALE);
|
||||||
wall1Physics.getPosition().set(new Vector2(-6, 0));
|
wall1Physics.getPosition().set(new Vector2(-6, 0));
|
||||||
|
@ -6,15 +6,15 @@ import com.saltosion.gladiator.util.CollisionListener;
|
|||||||
|
|
||||||
public class CPhysics extends Component {
|
public class CPhysics extends Component {
|
||||||
|
|
||||||
private Vector2 position = new Vector2();
|
private final Vector2 position = new Vector2();
|
||||||
private Vector2 velocity = new Vector2();
|
private final Vector2 velocity = new Vector2();
|
||||||
private Vector2 size = new Vector2();
|
private final Vector2 size = new Vector2();
|
||||||
private float movespeed = 5f, jumpForce = 0.5f, gravity = 1f;
|
private float movespeed = 5f, jumpForce = 0.5f, gravity = 1f;
|
||||||
private CollisionListener collisionListener = null;
|
private CollisionListener collisionListener = null;
|
||||||
|
|
||||||
private boolean movable = true;
|
private boolean movable = true;
|
||||||
private boolean gravityApplied = true;
|
private boolean gravityApplied = true;
|
||||||
private boolean dynamic = true;
|
private boolean processCollisions = true;
|
||||||
private boolean ghost = false;
|
private boolean ghost = false;
|
||||||
private boolean grounded = true;
|
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
|
* @return Returns the instance this methdod was called from
|
||||||
*/
|
*/
|
||||||
public CPhysics setDynamic(boolean dynamic) {
|
public CPhysics setProcessCollisions(boolean processCollisions) {
|
||||||
this.dynamic = dynamic;
|
this.processCollisions = processCollisions;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ public class CPhysics extends Component {
|
|||||||
this.size.set(w, h);
|
this.size.set(w, h);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CPhysics setSize(Vector2 size) {
|
public CPhysics setSize(Vector2 size) {
|
||||||
this.size.set(size);
|
this.size.set(size);
|
||||||
return this;
|
return this;
|
||||||
@ -74,66 +74,82 @@ public class CPhysics extends Component {
|
|||||||
this.position.set(x, y);
|
this.position.set(x, y);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CPhysics setPosition(Vector2 pos) {
|
public CPhysics setPosition(Vector2 pos) {
|
||||||
this.position.set(pos);
|
this.position.set(pos);
|
||||||
return this;
|
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) {
|
public CPhysics setCollisionListener(CollisionListener collisionListener) {
|
||||||
this.collisionListener = collisionListener;
|
this.collisionListener = collisionListener;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CPhysics setGrounded(boolean grounded) {
|
public CPhysics setGrounded(boolean grounded) {
|
||||||
this.grounded = grounded;
|
this.grounded = grounded;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2 getPosition() {
|
public Vector2 getPosition() {
|
||||||
return this.position;
|
return this.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2 getVelocity() {
|
public Vector2 getVelocity() {
|
||||||
return this.velocity;
|
return this.velocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2 getSize() {
|
public Vector2 getSize() {
|
||||||
return this.size;
|
return this.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getMovespeed() {
|
public float getMovespeed() {
|
||||||
return this.movespeed;
|
return this.movespeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getJumpForce() {
|
public float getJumpForce() {
|
||||||
return this.jumpForce;
|
return this.jumpForce;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getGravity() {
|
public float getGravity() {
|
||||||
return this.gravity;
|
return this.gravity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CollisionListener getCollisionListener() {
|
public CollisionListener getCollisionListener() {
|
||||||
return this.collisionListener;
|
return this.collisionListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMovable() {
|
public boolean isMovable() {
|
||||||
return this.movable;
|
return this.movable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGravityApplied() {
|
public boolean isGravityApplied() {
|
||||||
return this.gravityApplied;
|
return this.gravityApplied;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDynamic() {
|
public boolean isProcessCollisions() {
|
||||||
return this.dynamic;
|
return this.processCollisions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGhost() {
|
public boolean isGhost() {
|
||||||
return this.ghost;
|
return this.ghost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGrounded() {
|
public boolean isGrounded() {
|
||||||
return this.grounded;
|
return this.grounded;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ public class PhysicsSystem extends EntitySystem {
|
|||||||
obj.getVelocity().y = Math.max(Math.min(obj.getVelocity().y, MAX_VEL), -MAX_VEL);
|
obj.getVelocity().y = Math.max(Math.min(obj.getVelocity().y, MAX_VEL), -MAX_VEL);
|
||||||
|
|
||||||
// Collisions
|
// Collisions
|
||||||
if (obj.isDynamic()) {
|
if (obj.isProcessCollisions()) {
|
||||||
for (int j = 0; j < entities.size(); j++) {
|
for (int j = 0; j < entities.size(); j++) {
|
||||||
if (i == j) {
|
if (i == j) {
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user