diff --git a/core/src/com/saltosion/gladiator/GladiatorBrawler.java b/core/src/com/saltosion/gladiator/GladiatorBrawler.java index 908f2cf..88c13de 100644 --- a/core/src/com/saltosion/gladiator/GladiatorBrawler.java +++ b/core/src/com/saltosion/gladiator/GladiatorBrawler.java @@ -8,17 +8,9 @@ import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.math.Vector2; -import com.badlogic.gdx.physics.box2d.Body; -import com.badlogic.gdx.physics.box2d.BodyDef; -import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; -import com.badlogic.gdx.physics.box2d.Fixture; -import com.badlogic.gdx.physics.box2d.FixtureDef; -import com.badlogic.gdx.physics.box2d.PolygonShape; -import com.badlogic.gdx.physics.box2d.World; import com.saltosion.gladiator.components.CPhysics; import com.saltosion.gladiator.components.CRenderedObject; import com.saltosion.gladiator.input.InputHandler; -import com.saltosion.gladiator.systems.MovementSystem; import com.saltosion.gladiator.systems.RenderingSystem; import com.saltosion.gladiator.util.AppUtil; import com.saltosion.gladiator.util.Name; @@ -28,7 +20,6 @@ import com.saltosion.gladiator.util.SpriteSequence; public class GladiatorBrawler extends ApplicationAdapter { private Engine engine; - private World world; private InputHandler inputHandler; private float physics_accumulator = 0f; @@ -36,17 +27,13 @@ public class GladiatorBrawler extends ApplicationAdapter { private Entity player; @Override - public void create () { - // Initializing Physics - - world = new World(new Vector2(0, -10), true); + public void create () { // Initialize the Engine engine = new Engine(); - engine.addSystem(new RenderingSystem(world)); - engine.addSystem(new MovementSystem()); + engine.addSystem(new RenderingSystem()); engine.addEntityListener(Family.getFor(), new EntityListener() { @@ -54,16 +41,12 @@ public class GladiatorBrawler extends ApplicationAdapter { public void entityRemoved(Entity entity) { RenderingSystem rs = engine.getSystem(RenderingSystem.class); rs.updateEntities(engine); - MovementSystem ms = engine.getSystem(MovementSystem.class); - ms.updateEntities(engine); } @Override public void entityAdded(Entity entity) { RenderingSystem rs = engine.getSystem(RenderingSystem.class); rs.updateEntities(engine); - MovementSystem ms = engine.getSystem(MovementSystem.class); - ms.updateEntities(engine); } }); @@ -72,7 +55,6 @@ public class GladiatorBrawler extends ApplicationAdapter { // Initialize stuff in the world initializePlayer(); - initializeTerrain(); // Initialize input @@ -83,45 +65,9 @@ public class GladiatorBrawler extends ApplicationAdapter { @Override public void render () { engine.update(Gdx.graphics.getDeltaTime()); - physicsStep(Gdx.graphics.getDeltaTime()); - } - - private void physicsStep(float deltaTime) { - float frameTime = Math.max(deltaTime, 0.25f); - physics_accumulator += frameTime; - if (physics_accumulator >= AppUtil.PHYSICS_TIMESTEP) { - world.step(AppUtil.PHYSICS_TIMESTEP, 6, 2); - physics_accumulator -= AppUtil.PHYSICS_TIMESTEP; - } } public void initializePlayer() { - BodyDef bodyDef = new BodyDef(); - bodyDef.type = BodyType.DynamicBody; - bodyDef.position.set(5, 5); - bodyDef.fixedRotation = true; - Body body = world.createBody(bodyDef); - - PolygonShape bottomBox = new PolygonShape(); - bottomBox.setAsBox(1.95f, .5f, new Vector2(0, -1.5f), 0); - - FixtureDef bottomDef = new FixtureDef(); - bottomDef.shape = bottomBox; - bottomDef.density = 75f; - bottomDef.friction = 7f; - Fixture bottom = body.createFixture(bottomDef); - - PolygonShape topBox = new PolygonShape(); - topBox.setAsBox(2, 1.5f, new Vector2(0, .5f), 0); - - FixtureDef topDef = new FixtureDef(); - topDef.shape = topBox; - topDef.density = 75f; - topDef.friction = 0f; - Fixture top = body.createFixture(topDef); - - bottomBox.dispose(); - topBox.dispose(); player = new Entity(); @@ -133,22 +79,12 @@ public class GladiatorBrawler extends ApplicationAdapter { renderedObject.playAnimation("Idle"); player.add(renderedObject); player.add(new CPhysics()); - player.getComponent(CPhysics.class).body = body; engine.addEntity(player); AppUtil.player = player; } - public void initializeTerrain() { - BodyDef terrain = new BodyDef(); - Body terrainBody = world.createBody(terrain); - PolygonShape terrainBox = new PolygonShape(); - terrainBox.setAsBox(20, 2); - terrainBody.createFixture(terrainBox, 0); - terrainBox.dispose(); - } - @Override public void resize(int width, int height) { super.resize(width, height); diff --git a/core/src/com/saltosion/gladiator/components/CPhysics.java b/core/src/com/saltosion/gladiator/components/CPhysics.java index 6104008..71fbbde 100644 --- a/core/src/com/saltosion/gladiator/components/CPhysics.java +++ b/core/src/com/saltosion/gladiator/components/CPhysics.java @@ -2,14 +2,13 @@ package com.saltosion.gladiator.components; import com.badlogic.ashley.core.Component; import com.badlogic.gdx.math.Vector2; -import com.badlogic.gdx.physics.box2d.Body; public class CPhysics extends Component { - public Body body; - + public Vector2 position = new Vector2(0, 0); public Vector2 velocity = new Vector2(0, 0); public boolean movingLeft = false; public boolean movingRight = false; - + public boolean jumping = false; + public boolean grounded = true; } diff --git a/core/src/com/saltosion/gladiator/input/IRJump.java b/core/src/com/saltosion/gladiator/input/IRJump.java new file mode 100644 index 0000000..6a926c5 --- /dev/null +++ b/core/src/com/saltosion/gladiator/input/IRJump.java @@ -0,0 +1,23 @@ +package com.saltosion.gladiator.input; + +import com.saltosion.gladiator.components.CPhysics; +import com.saltosion.gladiator.util.AppUtil; + +public class IRJump implements InputReceiver { + + @Override + public boolean pressed() { + CPhysics physics = AppUtil.player.getComponent(CPhysics.class); + physics.jumping = true; + return true; + } + + @Override + public boolean released() { + CPhysics physics = AppUtil.player.getComponent(CPhysics.class); + physics.jumping = false; + physics.grounded = true; + return true; + } + +} diff --git a/core/src/com/saltosion/gladiator/input/InputHandler.java b/core/src/com/saltosion/gladiator/input/InputHandler.java index 60f4816..72a683a 100644 --- a/core/src/com/saltosion/gladiator/input/InputHandler.java +++ b/core/src/com/saltosion/gladiator/input/InputHandler.java @@ -13,6 +13,7 @@ public class InputHandler implements InputProcessor { public InputHandler() { keys.put(Keys.A, Name.MOVE_LEFT); keys.put(Keys.D, Name.MOVE_RIGHT); + keys.put(Keys.SPACE, Name.JUMP); } @Override diff --git a/core/src/com/saltosion/gladiator/input/InputReceivers.java b/core/src/com/saltosion/gladiator/input/InputReceivers.java index 260df8c..fdb0f5c 100644 --- a/core/src/com/saltosion/gladiator/input/InputReceivers.java +++ b/core/src/com/saltosion/gladiator/input/InputReceivers.java @@ -10,6 +10,7 @@ public class InputReceivers { static { inputreceivers.put(Name.MOVE_LEFT, new IRMoveLeft()); inputreceivers.put(Name.MOVE_RIGHT, new IRMoveRight()); + inputreceivers.put(Name.JUMP, new IRJump()); } public static InputReceiver getReceiver(String key) { diff --git a/core/src/com/saltosion/gladiator/systems/MovementSystem.java b/core/src/com/saltosion/gladiator/systems/MovementSystem.java deleted file mode 100644 index 25a0a6c..0000000 --- a/core/src/com/saltosion/gladiator/systems/MovementSystem.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.saltosion.gladiator.systems; - -import com.badlogic.ashley.core.ComponentMapper; -import com.badlogic.ashley.core.Engine; -import com.badlogic.ashley.core.Entity; -import com.badlogic.ashley.core.EntitySystem; -import com.badlogic.ashley.core.Family; -import com.badlogic.ashley.utils.ImmutableArray; -import com.badlogic.gdx.math.Vector2; -import com.saltosion.gladiator.components.CPhysics; - -public class MovementSystem extends EntitySystem { - - private ComponentMapper pm = ComponentMapper.getFor(CPhysics.class); - private ImmutableArray entities; - - private final Vector2 RIGHT = new Vector2(1, 0); - private final float MOVEMENT_SPEED = 850; - private final float MAX_MOVEMENT_SPEED = 10; - - private Vector2 newVel = new Vector2(0, 0); - private Vector2 bodyVel = new Vector2(0, 0); - - @Override - public void addedToEngine(Engine engine) { - updateEntities(engine); - } - - @Override - public void update(float deltaTime) { - for (int i=0; i