Compare commits
No commits in common. "dev" and "grouping" have entirely different histories.
@ -2,9 +2,9 @@ package com.me.asteroids;
|
|||||||
|
|
||||||
import com.me.asteroids.components.AccelerationComponent;
|
import com.me.asteroids.components.AccelerationComponent;
|
||||||
import com.me.asteroids.components.AsteroidComponent;
|
import com.me.asteroids.components.AsteroidComponent;
|
||||||
import com.me.asteroids.components.BulletTagComponent;
|
import com.me.asteroids.components.BulletComponent;
|
||||||
import com.me.asteroids.components.ColliderTagComponent;
|
import com.me.asteroids.components.ColliderComponent;
|
||||||
import com.me.asteroids.components.DebrisTagComponent;
|
import com.me.asteroids.components.DebrisComponent;
|
||||||
import com.me.asteroids.components.DecayComponent;
|
import com.me.asteroids.components.DecayComponent;
|
||||||
import com.me.asteroids.components.GameDataComponent;
|
import com.me.asteroids.components.GameDataComponent;
|
||||||
import com.me.asteroids.components.ModelComponent;
|
import com.me.asteroids.components.ModelComponent;
|
||||||
@ -17,9 +17,9 @@ public class Components {
|
|||||||
|
|
||||||
public static final ComponentMapper<AccelerationComponent> ACCELERATION;
|
public static final ComponentMapper<AccelerationComponent> ACCELERATION;
|
||||||
public static final ComponentMapper<AsteroidComponent> ASTEROID;
|
public static final ComponentMapper<AsteroidComponent> ASTEROID;
|
||||||
public static final ComponentMapper<BulletTagComponent> BULLET;
|
public static final ComponentMapper<BulletComponent> BULLET;
|
||||||
public static final ComponentMapper<ColliderTagComponent> COLLIDER;
|
public static final ComponentMapper<ColliderComponent> COLLIDER;
|
||||||
public static final ComponentMapper<DebrisTagComponent> DEBRIS;
|
public static final ComponentMapper<DebrisComponent> DEBRIS;
|
||||||
public static final ComponentMapper<DecayComponent> DECAY;
|
public static final ComponentMapper<DecayComponent> DECAY;
|
||||||
public static final ComponentMapper<GameDataComponent> GAME_DATA;
|
public static final ComponentMapper<GameDataComponent> GAME_DATA;
|
||||||
public static final ComponentMapper<ModelComponent> MODEL;
|
public static final ComponentMapper<ModelComponent> MODEL;
|
||||||
@ -31,9 +31,9 @@ public class Components {
|
|||||||
static {
|
static {
|
||||||
ACCELERATION = ComponentMapper.getFor(AccelerationComponent.class);
|
ACCELERATION = ComponentMapper.getFor(AccelerationComponent.class);
|
||||||
ASTEROID = ComponentMapper.getFor(AsteroidComponent.class);
|
ASTEROID = ComponentMapper.getFor(AsteroidComponent.class);
|
||||||
BULLET = ComponentMapper.getFor(BulletTagComponent.class);
|
BULLET = ComponentMapper.getFor(BulletComponent.class);
|
||||||
COLLIDER = ComponentMapper.getFor(ColliderTagComponent.class);
|
COLLIDER = ComponentMapper.getFor(ColliderComponent.class);
|
||||||
DEBRIS = ComponentMapper.getFor(DebrisTagComponent.class);
|
DEBRIS = ComponentMapper.getFor(DebrisComponent.class);
|
||||||
DECAY = ComponentMapper.getFor(DecayComponent.class);
|
DECAY = ComponentMapper.getFor(DecayComponent.class);
|
||||||
GAME_DATA = ComponentMapper.getFor(GameDataComponent.class);
|
GAME_DATA = ComponentMapper.getFor(GameDataComponent.class);
|
||||||
MODEL = ComponentMapper.getFor(ModelComponent.class);
|
MODEL = ComponentMapper.getFor(ModelComponent.class);
|
||||||
|
@ -5,9 +5,9 @@ import com.badlogic.gdx.math.MathUtils;
|
|||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.me.asteroids.components.AccelerationComponent;
|
import com.me.asteroids.components.AccelerationComponent;
|
||||||
import com.me.asteroids.components.AsteroidComponent;
|
import com.me.asteroids.components.AsteroidComponent;
|
||||||
import com.me.asteroids.components.BulletTagComponent;
|
import com.me.asteroids.components.BulletComponent;
|
||||||
import com.me.asteroids.components.ColliderTagComponent;
|
import com.me.asteroids.components.ColliderComponent;
|
||||||
import com.me.asteroids.components.DebrisTagComponent;
|
import com.me.asteroids.components.DebrisComponent;
|
||||||
import com.me.asteroids.components.DecayComponent;
|
import com.me.asteroids.components.DecayComponent;
|
||||||
import com.me.asteroids.components.ModelComponent;
|
import com.me.asteroids.components.ModelComponent;
|
||||||
import com.me.asteroids.components.PlayerComponent;
|
import com.me.asteroids.components.PlayerComponent;
|
||||||
@ -34,9 +34,8 @@ public class EntityFactory {
|
|||||||
private static final Vector2 tmpA = new Vector2();
|
private static final Vector2 tmpA = new Vector2();
|
||||||
private static final Vector2 tmpB = new Vector2();
|
private static final Vector2 tmpB = new Vector2();
|
||||||
|
|
||||||
private static final ColliderTagComponent COLLIDER_TAG = new ColliderTagComponent();
|
private static final ColliderComponent COLLIDER = new ColliderComponent();
|
||||||
private static final DebrisTagComponent DEBRIS_TAG = new DebrisTagComponent();
|
private static final DebrisComponent DEBRIS = new DebrisComponent();
|
||||||
private static final BulletTagComponent BULLET_TAG = new BulletTagComponent();
|
|
||||||
|
|
||||||
private static Entity createEntity(Engine engine) {
|
private static Entity createEntity(Engine engine) {
|
||||||
Entity entity = engine.createEntity();
|
Entity entity = engine.createEntity();
|
||||||
@ -47,7 +46,7 @@ public class EntityFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Entity createPlayer(Engine engine) {
|
public static Entity createPlayer(Engine engine) {
|
||||||
VelocityComponent velocity = new VelocityComponent(0f, 0f, 0f);
|
VelocityComponent velocity = new VelocityComponent(0f, 0f, 0f, 10f);
|
||||||
|
|
||||||
ModelComponent playerModel = new ModelComponent(new PolygonModel(Color.WHITE));
|
ModelComponent playerModel = new ModelComponent(new PolygonModel(Color.WHITE));
|
||||||
playerModel.setVertices(new float[]{
|
playerModel.setVertices(new float[]{
|
||||||
@ -58,7 +57,7 @@ public class EntityFactory {
|
|||||||
5/16f, -0.5f, // bottom right
|
5/16f, -0.5f, // bottom right
|
||||||
});
|
});
|
||||||
|
|
||||||
ModelComponent afterburnerModel = new ModelComponent(new LineModel(Color.CYAN));
|
ModelComponent afterburnerModel = new ModelComponent(new LineModel(Color.BLUE));
|
||||||
afterburnerModel.setVertices(new float[]{
|
afterburnerModel.setVertices(new float[]{
|
||||||
-2/16f, -5/16f,
|
-2/16f, -5/16f,
|
||||||
0f, -0.8f,
|
0f, -0.8f,
|
||||||
@ -71,8 +70,8 @@ public class EntityFactory {
|
|||||||
player.addComponent(new PositionComponent(Constants.HALF_WIDTH, Constants.HALF_HEIGHT, 90));
|
player.addComponent(new PositionComponent(Constants.HALF_WIDTH, Constants.HALF_HEIGHT, 90));
|
||||||
player.addComponent(velocity);
|
player.addComponent(velocity);
|
||||||
player.addComponent(playerModel);
|
player.addComponent(playerModel);
|
||||||
player.addComponent(new AccelerationComponent(10f));
|
player.addComponent(new AccelerationComponent(0f, 1f));
|
||||||
player.addComponent(COLLIDER_TAG);
|
player.addComponent(COLLIDER);
|
||||||
player.addComponent(new PlayerComponent(afterBurner));
|
player.addComponent(new PlayerComponent(afterBurner));
|
||||||
player.setTag("PLAYER");
|
player.setTag("PLAYER");
|
||||||
|
|
||||||
@ -136,7 +135,7 @@ public class EntityFactory {
|
|||||||
debris.addComponent(new PositionComponent(new Vector2(model.getPosition()), 90));
|
debris.addComponent(new PositionComponent(new Vector2(model.getPosition()), 90));
|
||||||
debris.addComponent(velocity);
|
debris.addComponent(velocity);
|
||||||
debris.addComponent(model);
|
debris.addComponent(model);
|
||||||
debris.addComponent(DEBRIS_TAG);
|
debris.addComponent(DEBRIS);
|
||||||
debris.addComponent(new DecayComponent(rand.nextFloat(0.5f, 2.5f)));
|
debris.addComponent(new DecayComponent(rand.nextFloat(0.5f, 2.5f)));
|
||||||
entities[i] = debris;
|
entities[i] = debris;
|
||||||
}
|
}
|
||||||
@ -145,8 +144,8 @@ public class EntityFactory {
|
|||||||
|
|
||||||
|
|
||||||
public static Entity createBullet(Engine engine, Entity player) {
|
public static Entity createBullet(Engine engine, Entity player) {
|
||||||
float[] modelVertices = MODEL.get(player).model.getVertices();
|
float[] modelVertices = player.getComponent(ModelComponent.class).model.getVertices();
|
||||||
float rotation = POSITION.get(player).rotation;
|
float rotation = player.getComponent(PositionComponent.class).rotation;
|
||||||
|
|
||||||
PositionComponent position = new PositionComponent(modelVertices[0], modelVertices[1], rotation);
|
PositionComponent position = new PositionComponent(modelVertices[0], modelVertices[1], rotation);
|
||||||
ModelComponent model = new ModelComponent(new PolygonModel(Color.YELLOW));
|
ModelComponent model = new ModelComponent(new PolygonModel(Color.YELLOW));
|
||||||
@ -165,8 +164,8 @@ public class EntityFactory {
|
|||||||
bullet.addComponent(position);
|
bullet.addComponent(position);
|
||||||
bullet.addComponent(new VelocityComponent(new Vector2(direction).scl(12.5f)));
|
bullet.addComponent(new VelocityComponent(new Vector2(direction).scl(12.5f)));
|
||||||
bullet.addComponent(model);
|
bullet.addComponent(model);
|
||||||
bullet.addComponent(COLLIDER_TAG);
|
bullet.addComponent(COLLIDER);
|
||||||
bullet.addComponent(BULLET_TAG);
|
bullet.addComponent(new BulletComponent());
|
||||||
return bullet;
|
return bullet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +185,7 @@ public class EntityFactory {
|
|||||||
asteroid.addComponent(new PositionComponent());
|
asteroid.addComponent(new PositionComponent());
|
||||||
asteroid.addComponent(new VelocityComponent());
|
asteroid.addComponent(new VelocityComponent());
|
||||||
asteroid.addComponent(model);
|
asteroid.addComponent(model);
|
||||||
asteroid.addComponent(COLLIDER_TAG);
|
asteroid.addComponent(COLLIDER);
|
||||||
asteroid.addComponent(new AsteroidComponent());
|
asteroid.addComponent(new AsteroidComponent());
|
||||||
asteroid.addGroup("ASTEROIDS");
|
asteroid.addGroup("ASTEROIDS");
|
||||||
return asteroid;
|
return asteroid;
|
||||||
@ -232,7 +231,7 @@ public class EntityFactory {
|
|||||||
split.addComponent(new PositionComponent(new Vector2(chunkPosition), 90));
|
split.addComponent(new PositionComponent(new Vector2(chunkPosition), 90));
|
||||||
split.addComponent(velocity);
|
split.addComponent(velocity);
|
||||||
split.addComponent(new AsteroidComponent(ASTEROID.get(asteroid).generation + 1));
|
split.addComponent(new AsteroidComponent(ASTEROID.get(asteroid).generation + 1));
|
||||||
split.addComponent(COLLIDER_TAG);
|
split.addComponent(COLLIDER);
|
||||||
split.addGroup("ASTEROIDS");
|
split.addGroup("ASTEROIDS");
|
||||||
entities[i] = split;
|
entities[i] = split;
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,22 @@
|
|||||||
package com.me.asteroids;
|
package com.me.asteroids;
|
||||||
|
|
||||||
|
import com.me.asteroids.components.AsteroidComponent;
|
||||||
|
import com.me.asteroids.components.BulletComponent;
|
||||||
|
import com.me.asteroids.components.PlayerComponent;
|
||||||
import com.me.asteroids.events.BulletAsteroidCollisionEvent;
|
import com.me.asteroids.events.BulletAsteroidCollisionEvent;
|
||||||
import com.me.asteroids.events.CollisionEvent;
|
import com.me.asteroids.events.CollisionEvent;
|
||||||
import com.me.asteroids.events.PlayerASteroidCollisionEvent;
|
import com.me.asteroids.events.PlayerASteroidCollisionEvent;
|
||||||
import com.me.common.ecs.Entity;
|
import com.me.common.ecs.Entity;
|
||||||
|
|
||||||
import static com.me.asteroids.Components.ASTEROID;
|
|
||||||
import static com.me.asteroids.Components.BULLET;
|
|
||||||
import static com.me.asteroids.Components.PLAYER;
|
|
||||||
|
|
||||||
public class EventFactory {
|
public class EventFactory {
|
||||||
|
|
||||||
public static CollisionEvent getNewCollisionEvent(Entity a, Entity b) {
|
public static CollisionEvent getNewCollisionEvent(Entity a, Entity b) {
|
||||||
boolean isEntityAPlayer = PLAYER.has(a);
|
boolean isEntityAPlayer = a.hasComponent(PlayerComponent.class);
|
||||||
boolean isEntityBPlayer = PLAYER.has(b);
|
boolean isEntityBPlayer = b.hasComponent(PlayerComponent.class);
|
||||||
boolean isEntityABullet = !isEntityAPlayer && BULLET.has(a);
|
boolean isEntityABullet = !isEntityAPlayer && a.hasComponent(BulletComponent.class);
|
||||||
boolean isEntityBBullet = !isEntityBPlayer && BULLET.has(b);
|
boolean isEntityBBullet = !isEntityBPlayer && b.hasComponent(BulletComponent.class);
|
||||||
boolean isEntityAAsteroid = !isEntityAPlayer && !isEntityABullet && ASTEROID.has(a);
|
boolean isEntityAAsteroid = !isEntityAPlayer && !isEntityABullet && a.hasComponent(AsteroidComponent.class);
|
||||||
boolean isEntityBAsteroid = !isEntityBPlayer && !isEntityBBullet && ASTEROID.has(b);
|
boolean isEntityBAsteroid = !isEntityBPlayer && !isEntityBBullet && b.hasComponent(AsteroidComponent.class);
|
||||||
|
|
||||||
if (isEntityAAsteroid || isEntityBAsteroid) {
|
if (isEntityAAsteroid || isEntityBAsteroid) {
|
||||||
if (isEntityAPlayer && isEntityBAsteroid) {
|
if (isEntityAPlayer && isEntityBAsteroid) {
|
||||||
|
@ -6,23 +6,17 @@ import com.me.common.ecs.Component;
|
|||||||
public class AccelerationComponent implements Component {
|
public class AccelerationComponent implements Component {
|
||||||
|
|
||||||
public Vector2 acceleration;
|
public Vector2 acceleration;
|
||||||
public float maxVelocity;
|
|
||||||
|
|
||||||
public AccelerationComponent() {
|
public AccelerationComponent() {
|
||||||
this(0f, 0f, Float.MAX_VALUE);
|
this(0f, 0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccelerationComponent(float maxVelocity) {
|
public AccelerationComponent(float x, float y) {
|
||||||
this(0f, 0f, maxVelocity);
|
this(new Vector2(x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccelerationComponent(float x, float y, float maxVelocity) {
|
public AccelerationComponent(Vector2 acceleration) {
|
||||||
this(new Vector2(x, y), maxVelocity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public AccelerationComponent(Vector2 acceleration, float maxVelocity) {
|
|
||||||
this.acceleration = acceleration;
|
this.acceleration = acceleration;
|
||||||
this.maxVelocity = maxVelocity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getX() {
|
public float getX() {
|
||||||
|
@ -2,6 +2,6 @@ package com.me.asteroids.components;
|
|||||||
|
|
||||||
import com.me.common.ecs.Component;
|
import com.me.common.ecs.Component;
|
||||||
|
|
||||||
public class BulletTagComponent implements Component {
|
public class BulletComponent implements Component {
|
||||||
// TODO: See PlayerComponent's TODO
|
// TODO: See PlayerComponent's TODO
|
||||||
}
|
}
|
@ -5,5 +5,5 @@ import com.me.common.ecs.Component;
|
|||||||
/**
|
/**
|
||||||
* Add this to Entities that should be checked for collisions with other entities.
|
* Add this to Entities that should be checked for collisions with other entities.
|
||||||
*/
|
*/
|
||||||
public class ColliderTagComponent implements Component {
|
public class ColliderComponent implements Component {
|
||||||
}
|
}
|
@ -2,6 +2,6 @@ package com.me.asteroids.components;
|
|||||||
|
|
||||||
import com.me.common.ecs.Component;
|
import com.me.common.ecs.Component;
|
||||||
|
|
||||||
public class DebrisTagComponent implements Component {
|
public class DebrisComponent implements Component {
|
||||||
// TODO: See PlayerComponent's TODO
|
// TODO: See PlayerComponent's TODO
|
||||||
}
|
}
|
@ -7,6 +7,7 @@ public class VelocityComponent implements Component {
|
|||||||
|
|
||||||
public Vector2 velocity;
|
public Vector2 velocity;
|
||||||
public float angularVelocity;
|
public float angularVelocity;
|
||||||
|
public float maxVelocity;
|
||||||
|
|
||||||
public VelocityComponent() {
|
public VelocityComponent() {
|
||||||
this(0f, 0f, 0f);
|
this(0f, 0f, 0f);
|
||||||
@ -21,12 +22,21 @@ public class VelocityComponent implements Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public VelocityComponent(float x, float y, float angularVelocity) {
|
public VelocityComponent(float x, float y, float angularVelocity) {
|
||||||
this(new Vector2(x, y), angularVelocity);
|
this(x, y, angularVelocity, Float.MAX_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public VelocityComponent(float x, float y, float angularVelocity, float maxVelocity) {
|
||||||
|
this(new Vector2(x, y), angularVelocity, maxVelocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public VelocityComponent(Vector2 velocity, float angularVelocity) {
|
public VelocityComponent(Vector2 velocity, float angularVelocity) {
|
||||||
|
this(velocity, angularVelocity, Float.MAX_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public VelocityComponent(Vector2 velocity, float angularVelocity, float maxVelocity) {
|
||||||
this.velocity = velocity;
|
this.velocity = velocity;
|
||||||
this.angularVelocity = angularVelocity;
|
this.angularVelocity = angularVelocity;
|
||||||
|
this.maxVelocity = maxVelocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getX() {
|
public float getX() {
|
||||||
|
@ -10,9 +10,9 @@ import com.me.asteroids.EntityFactory;
|
|||||||
import com.me.asteroids.Graphics;
|
import com.me.asteroids.Graphics;
|
||||||
import com.me.asteroids.components.AccelerationComponent;
|
import com.me.asteroids.components.AccelerationComponent;
|
||||||
import com.me.asteroids.components.AsteroidComponent;
|
import com.me.asteroids.components.AsteroidComponent;
|
||||||
import com.me.asteroids.components.BulletTagComponent;
|
import com.me.asteroids.components.BulletComponent;
|
||||||
import com.me.asteroids.components.ColliderTagComponent;
|
import com.me.asteroids.components.ColliderComponent;
|
||||||
import com.me.asteroids.components.DebrisTagComponent;
|
import com.me.asteroids.components.DebrisComponent;
|
||||||
import com.me.asteroids.components.DecayComponent;
|
import com.me.asteroids.components.DecayComponent;
|
||||||
import com.me.asteroids.components.GameDataComponent;
|
import com.me.asteroids.components.GameDataComponent;
|
||||||
import com.me.asteroids.components.ModelComponent;
|
import com.me.asteroids.components.ModelComponent;
|
||||||
@ -67,18 +67,17 @@ public class GameScreen extends Screen implements Listener {
|
|||||||
|
|
||||||
engine = new Engine();
|
engine = new Engine();
|
||||||
|
|
||||||
engine.registerComponentClass(BulletTagComponent.class);
|
|
||||||
engine.registerComponentClass(ColliderTagComponent.class);
|
|
||||||
engine.registerComponentClass(DebrisTagComponent.class);
|
|
||||||
|
|
||||||
engine.registerComponentClass(AccelerationComponent.class);
|
|
||||||
engine.registerComponentClass(AsteroidComponent.class);
|
|
||||||
engine.registerComponentClass(DecayComponent.class);
|
|
||||||
engine.registerComponentClass(GameDataComponent.class);
|
engine.registerComponentClass(GameDataComponent.class);
|
||||||
engine.registerComponentClass(ModelComponent.class);
|
|
||||||
engine.registerComponentClass(PlayerComponent.class);
|
engine.registerComponentClass(PlayerComponent.class);
|
||||||
|
engine.registerComponentClass(BulletComponent.class);
|
||||||
|
engine.registerComponentClass(AsteroidComponent.class);
|
||||||
|
engine.registerComponentClass(DebrisComponent.class);
|
||||||
|
engine.registerComponentClass(DecayComponent.class);
|
||||||
|
engine.registerComponentClass(ColliderComponent.class);
|
||||||
engine.registerComponentClass(PositionComponent.class);
|
engine.registerComponentClass(PositionComponent.class);
|
||||||
engine.registerComponentClass(VelocityComponent.class);
|
engine.registerComponentClass(VelocityComponent.class);
|
||||||
|
engine.registerComponentClass(AccelerationComponent.class);
|
||||||
|
engine.registerComponentClass(ModelComponent.class);
|
||||||
|
|
||||||
GameDataSystem system = new GameDataSystem(engine);
|
GameDataSystem system = new GameDataSystem(engine);
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ package com.me.asteroids.systems;
|
|||||||
|
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
import com.me.asteroids.EventFactory;
|
import com.me.asteroids.EventFactory;
|
||||||
import com.me.asteroids.components.ColliderTagComponent;
|
import com.me.asteroids.components.ColliderComponent;
|
||||||
import com.me.asteroids.components.ModelComponent;
|
import com.me.asteroids.components.ModelComponent;
|
||||||
import com.me.common.ecs.Engine;
|
import com.me.common.ecs.Engine;
|
||||||
import com.me.common.ecs.Entity;
|
import com.me.common.ecs.Entity;
|
||||||
@ -13,7 +13,7 @@ import static com.me.asteroids.Components.MODEL;
|
|||||||
public class CollisionSystem extends EntitySystem {
|
public class CollisionSystem extends EntitySystem {
|
||||||
|
|
||||||
public CollisionSystem(Engine engine) {
|
public CollisionSystem(Engine engine) {
|
||||||
super(engine, ColliderTagComponent.class, ModelComponent.class);
|
super(engine, ColliderComponent.class, ModelComponent.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,29 +29,18 @@ public class MovementSystem extends EntitySystem {
|
|||||||
public void processEntity(Entity entity, float dt) {
|
public void processEntity(Entity entity, float dt) {
|
||||||
PositionComponent positionComponent = POSITION.get(entity);
|
PositionComponent positionComponent = POSITION.get(entity);
|
||||||
VelocityComponent velocityComponent = VELOCITY.get(entity);
|
VelocityComponent velocityComponent = VELOCITY.get(entity);
|
||||||
AccelerationComponent accelComponent = ACCELERATION.get(entity);
|
|
||||||
|
|
||||||
Vector2 velocity = velocityComponent.velocity;
|
Vector2 velocity = velocityComponent.velocity;
|
||||||
|
|
||||||
|
AccelerationComponent accelComponent = ACCELERATION.get(entity);
|
||||||
if (accelComponent != null && !accelComponent.acceleration.isZero()) {
|
if (accelComponent != null && !accelComponent.acceleration.isZero()) {
|
||||||
tmp.set(accelComponent.acceleration).scl(dt).add(velocity);
|
velocity.add(tmp.set(accelComponent.acceleration).scl(dt));
|
||||||
|
|
||||||
if (velocity.dot(tmp) < 0) {
|
|
||||||
// current velocity is opposite of velocity with acceleration applied, which means
|
|
||||||
// we're coming to a stop. Set position correctly and velocity to zero
|
|
||||||
velocity.set(0, 0);
|
|
||||||
positionComponent.position.add(tmp.scl(dt));
|
|
||||||
} else {
|
|
||||||
// Else just use the accelerated velocity
|
|
||||||
velocity.set(tmp);
|
|
||||||
velocity.clamp(0, accelComponent.maxVelocity);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float maxVelocity = velocityComponent.maxVelocity;
|
||||||
Vector2 position = positionComponent.position;
|
Vector2 position = positionComponent.position;
|
||||||
|
|
||||||
if (!velocity.isZero()) {
|
if (!velocity.isZero()) {
|
||||||
positionComponent.position.add(tmp.set(velocity).scl(dt));
|
velocity.clamp(0, maxVelocity);
|
||||||
|
position.add(tmp.set(velocity).scl(dt));
|
||||||
}
|
}
|
||||||
|
|
||||||
float angularVelocity = velocityComponent.angularVelocity;
|
float angularVelocity = velocityComponent.angularVelocity;
|
||||||
|
@ -51,12 +51,13 @@ public class PlayerInputSystem extends EntitySystem {
|
|||||||
velocityComponent.angularVelocity = 0;
|
velocityComponent.angularVelocity = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector2 acceleration = accelComponent.acceleration;
|
||||||
Vector2 velocity = velocityComponent.velocity;
|
Vector2 velocity = velocityComponent.velocity;
|
||||||
|
|
||||||
MODEL.get(playerComponent.afterBurner).setPosition(positionComponent.position);
|
MODEL.get(playerComponent.afterBurner).model.setPosition(positionComponent.position);
|
||||||
|
|
||||||
if (Gdx.input.isKeyPressed(Input.Keys.W)) {
|
if (Gdx.input.isKeyPressed(Input.Keys.W)) {
|
||||||
accelComponent.set(Utils.setUnitVectorAngle(tmp, positionComponent.rotation).scl(12.5f));
|
acceleration.set(Utils.setUnitVectorAngle(tmp, positionComponent.rotation).scl(12.5f));
|
||||||
|
|
||||||
if (rand.nextFloat() < 0.85) {
|
if (rand.nextFloat() < 0.85) {
|
||||||
PositionComponent afterBurnerPosition = POSITION.get(playerComponent.afterBurner);
|
PositionComponent afterBurnerPosition = POSITION.get(playerComponent.afterBurner);
|
||||||
@ -68,10 +69,10 @@ public class PlayerInputSystem extends EntitySystem {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
playerComponent.afterBurner.deactivate();
|
playerComponent.afterBurner.deactivate();
|
||||||
if (velocity.isZero(0f)) {
|
if (!velocity.isZero(1f)) {
|
||||||
accelComponent.set(0, 0);
|
acceleration.set(Utils.setUnitVectorAngleRad(tmp, velocity.angleRad()).scl(-2.5f));
|
||||||
} else {
|
} else {
|
||||||
accelComponent.set(Utils.setUnitVectorAngleRad(tmp, velocity.angleRad()).scl(-2.5f));
|
acceleration.set(0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user