Utilize a PLAYER tag and ASTEROIDS group
User PLAYER tag for access to the player entity Use ASTEROIDS group to count how many asteroids there are
This commit is contained in:
parent
d8cabf4549
commit
f4508fa0da
@ -73,6 +73,7 @@ public class EntityFactory {
|
||||
player.addComponent(new AccelerationComponent(0f, 1f));
|
||||
player.addComponent(COLLIDER);
|
||||
player.addComponent(new PlayerComponent(afterBurner));
|
||||
player.setTag("PLAYER");
|
||||
|
||||
afterBurner.addComponent(new PositionComponent(Constants.HALF_WIDTH, Constants.HALF_HEIGHT, 90));
|
||||
afterBurner.addComponent(velocity);
|
||||
@ -186,6 +187,7 @@ public class EntityFactory {
|
||||
asteroid.addComponent(model);
|
||||
asteroid.addComponent(COLLIDER);
|
||||
asteroid.addComponent(new AsteroidComponent());
|
||||
asteroid.addGroup("ASTEROIDS");
|
||||
return asteroid;
|
||||
}
|
||||
|
||||
@ -230,6 +232,7 @@ public class EntityFactory {
|
||||
split.addComponent(velocity);
|
||||
split.addComponent(new AsteroidComponent(ASTEROID.get(asteroid).generation + 1));
|
||||
split.addComponent(COLLIDER);
|
||||
split.addGroup("ASTEROIDS");
|
||||
entities[i] = split;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package com.me.asteroids.systems;
|
||||
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.me.asteroids.Constants;
|
||||
import com.me.asteroids.EntityFactory;
|
||||
import com.me.asteroids.Utils;
|
||||
@ -12,7 +11,6 @@ import com.me.common.ecs.BaseSystem;
|
||||
import com.me.common.ecs.Engine;
|
||||
import com.me.common.ecs.Entity;
|
||||
|
||||
import static com.me.asteroids.Components.ASTEROID;
|
||||
import static com.me.asteroids.Components.MODEL;
|
||||
import static com.me.asteroids.Components.POSITION;
|
||||
import static com.me.asteroids.Components.VELOCITY;
|
||||
@ -63,16 +61,7 @@ public class AsteroidSpawningSystem extends BaseSystem {
|
||||
|
||||
@Override
|
||||
public void process(float dt) {
|
||||
Array<Entity> entities = engine.getEntities();
|
||||
int asteroidCount = 0;
|
||||
for (Entity entity : entities) {
|
||||
// It's rather inefficient to have to check our entire entity list every frame
|
||||
// to count how many entities have a specific component. Maybe we should keep a count of
|
||||
// how many entites a given component?
|
||||
if (ASTEROID.has(entity)) {
|
||||
asteroidCount++;
|
||||
}
|
||||
}
|
||||
int asteroidCount = engine.getEntitiesInGroup("ASTEROIDS").size;
|
||||
|
||||
if (asteroidCount++ < Constants.ASTEROID_SPAWN_COUNT && (asteroidSpawnDelay -= dt) <= 0) {
|
||||
spawnAsteroid();
|
||||
|
@ -85,7 +85,7 @@ public class GameDataSystem extends EntitySystem implements Listener {
|
||||
}
|
||||
|
||||
private void resetPlayer() {
|
||||
Entity player = engine.getEntities().get(1);
|
||||
Entity player = engine.getEntityByTag("PLAYER");
|
||||
PositionComponent position = POSITION.get(player);
|
||||
position.set(Constants.HALF_WIDTH, Constants.HALF_HEIGHT);
|
||||
position.rotation = 90;
|
||||
|
Loading…
Reference in New Issue
Block a user