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

Overview

The Big sawfish NPC is a slow enemy NPC that inhabits the Underwater Kingdom. With a speed of 2 units, it does not excel at rapidly closing the distance to its target, so player can easily avoid them with quick movements. Although its health and attack power are relatively strong, its speed and agility compensate, makes it a force to be reckoned with in the kingdom.

bigsawfish

Enemy Stats

Enemy chicken NPC stats are defined in an NPC.json file which are loaded into the game using the FileLoader class.

  • Health: 10
  • Base Attack: 10
  • Base Defense: 15
  • Speed: 75
  • Experience: 100

Big sawfish NPC Implementation

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

Create new chicken enemy NPC:

Entity bigsawfish = createBaseEnemy(target, EnemyType.BIGSAWFISH, config);

Creation of big sawfish enemy NPC, along with texture and animation:

public static Entity createBigsawfish(Entity target) {
        BaseEnemyEntityConfig config = configs.bigsawfish;
        Entity bigsawfish = createBaseEnemy(target, EnemyType.BIGSAWFISH, config);
        bigsawfish.setEnemyType(Entity.EnemyType.BIGSAWFISH);

        TextureAtlas bigsawfishAtlas = ServiceLocator.getResourceService().getAsset(config.getSpritePath(), TextureAtlas.class);

        AnimationRenderComponent animator = new AnimationRenderComponent(bigsawfishAtlas);

        animator.addAnimation("chase", 0.5f, Animation.PlayMode.LOOP);
        animator.addAnimation("float", 0.5f, Animation.PlayMode.LOOP);
        animator.addAnimation("spawn", 1.0f, Animation.PlayMode.NORMAL);

        bigsawfish
                .addComponent(animator)
                .addComponent(new BigsawfishAnimationController());


        bigsawfish.setScale(2f,1.38f);

        return bigsawfish;
    }

Enemy Big sawfish NPCs are spawned in UnderwaterGameTerrain 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
    }
  }
⚠️ **GitHub.com Fallback** ⚠️