Octopus (Enemy NPC) - UQcsse3200/2024-studio-2 GitHub Wiki

Overview

The Octopus NPC is a formidable enemy residing in the Water Kingdom. This massive aquatic creature is known for its powerful and aggressive nature, making it a significant challenge for players. It's a big, tanky creature adept at navigating underwater environments, using its strength and defences to overwhelm those who target it. octopus

Enemy Stats

The Octopus NPC's stats are defined in an NPC.json file, which is loaded into the game using the FileLoader class.

  • Health: 8
  • Base Attack: 2
  • Base Defense: 5
  • Speed: 170
  • Experience: 15

Octopus NPC Implementation

The Octopus NPC is generated through the EnemyFactory class, which is responsible for creating non-playable character (NPC) entities.

This includes the creation of the Octopus NPC, complete with texture and animation, utilizing the following stats:

public static Entity createOctopusCombatEnemy() {
        BaseEnemyEntityConfig config = configs.octopus;
        Entity octopusEnemy = createCombatNPC(config);
        octopusEnemy.setEnemyType(Entity.EnemyType.OCTOPUS);
        
        octopusEnemy
                .addComponent(new TextureRenderComponent("images/octopus_idle.png"));
        octopusEnemy.scaleHeight(90.0f);
        
        return octopusEnemy;
    }

Enemy octopusEnemy NPCs are spawned in ForestGameTerrain class through randomisation based on the player's position:

 private void spawnRandomEnemy(Supplier<Entity> creator, int numItems, double proximityRange) {
    GridPoint2 minPos = new GridPoint2(PLAYER_SPAWN.x - 20, PLAYER_SPAWN.y - 20);
    GridPoint2 maxPos = new GridPoint2(PLAYER_SPAWN.x + 20, PLAYER_SPAWN.y + 20);

    for (int i = 0; i < numItems; i++) {
      GridPoint2 randomPos = RandomUtils.random(minPos, maxPos);
      Entity enemy = creator.get();
      spawnEntityAt(enemy, randomPos, true, false);
      enemies.add(enemy);
      enemy.addComponent(new ProximityComponent(player, proximityRange)); // Add ProximityComponent
    }
  }

Sequence Diagram

image image
⚠️ **GitHub.com Fallback** ⚠️