Position Component -> Physics Componenty

This commit is contained in:
Allexit 2015-04-09 01:14:07 +03:00
parent eff6647704
commit 91135acfce
4 changed files with 20 additions and 20 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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<CRenderedObject> rom = ComponentMapper.getFor(CRenderedObject.class);
private ComponentMapper<CPosition> pm = ComponentMapper.getFor(CPosition.class);
private ComponentMapper<CPhysics> pm = ComponentMapper.getFor(CPhysics.class);
private ImmutableArray<Entity> 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));
}
}