Class Area

  • All Implemented Interfaces:
    Drawable, com.badlogic.gdx.utils.Disposable

    public class Area
    extends java.lang.Object
    implements Drawable
    An Area is a single room or outdoor scene in which the player can exist, containing its own TiledMap texture and set of Interactable objects.
    Author:
    ENG1 Team 23 (Cohort 3)
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Area.Name
      Distinguishes between the standard Area instantiations
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private com.badlogic.gdx.math.Vector2 initialCharacterPosition
      The initial position of the player-controlled Character upon being spawned into the Area.
      private java.util.List<Interactable> interactables
      The list of Interactable objects existing in the Area
      private GameMap map
      The GameMap forming the background of the Area, including its respective rendering mechanisms
      private com.badlogic.gdx.physics.box2d.World world
      The LibGDX world responsible for holding BodyDef.BodyType.StaticBody and BodyDef.BodyType.DynamicBody collision zones, generally used for Interactable and TiledMap border objects
    • Constructor Summary

      Constructors 
      Constructor Description
      Area​(java.lang.String mapPath, com.badlogic.gdx.math.Vector2 initialCharacterPosition)
      Constructs a new Area with a TiledMap with a TMX file at the given path
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) void addInteractable​(Interactable interactable)
      Adds an Interactable to the set of interactable tiles in the current Area.
      com.badlogic.gdx.math.Vector2 bound​(com.badlogic.gdx.math.Vector2 candidate, float horizontalGutter, float verticalGutter)
      Bounds the given candidate vector along the given gutter boundaries and Map edges
      void dispose()
      Releases all resources used by the Area
      private void generateBorders​(com.badlogic.gdx.utils.Array<com.badlogic.gdx.maps.objects.RectangleMapObject> borderObjects)
      Generate the static collision bodies for all given border objects, as defined by the TiledMap
      com.badlogic.gdx.math.Vector2 getInitialCharacterPosition()
      Retrieves the initial Area-local Character position, in in-game metres
      (package private) com.badlogic.gdx.physics.box2d.Body registerCharacter​(float width, float height)
      Registers a new Character of the given width and height to the current Area
      (package private) com.badlogic.gdx.physics.box2d.Body registerCollisionBody​(com.badlogic.gdx.math.Vector2 initialPosition, com.badlogic.gdx.physics.box2d.BodyDef.BodyType type, float width, float height)
      Registers a new body with a standard collision box in the World corresponding to the Area
      void render​(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)
      Registers the current Area onto the given game instance SpriteBatch, including all Interactable objects
      void setInitialCharacterPosition​(com.badlogic.gdx.math.Vector2 position)
      Resets the initial Area-local Character position, in in-game metres
      void step()
      Steps the World associated with the Area
      void triggerInteractables​(com.badlogic.gdx.math.Vector2 characterPosition)
      Given the current position of the Character, interact with any nearby Interactable objects
      void updateView​(com.badlogic.gdx.graphics.OrthographicCamera gameCam)
      Instructs the GameMap rendering object to update its viewing position with respect to the OrthographicCamera game camera
      • Methods inherited from class java.lang.Object

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

      • world

        private final com.badlogic.gdx.physics.box2d.World world
        The LibGDX world responsible for holding BodyDef.BodyType.StaticBody and BodyDef.BodyType.DynamicBody collision zones, generally used for Interactable and TiledMap border objects
      • initialCharacterPosition

        private com.badlogic.gdx.math.Vector2 initialCharacterPosition
        The initial position of the player-controlled Character upon being spawned into the Area. This position Vector2 is specified in in-game metres.
        See Also:
        getInitialCharacterPosition()
    • Constructor Detail

      • Area

        Area​(java.lang.String mapPath,
             com.badlogic.gdx.math.Vector2 initialCharacterPosition)
        throws InvalidAreaException
        Constructs a new Area with a TiledMap with a TMX file at the given path
        Parameters:
        mapPath - The path of the Area's background texture
        initialCharacterPosition - The initial position of the Character on the Area map, specified by in-game metre components
        Throws:
        InvalidAreaException
        See Also:
        Character
    • Method Detail

      • triggerInteractables

        public void triggerInteractables​(com.badlogic.gdx.math.Vector2 characterPosition)
        Given the current position of the Character, interact with any nearby Interactable objects
        Parameters:
        characterPosition - The position of the player-controlled Character
        See Also:
        Interactable.interact()
      • bound

        public com.badlogic.gdx.math.Vector2 bound​(com.badlogic.gdx.math.Vector2 candidate,
                                                   float horizontalGutter,
                                                   float verticalGutter)
        Bounds the given candidate vector along the given gutter boundaries and Map edges
        Parameters:
        candidate - The vector to be bounded
        horizontalGutter - The gutter, specified as in-game metres, on the horizontal axis
        verticalGutter - The gutter, specified as in-game metres, on the vertical axis
        Returns:
        The bounded vector
        See Also:
        GameMap.bound(Vector2, float, float)
      • updateView

        public void updateView​(com.badlogic.gdx.graphics.OrthographicCamera gameCam)
        Instructs the GameMap rendering object to update its viewing position with respect to the OrthographicCamera game camera
        Parameters:
        gameCam - The OrthographicCamera game camera against which the Area viewport should be aligned
      • step

        public void step()
        Steps the World associated with the Area
        See Also:
        World.step(float, int, int)
      • registerCollisionBody

        com.badlogic.gdx.physics.box2d.Body registerCollisionBody​(com.badlogic.gdx.math.Vector2 initialPosition,
                                                                  com.badlogic.gdx.physics.box2d.BodyDef.BodyType type,
                                                                  float width,
                                                                  float height)
        Registers a new body with a standard collision box in the World corresponding to the Area
        Parameters:
        initialPosition - The initial position of the body, specified as in-game metre components
        type - The type of the body, according to BodyDef.BodyType
        width - The fixed width of the body, in in-game metres
        height - The fixed height of the body, in in-game metres
        Returns:
        The newly registered body
      • getInitialCharacterPosition

        public com.badlogic.gdx.math.Vector2 getInitialCharacterPosition()
        Retrieves the initial Area-local Character position, in in-game metres
        Returns:
        The requested position vector
        See Also:
        Character
      • setInitialCharacterPosition

        public void setInitialCharacterPosition​(com.badlogic.gdx.math.Vector2 position)
        Resets the initial Area-local Character position, in in-game metres
        Parameters:
        position - The new position
        See Also:
        Character
      • generateBorders

        private void generateBorders​(com.badlogic.gdx.utils.Array<com.badlogic.gdx.maps.objects.RectangleMapObject> borderObjects)
        Generate the static collision bodies for all given border objects, as defined by the TiledMap
        Parameters:
        borderObjects - The array of RectangleMapObjects represented the border vector
      • dispose

        public void dispose()
        Releases all resources used by the Area
        Specified by:
        dispose in interface com.badlogic.gdx.utils.Disposable
      • render

        public void render​(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)
        Registers the current Area onto the given game instance SpriteBatch, including all Interactable objects
        Specified by:
        render in interface Drawable
        Parameters:
        batch - The SpriteBatch to which the Area should be polled