Jumping implemented.
This commit is contained in:
parent
47eb5f5702
commit
d961bd21de
@ -102,7 +102,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
|
||||
CPhysics physics = new CPhysics().setMovable(false).setGravityApplied(false)
|
||||
.setSize(groundSprite.getRegionWidth() * Global.SPRITE_SCALE,
|
||||
groundSprite.getRegionHeight() * Global.SPRITE_SCALE);
|
||||
physics.position.set(new Vector2(-2.5f, -5));
|
||||
physics.position.set(new Vector2(0, -4));
|
||||
ground.add(physics);
|
||||
|
||||
Sprite wallSprite = SpriteLoader.loadSprite(Name.WALLIMG, 0, 0, 64, 64);
|
||||
@ -112,7 +112,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
|
||||
CPhysics wall0Physics = new CPhysics().setMovable(false).setGravityApplied(false)
|
||||
.setSize(wallSprite.getRegionWidth() * Global.SPRITE_SCALE,
|
||||
wallSprite.getRegionHeight() * Global.SPRITE_SCALE);
|
||||
wall0Physics.position.set(new Vector2(5, 0));
|
||||
wall0Physics.position.set(new Vector2(6, 0));
|
||||
wall0.add(wall0RenderedObject);
|
||||
wall0.add(wall0Physics);
|
||||
|
||||
@ -121,7 +121,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
|
||||
CPhysics wall1Physics = new CPhysics().setMovable(false).setGravityApplied(false)
|
||||
.setSize(wallSprite.getRegionWidth() * Global.SPRITE_SCALE,
|
||||
wallSprite.getRegionHeight() * Global.SPRITE_SCALE);
|
||||
wall1Physics.position.set(new Vector2(-5, 0));
|
||||
wall1Physics.position.set(new Vector2(-6, 0));
|
||||
wall1.add(wall1RenderedObject);
|
||||
wall1.add(wall1Physics);
|
||||
|
||||
|
@ -8,7 +8,7 @@ public class CPhysics extends Component {
|
||||
public Vector2 position = new Vector2();
|
||||
public Vector2 velocity = new Vector2();
|
||||
public Vector2 size = new Vector2();
|
||||
public float movespeed = 5f, jumpForce = 5f, gravity = 1f;
|
||||
public float movespeed = 5f, jumpForce = 0.3f, gravity = 1f;
|
||||
public boolean grounded = true;
|
||||
|
||||
// Movable toggles if the entity can move by itself
|
||||
|
@ -37,7 +37,8 @@ public class PhysicsSystem extends EntitySystem {
|
||||
move++;
|
||||
}
|
||||
obj.velocity.x = move * obj.movespeed * deltaTime;
|
||||
if (obj.jumping) {
|
||||
if (obj.jumping && obj.grounded) {
|
||||
obj.grounded = false;
|
||||
obj.velocity.y = obj.jumpForce;
|
||||
}
|
||||
}
|
||||
@ -72,8 +73,6 @@ public class PhysicsSystem extends EntitySystem {
|
||||
float y01 = cp0.position.y + cp0.size.y / 2;
|
||||
float y10 = cp1.position.y - cp1.size.y / 2;
|
||||
float y11 = cp1.position.y + cp1.size.y / 2;
|
||||
cp0.grounded = false;
|
||||
cp1.grounded = false;
|
||||
|
||||
boolean colliding = (x00 < x11) && (x01 > x10) && (y00 < y11) && (y01 > y10);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user