Class NPC

  • Direct Known Subclasses:
    CrewMembers, Infiltrator

    public abstract class NPC
    extends com.badlogic.gdx.graphics.g2d.Sprite
    NPCs use nodes to walk around and A* to navigate between them, the nodes are generated and stored in GraphCreator, while MapGraph is used to search and manipulate the node graph. Generally, NPCs are updated through updateNPC, which calls each npcs step method, which makes them moves, sets their sprite scale, checks if they have reached the next node etc Crewmember is very simple, they walk around randomly and wait for a random amount of time Infiltrator is more complex, they sometimes go to destroy keysystems, and can use abilities
    • Field Summary

      Fields 
      Modifier and Type Field Description
      MapGraph mapGraph
      Mapgraph for the NPC to reference.
    • Constructor Summary

      Constructors 
      Constructor Description
      NPC​(com.badlogic.gdx.graphics.g2d.Sprite sprite, float x, float y, MapGraph newMapGraph, float speed)  
      NPC​(com.badlogic.gdx.graphics.g2d.Sprite sprite, Node start, MapGraph newMapGraph, float speed)
      Constructor for NPC.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void checkCollision​(float speed)
      Checks whether the NPC has made it to the next node.
      void clearPathQueue()
      Clears this NPC's pathQueue.
      static void disposeNPC()
      Dispose method to be called in dispose method of screen.
      float getElapsedTime()
      Returns how long this NPC has been waiting for.
      int getIndex()
      Gets the index of this NPC.
      com.badlogic.gdx.utils.Queue<Node> getPathQueue()
      Returns the path this NPC is following.
      Node getPreviousNode()
      Gets the previous node that this NPC visited.
      com.badlogic.gdx.math.Vector2 getVelocity()
      Gets this NPC's velocity.
      void incrementElapsedTime​(float delta)
      Increases the elapsed time by the given value.
      void moveNPC​(float deltaTime)
      Moves the NPC based on their movement vector, and sets their sprite in the direction of movement.
      abstract void reachDestination()
      A placeholder function to be superceded by subclasses own reachDestination().
      void reachNextNode​(float speed)
      Called when NPC has reached a node, sets the next node to be moved to, or if the path queue is empty, destination is reached.
      static void render​(com.badlogic.gdx.graphics.g2d.Batch batch)
      Render method for rendering all NPCs.
      void resetElapsedTime()
      Sets the elapsed time to 0.
      void setGoal​(Node goal, float speed)
      Sets the goal node and calculates the path to take there.
      void setIndex​(int newIndex)
      Sets the index of this NPC.
      void setSpeedToNextNode​(float speed)
      Sets the velocity towards the next node.
      void setVelocity​(com.badlogic.gdx.math.Vector2 newVelocity)
      Sets this NPC's velocity.
      static void updateNPC​(Player p, float delta)
      Updates every NPC, to be called in a screens update method.
      • Methods inherited from class com.badlogic.gdx.graphics.g2d.Sprite

        draw, draw, flip, getBoundingRectangle, getColor, getHeight, getOriginX, getOriginY, getRotation, getScaleX, getScaleY, getVertices, getWidth, getX, getY, rotate, rotate90, scale, scroll, set, setAlpha, setBounds, setCenter, setCenterX, setCenterY, setColor, setColor, setFlip, setOrigin, setOriginBasedPosition, setOriginCenter, setPackedColor, setPosition, setRegion, setRotation, setScale, setScale, setSize, setU, setU2, setV, setV2, setX, setY, translate, translateX, translateY
      • Methods inherited from class com.badlogic.gdx.graphics.g2d.TextureRegion

        getRegionHeight, getRegionWidth, getRegionX, getRegionY, getTexture, getU, getU2, getV, getV2, isFlipX, isFlipY, setRegion, setRegion, setRegion, setRegion, setRegionHeight, setRegionWidth, setRegionX, setRegionY, setTexture, split, split
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • mapGraph

        public MapGraph mapGraph
        Mapgraph for the NPC to reference.
    • Constructor Detail

      • NPC

        public NPC​(com.badlogic.gdx.graphics.g2d.Sprite sprite,
                   Node start,
                   MapGraph newMapGraph,
                   float speed)
        Constructor for NPC.
        Parameters:
        sprite - Sprite to be used for the NPC
        start - Node for the NPC to start at
        newMapGraph - mapGraph for the NPC to reference
        speed - The speed of this NPC.
      • NPC

        public NPC​(com.badlogic.gdx.graphics.g2d.Sprite sprite,
                   float x,
                   float y,
                   MapGraph newMapGraph,
                   float speed)
    • Method Detail

      • updateNPC

        public static void updateNPC​(Player p,
                                     float delta)
        Updates every NPC, to be called in a screens update method.
        Parameters:
        p - The current instance of the player.
        delta - Float of time between last and current frame, used for movement
      • setGoal

        public void setGoal​(Node goal,
                            float speed)
        Sets the goal node and calculates the path to take there.
        Parameters:
        goal - Node to move NPC to.
        speed - The speed of this NPC.
      • checkCollision

        public void checkCollision​(float speed)
        Checks whether the NPC has made it to the next node.
        Parameters:
        speed - The speed of this NPC.
      • reachNextNode

        public void reachNextNode​(float speed)
        Called when NPC has reached a node, sets the next node to be moved to, or if the path queue is empty, destination is reached.
        Parameters:
        speed - The speed of this NPC.
      • setSpeedToNextNode

        public void setSpeedToNextNode​(float speed)
        Sets the velocity towards the next node.
        Parameters:
        speed - The speed of this NPC.
      • moveNPC

        public void moveNPC​(float deltaTime)
        Moves the NPC based on their movement vector, and sets their sprite in the direction of movement.
        Parameters:
        deltaTime - The time since the previous frame in seconds.
      • render

        public static void render​(com.badlogic.gdx.graphics.g2d.Batch batch)
        Render method for rendering all NPCs.
        Parameters:
        batch - Batch for the NPCs to render in.
      • disposeNPC

        public static void disposeNPC()
        Dispose method to be called in dispose method of screen.
      • reachDestination

        public abstract void reachDestination()
        A placeholder function to be superceded by subclasses own reachDestination().
      • getIndex

        public int getIndex()
        Gets the index of this NPC.
        Returns:
        the index of this NPC.
      • setIndex

        public void setIndex​(int newIndex)
        Sets the index of this NPC.
        Parameters:
        newIndex - The new index for this NPC.
      • getVelocity

        public com.badlogic.gdx.math.Vector2 getVelocity()
        Gets this NPC's velocity.
        Returns:
        this NPC's velocity.
      • setVelocity

        public void setVelocity​(com.badlogic.gdx.math.Vector2 newVelocity)
        Sets this NPC's velocity.
        Parameters:
        newVelocity - The new velocity for this NPC.
      • getPreviousNode

        public Node getPreviousNode()
        Gets the previous node that this NPC visited.
        Returns:
        The previous node that this NPC visited.
      • getElapsedTime

        public float getElapsedTime()
        Returns how long this NPC has been waiting for.
        Returns:
        the elapsedTime variable.
      • resetElapsedTime

        public void resetElapsedTime()
        Sets the elapsed time to 0.
      • getPathQueue

        public com.badlogic.gdx.utils.Queue<Node> getPathQueue()
        Returns the path this NPC is following.
        Returns:
        The path that this NPC is following.
      • incrementElapsedTime

        public void incrementElapsedTime​(float delta)
        Increases the elapsed time by the given value.
        Parameters:
        delta - The amount to increase the elapsed time by.
      • clearPathQueue

        public void clearPathQueue()
        Clears this NPC's pathQueue.