-
Notifications
You must be signed in to change notification settings - Fork 1
Spawning Bosses
Phurin Vanasrivilai edited this page Oct 17, 2024
·
3 revisions
Handle the event triggers and event listeners which spawn the boss into the main game (After completing required quests).
In KeyboardPlayerInputComponent
, add temporary triggers key press for testing the events which spawns the boss "spawn...Boss".
case Keys.NUM_1: // TEMPORARY: Press 1 to spawn the land boss
entity.getEvents().trigger("spawnLandBoss");
return true;
case Keys.NUM_2: // TEMPORARY: Press 2 to spawn the water boss
entity.getEvents().trigger("spawnWaterBoss");
return true;
case Keys.NUM_3: // TEMPORARY: Press 3 to spawn the air boss
entity.getEvents().trigger("spawnAirBoss");
return true;
@Override
public void create() {
.
.
.
player.getEvents().addListener("spawnLandBoss", this::spawnKangarooBoss);
player.getEvents().addListener("spawnWaterBoss", this::spawnWaterBoss);
player.getEvents().addListener("spawnAirBoss", this::spawnAirBoss);
.
.
.
}
private void spawnKangarooBoss() {
if (!kangarooBossSpawned) {
Entity kangarooBoss = BossFactory.createKangaBossEntity(player);
kangarooBoss.getEvents().addListener("spawnJoey", this::spawnJoeyEnemy);
spawnBossOnMap(kangarooBoss);
bosses.add(kangarooBoss);
kangarooBossSpawned = true;
}
}
private void spawnWaterBoss() {
if (!waterBossSpawned) {
Entity waterBoss = BossFactory.createWaterBossEntity(player);
waterBoss.getEvents().addListener("spawnWaterSpiral", this::spawnWaterSpiral);
spawnBossOnMap(waterBoss);
bosses.add(waterBoss);
waterBossSpawned = true;
}
}
private void spawnAirBoss() {
if (!airBossSpawned) {
Entity airBoss = BossFactory.createAirBossEntity(player);
airBoss.getEvents().addListener("spawnWindGust", this::spawnWindGust);
spawnBossOnMap(airBoss);
bosses.add(airBoss);
airBossSpawned = true;
}
}
the method spawnBossOnMap()
determine which location the bosses will spawn in, usually will be around the gate going to the next area, with the exception for the Griffin (final boss) which spawns around the middle of its area.
private void spawnBossOnMap(Entity entity) {
GridPoint2 minPos = null;
GridPoint2 maxPos = null;
float tileSize = terrain.getTileSize();
GridPoint2 tileBounds = terrain.getMapBounds(0);
Vector2 worldBounds = new Vector2(tileBounds.x * tileSize, tileBounds.y * tileSize);
int minGateX = (int) (worldBounds.x / 2) - 5;
int maxGateX = (int) (worldBounds.x / 2) + 5;
// Define spawn areas based on the boss type
if (entity.getEnemyType() == Entity.EnemyType.KANGAROO) {
// Spawn near the first barrier
minPos = new GridPoint2(minGateX, (MAP_SIZE.y / 3 )- 10);
maxPos = new GridPoint2(maxGateX, (MAP_SIZE.y / 3) - 5);
} else if (entity.getEnemyType() == Entity.EnemyType.WATER_BOSS) {
// Spawn near the second barrier
minPos = new GridPoint2(minGateX, (MAP_SIZE.y / 3 * 2) - 10);
maxPos = new GridPoint2(maxGateX, (MAP_SIZE.y / 3 * 2) - 5);
} else if (entity.getEnemyType() == Entity.EnemyType.AIR_BOSS) {
// Spawn at the top of the map
minPos = new GridPoint2(minGateX, MAP_SIZE.y - 20);
maxPos = new GridPoint2(maxGateX, MAP_SIZE.y - 15);
}
if (minPos != null) {
// Generate a random position within the range
GridPoint2 randomPos = RandomUtils.random(minPos, maxPos);
// Spawn the entity at the calculated random position
spawnEntityAt(entity, randomPos, true, true);
}
}
Visual testing, with captioning to explain: https://youtu.be/Ny-1nAlynto