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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +80,22 @@ public class CPhysics extends Component {
|
|||||||
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;
|
||||||
@ -126,8 +142,8 @@ public class CPhysics extends Component {
|
|||||||
return this.gravityApplied;
|
return this.gravityApplied;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDynamic() {
|
public boolean isProcessCollisions() {
|
||||||
return this.dynamic;
|
return this.processCollisions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGhost() {
|
public boolean isGhost() {
|
||||||
|
@ -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