Use ComponentMappers everywhere else

This commit is contained in:
Matt Low 2020-02-01 21:51:54 +04:00
parent 84a353cfd2
commit 3cf1d19c4d
2 changed files with 12 additions and 11 deletions

View File

@ -145,8 +145,8 @@ public class EntityFactory {
public static Entity createBullet(Engine engine, Entity player) {
float[] modelVertices = player.getComponent(ModelComponent.class).model.getVertices();
float rotation = player.getComponent(PositionComponent.class).rotation;
float[] modelVertices = MODEL.get(player).model.getVertices();
float rotation = POSITION.get(player).rotation;
PositionComponent position = new PositionComponent(modelVertices[0], modelVertices[1], rotation);
ModelComponent model = new ModelComponent(new PolygonModel(Color.YELLOW));

View File

@ -1,22 +1,23 @@
package com.me.asteroids;
import com.me.asteroids.components.AsteroidComponent;
import com.me.asteroids.components.BulletTagComponent;
import com.me.asteroids.components.PlayerComponent;
import com.me.asteroids.events.BulletAsteroidCollisionEvent;
import com.me.asteroids.events.CollisionEvent;
import com.me.asteroids.events.PlayerASteroidCollisionEvent;
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 static CollisionEvent getNewCollisionEvent(Entity a, Entity b) {
boolean isEntityAPlayer = a.hasComponent(PlayerComponent.class);
boolean isEntityBPlayer = b.hasComponent(PlayerComponent.class);
boolean isEntityABullet = !isEntityAPlayer && a.hasComponent(BulletTagComponent.class);
boolean isEntityBBullet = !isEntityBPlayer && b.hasComponent(BulletTagComponent.class);
boolean isEntityAAsteroid = !isEntityAPlayer && !isEntityABullet && a.hasComponent(AsteroidComponent.class);
boolean isEntityBAsteroid = !isEntityBPlayer && !isEntityBBullet && b.hasComponent(AsteroidComponent.class);
boolean isEntityAPlayer = PLAYER.has(a);
boolean isEntityBPlayer = PLAYER.has(b);
boolean isEntityABullet = !isEntityAPlayer && BULLET.has(a);
boolean isEntityBBullet = !isEntityBPlayer && BULLET.has(b);
boolean isEntityAAsteroid = !isEntityAPlayer && !isEntityABullet && ASTEROID.has(a);
boolean isEntityBAsteroid = !isEntityBPlayer && !isEntityBBullet && ASTEROID.has(b);
if (isEntityAAsteroid || isEntityBAsteroid) {
if (isEntityAPlayer && isEntityBAsteroid) {