From 91135acfce0442dcf47dbfecef32348a94294185 Mon Sep 17 00:00:00 2001 From: Allexit Date: Thu, 9 Apr 2015 01:14:07 +0300 Subject: [PATCH] Position Component -> Physics Componenty --- .../src/com/saltosion/gladiator/GladiatorBrawler.java | 9 ++++----- .../com/saltosion/gladiator/components/CPhysics.java | 11 +++++++++++ .../com/saltosion/gladiator/components/CPosition.java | 10 ---------- .../saltosion/gladiator/systems/RenderingSystem.java | 10 +++++----- 4 files changed, 20 insertions(+), 20 deletions(-) create mode 100644 core/src/com/saltosion/gladiator/components/CPhysics.java delete mode 100644 core/src/com/saltosion/gladiator/components/CPosition.java diff --git a/core/src/com/saltosion/gladiator/GladiatorBrawler.java b/core/src/com/saltosion/gladiator/GladiatorBrawler.java index a736e3a..ae62529 100644 --- a/core/src/com/saltosion/gladiator/GladiatorBrawler.java +++ b/core/src/com/saltosion/gladiator/GladiatorBrawler.java @@ -7,7 +7,7 @@ import com.badlogic.ashley.core.Family; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.g2d.Sprite; -import com.saltosion.gladiator.components.CPosition; +import com.saltosion.gladiator.components.CPhysics; import com.saltosion.gladiator.components.CRenderedObject; import com.saltosion.gladiator.systems.RenderingSystem; import com.saltosion.gladiator.util.GlobalStrings; @@ -27,7 +27,7 @@ public class GladiatorBrawler extends ApplicationAdapter { engine.addSystem(new RenderingSystem()); - engine.addEntityListener(Family.getFor(CRenderedObject.class, CPosition.class), + engine.addEntityListener(Family.getFor(CRenderedObject.class, CPhysics.class), new EntityListener() { @Override public void entityRemoved(Entity entity) { @@ -72,9 +72,8 @@ public class GladiatorBrawler extends ApplicationAdapter { renderedObject.addSequence("Idle", sequence); renderedObject.setCurrentSequence("Idle"); player.add(renderedObject); - player.add(new CPosition()); - player.getComponent(CPosition.class).x = 50; - player.getComponent(CPosition.class).y = 50; + player.add(new CPhysics()); + player.getComponent(CPhysics.class).position.set(50, 50); engine.addEntity(player); } diff --git a/core/src/com/saltosion/gladiator/components/CPhysics.java b/core/src/com/saltosion/gladiator/components/CPhysics.java new file mode 100644 index 0000000..b4934ee --- /dev/null +++ b/core/src/com/saltosion/gladiator/components/CPhysics.java @@ -0,0 +1,11 @@ +package com.saltosion.gladiator.components; + +import com.badlogic.ashley.core.Component; +import com.badlogic.gdx.math.Vector2; + +public class CPhysics extends Component { + + public Vector2 position = new Vector2(0, 0); + public Vector2 velocity = new Vector2(0, 0); + +} diff --git a/core/src/com/saltosion/gladiator/components/CPosition.java b/core/src/com/saltosion/gladiator/components/CPosition.java deleted file mode 100644 index 35f79bd..0000000 --- a/core/src/com/saltosion/gladiator/components/CPosition.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.saltosion.gladiator.components; - -import com.badlogic.ashley.core.Component; - -public class CPosition extends Component { - - public int x = 0; - public int y = 0; - -} diff --git a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java index 37c5eae..40f4edc 100644 --- a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java +++ b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java @@ -12,13 +12,13 @@ import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.saltosion.gladiator.SpriteSequence; -import com.saltosion.gladiator.components.CPosition; +import com.saltosion.gladiator.components.CPhysics; import com.saltosion.gladiator.components.CRenderedObject; public class RenderingSystem extends EntitySystem { private ComponentMapper rom = ComponentMapper.getFor(CRenderedObject.class); - private ComponentMapper pm = ComponentMapper.getFor(CPosition.class); + private ComponentMapper pm = ComponentMapper.getFor(CPhysics.class); private ImmutableArray entities; private SpriteBatch batch; @@ -52,9 +52,9 @@ public class RenderingSystem extends EntitySystem { int currFrame = (int) Math.floor(renderedObject.getCurrentFrame()); Sprite currSprite = currSequence.getSprite(currFrame); - CPosition position = pm.get(entities.get(i)); + CPhysics physics = pm.get(entities.get(i)); - batch.draw(currSprite, position.x, position.y); + batch.draw(currSprite, physics.position.x, physics.position.y); float nextFrame = renderedObject.getCurrentFrame() + deltaTime*currSequence.getPlayspeed(); renderedObject.setCurrentFrame(nextFrame%currSequence.frameCount()); @@ -64,7 +64,7 @@ public class RenderingSystem extends EntitySystem { } public void updateEntities(Engine engine) { - entities = engine.getEntitiesFor(Family.getFor(CRenderedObject.class, CPosition.class)); + entities = engine.getEntitiesFor(Family.getFor(CRenderedObject.class, CPhysics.class)); } }