Position Component -> Physics Componenty
This commit is contained in:
parent
eff6647704
commit
91135acfce
@ -7,7 +7,7 @@ import com.badlogic.ashley.core.Family;
|
|||||||
import com.badlogic.gdx.ApplicationAdapter;
|
import com.badlogic.gdx.ApplicationAdapter;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
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.components.CRenderedObject;
|
||||||
import com.saltosion.gladiator.systems.RenderingSystem;
|
import com.saltosion.gladiator.systems.RenderingSystem;
|
||||||
import com.saltosion.gladiator.util.GlobalStrings;
|
import com.saltosion.gladiator.util.GlobalStrings;
|
||||||
@ -27,7 +27,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
|
|||||||
|
|
||||||
engine.addSystem(new RenderingSystem());
|
engine.addSystem(new RenderingSystem());
|
||||||
|
|
||||||
engine.addEntityListener(Family.getFor(CRenderedObject.class, CPosition.class),
|
engine.addEntityListener(Family.getFor(CRenderedObject.class, CPhysics.class),
|
||||||
new EntityListener() {
|
new EntityListener() {
|
||||||
@Override
|
@Override
|
||||||
public void entityRemoved(Entity entity) {
|
public void entityRemoved(Entity entity) {
|
||||||
@ -72,9 +72,8 @@ public class GladiatorBrawler extends ApplicationAdapter {
|
|||||||
renderedObject.addSequence("Idle", sequence);
|
renderedObject.addSequence("Idle", sequence);
|
||||||
renderedObject.setCurrentSequence("Idle");
|
renderedObject.setCurrentSequence("Idle");
|
||||||
player.add(renderedObject);
|
player.add(renderedObject);
|
||||||
player.add(new CPosition());
|
player.add(new CPhysics());
|
||||||
player.getComponent(CPosition.class).x = 50;
|
player.getComponent(CPhysics.class).position.set(50, 50);
|
||||||
player.getComponent(CPosition.class).y = 50;
|
|
||||||
|
|
||||||
engine.addEntity(player);
|
engine.addEntity(player);
|
||||||
}
|
}
|
||||||
|
11
core/src/com/saltosion/gladiator/components/CPhysics.java
Normal file
11
core/src/com/saltosion/gladiator/components/CPhysics.java
Normal 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);
|
||||||
|
|
||||||
|
}
|
@ -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;
|
|
||||||
|
|
||||||
}
|
|
@ -12,13 +12,13 @@ import com.badlogic.gdx.graphics.OrthographicCamera;
|
|||||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.saltosion.gladiator.SpriteSequence;
|
import com.saltosion.gladiator.SpriteSequence;
|
||||||
import com.saltosion.gladiator.components.CPosition;
|
import com.saltosion.gladiator.components.CPhysics;
|
||||||
import com.saltosion.gladiator.components.CRenderedObject;
|
import com.saltosion.gladiator.components.CRenderedObject;
|
||||||
|
|
||||||
public class RenderingSystem extends EntitySystem {
|
public class RenderingSystem extends EntitySystem {
|
||||||
|
|
||||||
private ComponentMapper<CRenderedObject> rom = ComponentMapper.getFor(CRenderedObject.class);
|
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 ImmutableArray<Entity> entities;
|
||||||
|
|
||||||
private SpriteBatch batch;
|
private SpriteBatch batch;
|
||||||
@ -52,9 +52,9 @@ public class RenderingSystem extends EntitySystem {
|
|||||||
int currFrame = (int) Math.floor(renderedObject.getCurrentFrame());
|
int currFrame = (int) Math.floor(renderedObject.getCurrentFrame());
|
||||||
Sprite currSprite = currSequence.getSprite(currFrame);
|
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();
|
float nextFrame = renderedObject.getCurrentFrame() + deltaTime*currSequence.getPlayspeed();
|
||||||
renderedObject.setCurrentFrame(nextFrame%currSequence.frameCount());
|
renderedObject.setCurrentFrame(nextFrame%currSequence.frameCount());
|
||||||
@ -64,7 +64,7 @@ public class RenderingSystem extends EntitySystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateEntities(Engine engine) {
|
public void updateEntities(Engine engine) {
|
||||||
entities = engine.getEntitiesFor(Family.getFor(CRenderedObject.class, CPosition.class));
|
entities = engine.getEntitiesFor(Family.getFor(CRenderedObject.class, CPhysics.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user