From 3cf1d19c4d7681e481dc77acc417a064ac04423b Mon Sep 17 00:00:00 2001 From: Matt Low Date: Sat, 1 Feb 2020 21:51:54 +0400 Subject: [PATCH] Use ComponentMappers everywhere else --- core/src/com/me/asteroids/EntityFactory.java | 4 ++-- core/src/com/me/asteroids/EventFactory.java | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/core/src/com/me/asteroids/EntityFactory.java b/core/src/com/me/asteroids/EntityFactory.java index 7ff780d..ca10990 100644 --- a/core/src/com/me/asteroids/EntityFactory.java +++ b/core/src/com/me/asteroids/EntityFactory.java @@ -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)); diff --git a/core/src/com/me/asteroids/EventFactory.java b/core/src/com/me/asteroids/EventFactory.java index 4f08b9d..668f459 100644 --- a/core/src/com/me/asteroids/EventFactory.java +++ b/core/src/com/me/asteroids/EventFactory.java @@ -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) {