Bosses inside Combat - UQcsse3200/2024-studio-2 GitHub Wiki
Overview
This section focuses on displaying boss entities on the combat screen. The CombatArea
class is responsible for spawning and managing combat enemies, like the bosses, such as the Kangaroo, Leviathan, and Griffin bosses. Each boss has a unique appearance, animations, and combat music that plays during encounters, adding depth and variety to the gameplay.
Implementation
CombatArea
class
In public class CombatArea extends GameArea {
.
.
/** Spawn a combat enemy. Different to a regular enemy npc */
private void spawnKangaBoss() {
Entity newEnemy = CombatAnimalFactory.createKangaBossCombatEntity();
spawnEntityAt(newEnemy, new GridPoint2(800, 230), true, true);
this.enemyDisplay = newEnemy;
}
/** Spawn a combat enemy. Different to a regular enemy npc */
private void spawnWaterBoss() {
Entity newEnemy = CombatAnimalFactory.createWaterBossCombatEntity();
spawnEntityAt(newEnemy, new GridPoint2(800, 390), true, true);
this.enemyDisplay = newEnemy;
}
/** Spawn a combat enemy. Different to a regular enemy npc */
private void spawnAirBoss() {
Entity newEnemy = CombatAnimalFactory.createAirBossCombatEntity();
spawnEntityAt(newEnemy, new GridPoint2(800, 330), true, true);
this.enemyDisplay = newEnemy;
}
/**
* spawns a joey enemy, with the player entity as its target
*/
private void spawnJoey() {
Entity newEnemy = CombatAnimalFactory.createJoeyCombatEnemy();
spawnEntityAt(newEnemy, new GridPoint2(796, 180), true, true);
this.enemyDisplay = newEnemy;
}
/**
* Plays an enemy animation in combat
* @param animation CombatAnimation (IDLE or MOVE) to trigger
*/
public void startEnemyAnimation(CombatAnimation animation) {
switch (animation) {
case IDLE:
enemyDisplay.getEvents().trigger("idleLeft");
break;
case MOVE:
enemyDisplay.getEvents().trigger("moveLeft");
break;
}
}
/**
* Plays a player animation in combat
* @param animation CombatAnimation (IDLE or MOVE) to trigger
*/
public void startPlayerAnimation(CombatAnimation animation) {
switch (animation) {
case IDLE:
playerDisplay.getEvents().trigger("idleRight");
break;
case MOVE:
playerDisplay.getEvents().trigger("moveRight");
break;
}
}
playMusic()
method controls the background music during combat, changing the track based on the type of boss spawned.
The /**
* Play the music for combat
*/
public void playMusic() {
AudioManager.stopMusic();
if (this.enemy.getEnemyType() == Entity.EnemyType.KANGAROO) {
AudioManager.playMusic("sounds/combat-land-boss.mp3", true);
} else if (this.enemy.getEnemyType() == Entity.EnemyType.WATER_BOSS) {
AudioManager.playMusic("sounds/combat-water-boss.mp3", true);
} else if (this.enemy.getEnemyType() == Entity.EnemyType.AIR_BOSS) {
AudioManager.playMusic("sounds/combat-air-boss.mp3", true);
} else {
AudioManager.playMusic(CombatAreaConfig.COMBATBACKGROUND_MUSIC, true);
}
}
/** Pause the music for combat. Will be finalised and used when
* combat pause is implemented
*/
public void pauseMusic() {
// Stop the music using AudioManager
AudioManager.stopMusic();
}
CombatAnimalFactory
class, which handles the setup of their appearance, animations, and behaviour using reusable components like animation controllers.
Each boss is created through the public class CombatAnimalFactory {
/**
* Creates a base Combat NPC to be used by more specific NPC creation methods.
*
* @return entity
*/
public static Entity createCombatBaseEnemy(BaseEnemyEntityConfig config, Entity.EnemyType type) {
Entity entity =
new Entity()
.addComponent(new PhysicsComponent())
.addComponent(new ColliderComponent());
PhysicsUtils.setScaledCollider(entity, 0.9f, 0.4f);
entity.setEnemyType(type);
TextureAtlas textureAtlas = ServiceLocator.getResourceService().getAsset(config.getSpritePath(), TextureAtlas.class);
AnimationRenderComponent animator = new AnimationRenderComponent(textureAtlas);
animator.addAnimation("combat_idle", 0.8f, Animation.PlayMode.LOOP);
animator.addAnimation("combat_move", 0.2f, Animation.PlayMode.LOOP);
entity
.addComponent(animator)
.addComponent(new CombatAnimationController());
return entity;
}
/**
* Creates joey enemy as NPC entity for static combat
* */
public static Entity createJoeyCombatEnemy() {
BaseEnemyEntityConfig config = configs.joey;
Entity joeyEnemy = createCombatBaseEnemy(config, Entity.EnemyType.JOEY);
joeyEnemy.scaleHeight(90.0f);
return joeyEnemy;
}
/**
* Creates kangaroo boss enemy as entity for combat display
*
* @return entity
* */
public static Entity createKangaBossCombatEntity() {
BaseEnemyEntityConfig config = configs.kangarooBoss;
Entity kangarooBoss = createCombatBaseEnemy(config, Entity.EnemyType.KANGAROO);
kangarooBoss.scaleHeight(200.0f);
return kangarooBoss;
}
/**
* Creates water boss enemy as entity for combat display
*
* @return entity
* */
public static Entity createWaterBossCombatEntity() {
BaseEnemyEntityConfig config = configs.waterBoss;
Entity waterBoss = createCombatBaseEnemy(config, Entity.EnemyType.WATER_BOSS);
waterBoss.scaleHeight(300.0f);
return waterBoss;
}
/**
* Creates air boss enemy as entity for combat display
*
* @return entity
* */
public static Entity createAirBossCombatEntity() {
BaseEnemyEntityConfig config = configs.airBoss;
Entity airBoss = createCombatBaseEnemy(config, Entity.EnemyType.AIR_BOSS);
airBoss.scaleHeight(300.0f);
return airBoss;
}
}
Testing Plan
Visual testing, with captioning to explain: https://youtu.be/Ny-1nAlynto