use of de.gurkenlabs.litiengine.entities.Spawnpoint in project litiengine by gurkenlabs.
the class EnvironmentTests method testSpawnPoint.
@Test
void testSpawnPoint() {
Spawnpoint testSpawn = new Spawnpoint(1, 0, 0);
testSpawn.setName("test");
this.testEnvironment.add(testSpawn);
assertNotNull(this.testEnvironment.getSpawnpoint(1));
assertNotNull(this.testEnvironment.getSpawnpoint("test"));
assertEquals(1, this.testEnvironment.getEntities(Spawnpoint.class).size());
assertEquals(1, this.testEnvironment.getEntities().size());
this.testEnvironment.remove(testSpawn);
assertNull(this.testEnvironment.getSpawnpoint(1));
assertNull(this.testEnvironment.getSpawnpoint("test"));
assertEquals(0, this.testEnvironment.getEntities(MapArea.class).size());
assertEquals(0, this.testEnvironment.getEntities().size());
}
use of de.gurkenlabs.litiengine.entities.Spawnpoint in project litiengine by gurkenlabs.
the class EntitySpawner method spawnNewEntities.
/**
* Spawn new entities, depending on the {@code SpawnMode}, spawnAmount, spawnDelay, and spawnInterval of an
* {@code EntitySpawner}.
*
* @see SpawnMode
*/
protected void spawnNewEntities() {
if (this.getSpawnMode() != SpawnMode.CUSTOMSPAWNPOINTS && this.getSpawnPoints().isEmpty()) {
return;
}
switch(this.getSpawnMode()) {
case ALLSPAWNPOINTS:
for (int i = 0; i < this.getSpawnPoints().size(); i++) {
final int index = i;
Game.loop().perform(this.getSpawnDelay() + this.getSpawnDelay() * i, () -> this.spawn(this.getSpawnPoints().get(index), this.getSpawnAmount()));
}
break;
case ONERANDOMSPAWNPOINT:
this.spawn(Game.random().choose(this.getSpawnPoints()), this.getSpawnAmount());
break;
case RANDOMSPAWNPOINTS:
for (int i = 0; i < this.getSpawnAmount(); i++) {
Game.loop().perform(this.getSpawnDelay() + this.getSpawnDelay() * i, () -> this.spawn(Game.random().choose(this.getSpawnPoints()), 1));
}
break;
case CUSTOMSPAWNPOINTS:
List<Spawnpoint> spawnPoints = this.customSpawnpoints != null ? this.customSpawnpoints.apply(this) : this.getCustomSpawnpoints();
int index = 0;
for (Spawnpoint spawn : spawnPoints) {
Game.loop().perform(this.getSpawnDelay() + this.getSpawnDelay() * index, () -> this.spawn(spawn, 1));
index++;
}
break;
default:
break;
}
}
use of de.gurkenlabs.litiengine.entities.Spawnpoint in project litiengine by gurkenlabs.
the class EntitySpawner method spawn.
private void spawn(final Spawnpoint spawnpoint, final int amount) {
if (spawnpoint.getEnvironment() == null || !spawnpoint.getEnvironment().isLoaded()) {
return;
}
for (int i = 0; i < amount; i++) {
final T newEntity = this.createNew();
spawnpoint.spawn(newEntity);
}
}
use of de.gurkenlabs.litiengine.entities.Spawnpoint in project litiengine by gurkenlabs.
the class EntitySpawnerTests method setup.
@BeforeEach
public void setup() {
testEnvironment = mock(Environment.class);
spawnPoint = mock(Spawnpoint.class);
spawner = new TestCreatureSpawner(spawnPoint, spawnAmount);
spawnedCreature = new Creature();
}
use of de.gurkenlabs.litiengine.entities.Spawnpoint in project litiengine by gurkenlabs.
the class Environment method remove.
/**
* Removes the specified entity from this environment and unloads is.
*
* @param entity
* The entity to be removed.
*
* @see #remove(int)
* @see #remove(String)
* @see #removeAll(Iterable)
* @see #unload(IEntity)
* @see EnvironmentEntityListener#entityRemoved(IEntity)
* @see IEntity#removed(Environment)
* @see EntityListener#removed(IEntity, Environment)
*/
public void remove(final IEntity entity) {
if (entity == null) {
return;
}
this.allEntities.remove(entity.getMapId());
Iterator<List<IEntity>> iter = this.layerEntities.values().iterator();
while (iter.hasNext()) {
List<IEntity> layer = iter.next();
if (layer.remove(entity) && layer.isEmpty()) {
iter.remove();
}
}
if (this.miscEntities.get(entity.getRenderType()) != null) {
this.miscEntities.get(entity.getRenderType()).values().remove(entity);
}
for (String tag : entity.getTags()) {
if (this.getEntitiesByTag().containsKey(tag)) {
this.getEntitiesByTag().get(tag).remove(entity);
if (this.getEntitiesByTag().get(tag).isEmpty()) {
this.getEntitiesByTag().remove(tag);
}
}
}
if (entity instanceof Emitter) {
Emitter emitter = (Emitter) entity;
this.removeEmitter(emitter);
}
if (entity instanceof MapArea) {
this.mapAreas.remove(entity);
}
if (entity instanceof Prop) {
this.props.remove(entity);
}
if (entity instanceof Creature) {
this.creatures.remove(entity);
}
if (entity instanceof CollisionBox) {
this.colliders.remove(entity);
this.staticShadows.removeIf(x -> x.getOrigin() != null && x.getOrigin().equals(entity));
}
if (entity instanceof LightSource) {
this.lightSources.remove(entity);
this.updateLighting(entity);
}
if (entity instanceof Trigger) {
this.triggers.remove(entity);
}
if (entity instanceof Spawnpoint) {
this.spawnPoints.remove(entity);
}
if (entity instanceof SoundSource) {
this.soundSources.remove(entity);
}
if (entity instanceof StaticShadow) {
this.staticShadows.remove(entity);
this.updateLighting(entity);
}
if (entity instanceof IMobileEntity) {
this.mobileEntities.values().remove(entity);
}
if (entity instanceof ICombatEntity) {
this.combatEntities.values().remove(entity);
}
this.unload(entity);
this.fireEntityEvent(l -> l.entityRemoved(entity));
}
Aggregations