CombatArea - UQcsse3200/2024-studio-2 GitHub Wiki
The CombatArea
class represents the combat arena in the game where battles between the player and enemies take place. It is responsible for creating the combat environment, spawning entities, and managing the overall combat experience.
classDiagram
class GameArea {
<<abstract>>
+create()
+dispose()
+getPlayer(): Entity
+getEnemies(): List<Entity>
+getBosses(): List<Entity>
+getFriendlyNPCs(): List<Entity>
+getMinigameNPCs(): List<Entity>
}
class CombatArea {
-GdxGame game
-Entity player
-Entity playerDisplay
-GridPoint2 playerSpawn
-CombatTerrainFactory combatTerrainFactory
-Entity enemy
-Entity enemyDisplay
-KINGDOM kingdomType
+CombatArea(Entity player, Entity enemy, GdxGame game, CombatTerrainFactory terrainFactory)
+create()
-displayUI()
-spawnTerrain()
-spawnPlayer()
-spawnCameraInvisibleEntity()
-spawnCombatEnemy()
-spawnKangaBoss()
-spawnWaterBoss()
-spawnAirBoss()
-spawnChicken()
-spawnFrog()
-spawnMonkey()
-spawnBear()
-spawnMacaw()
-spawnBee()
-spawnOctopus()
-spawnPigeon()
-spawnEel()
-spawnBigSawfish()
-spawnJoey()
+startEnemyAnimation(CombatAnimation animation)
+startPlayerAnimation(CombatAnimation animation)
+playMusic()
+pauseMusic()
-loadAssets()
+unloadAssets()
+dispose()
}
GameArea <|-- CombatArea
- Player: The player entity in the combat area.
- Enemy: The enemy entity that the player is fighting against.
- Terrain: The combat arena's background and environment.
- Kingdom Type: Determines the type of combat area (LAND, AIR, or WATER).
The CombatArea
is initialized with the player, enemy, game instance, and terrain factory:
public CombatArea(Entity player, Entity enemy, GdxGame game, CombatTerrainFactory terrainFactory) {
super();
this.game = game;
this.combatTerrainFactory = terrainFactory;
this.player = player;
this.enemy = enemy;
}
The create()
method sets up the entire combat area:
@Override
public void create() {
loadAssets();
displayUI();
spawnTerrain();
spawnEnemy();
spawnPlayer();
playMusic();
}
The CombatArea
class provides methods to spawn various entities:
-
spawnPlayer()
: Spawns the player entity in the combat area. -
spawnCombatEnemy()
: Spawns a generic combat enemy. -
spawnKangaBoss()
,spawnWaterBoss()
,spawnAirBoss()
: Spawn boss entities. -
spawnChicken()
,spawnFrog()
,spawnMonkey()
, etc.: Spawn specific enemy types.
Example of spawning a chicken enemy:
private void spawnChicken() {
Entity newEnemy = CombatAnimalFactory.createChickenCombatEnemy();
spawnEntityAt(newEnemy, new GridPoint2(760, 190), true, true);
this.enemyDisplay = newEnemy;
}
The class provides methods to start animations for both the player and enemy:
public void startEnemyAnimation(CombatAnimation animation) {
switch (animation) {
case IDLE:
enemyDisplay.getEvents().trigger("idleLeft");
break;
case MOVE:
enemyDisplay.getEvents().trigger("moveLeft");
break;
}
}
The CombatArea
class handles playing and pausing music for the combat scene:
public void playMusic() {
AudioManager.stopMusic();
AudioManager.playMusic(CombatAreaConfig.COMBATBACKGROUND_MUSIC, true);
}
public void pauseMusic() {
AudioManager.stopMusic();
}
sequenceDiagram
participant Game
participant CombatArea
participant CombatTerrainFactory
participant EntityFactory
participant AudioManager
Game->>CombatArea: new CombatArea(player, enemy, game, terrainFactory)
Game->>CombatArea: create()
CombatArea->>CombatArea: loadAssets()
CombatArea->>CombatArea: displayUI()
CombatArea->>CombatTerrainFactory: createBackgroundTerrain()
CombatTerrainFactory-->>CombatArea: terrain
CombatArea->>EntityFactory: createCombatEnemy()
EntityFactory-->>CombatArea: enemy
CombatArea->>EntityFactory: createCombatPlayer()
EntityFactory-->>CombatArea: player
CombatArea->>AudioManager: playMusic()
Game->>CombatArea: startEnemyAnimation(IDLE)
CombatArea->>CombatArea: enemyDisplay.getEvents().trigger("idleLeft")
Game->>CombatArea: startPlayerAnimation(MOVE)
CombatArea->>CombatArea: playerDisplay.getEvents().trigger("moveRight")
Game->>CombatArea: dispose()
CombatArea->>AudioManager: stopMusic()
CombatArea->>CombatArea: unloadAssets()
To create and use a CombatArea
:
- Initialize the
CombatArea
with the necessary parameters. - Call the
create()
method to set up the combat environment. - Use
startEnemyAnimation()
andstartPlayerAnimation()
to trigger animations during combat. - Manage music with
playMusic()
andpauseMusic()
. - Call
dispose()
when the combat area is no longer needed.
Example:
CombatTerrainFactory terrainFactory = new CombatTerrainFactory();
Entity player = PlayerFactory.createPlayer();
Entity enemy = EnemyFactory.createEnemy();
GdxGame game = new GdxGame();
CombatArea combatArea = new CombatArea(player, enemy, game, terrainFactory);
combatArea.create();
// During combat
combatArea.startPlayerAnimation(CombatArea.CombatAnimation.MOVE);
combatArea.startEnemyAnimation(CombatArea.CombatAnimation.IDLE);
// When combat is over
combatArea.dispose();
- The
CombatArea
class extends the abstractGameArea
class. - It uses a
CombatTerrainFactory
to create the combat environment. - Different enemy types can be spawned based on the game's requirements.
- The class manages its own assets, including loading and unloading them.
- Music and sound effects are handled through the
AudioManager
.