Class NpcService

java.lang.Object
com.deco2800.game.entities.EntityService
com.deco2800.game.entities.NpcService

public class NpcService extends EntityService
Provides a global access point for NPC entities to register themselves. This allows for iterating over NPC entities to perform updates each loop. All NPC entities should be registered here.
  • Constructor Details

    • NpcService

      public NpcService()
  • Method Details

    • setNpcNum

      public void setNpcNum(int num)
    • getNpcNum

      public int getNpcNum()
    • setNpcType

      public void setNpcType(int num)
    • getNpcType

      public int getNpcType()
    • register

      public void register(Entity entity)
      Register a new entity with the NPC service. The entity will be created and start updating.
      Overrides:
      register in class EntityService
      Parameters:
      entity - new entity.
    • registerNamed

      public void registerNamed(String name, Entity entity)
      Registers an entity with a name so it can be found later
      Overrides:
      registerNamed in class EntityService
      Parameters:
      name - the name to register it as (must be unique or will overwrite)
      entity - the entity to register
    • getNamedEntity

      public Entity getNamedEntity(String name)
      Returns a registered named entity
      Overrides:
      getNamedEntity in class EntityService
      Parameters:
      name - the name the entity was registered as
      Returns:
      the registered entity or null
    • getLastEntity

      public Entity getLastEntity()
      Returns the last registered entity
      Overrides:
      getLastEntity in class EntityService
      Returns:
      the last registered entity or null
    • getAllNamedEntities

      public Map<String,Entity> getAllNamedEntities()
      Returns all registered entities
      Overrides:
      getAllNamedEntities in class EntityService
      Returns:
      all registered entities or null
    • unregister

      public void unregister(Entity entity)
      Unregister an entity with the NPC service. The entity will be removed and stop updating.
      Overrides:
      unregister in class EntityService
      Parameters:
      entity - entity to be removed.
    • update

      public void update()
      Update all registered entities. Should only be called from the main game loop.
      Overrides:
      update in class EntityService
    • dispose

      public void dispose()
      Dispose all entities.
      Overrides:
      dispose in class EntityService
    • npcClicked

      public static boolean npcClicked(int screenX, int screenY)
      Determine if NPCs on map are being clicked on
      Parameters:
      screenX - x coordinate
      screenY - y coordinate