Class Interactable

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

    class Interactable
    extends Item
    An Interactable is an Item with which the Character may interact.
    Author:
    ENG1 Team 23 (Cohort 3)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Runnable action
      The action to execute after interact() has been finished.
      private float interactionThreshold
      The square of the maximum interaction distance; that is, the maximum distance, measured by the Euclidean metric, that a Character may be from an Interactable to fire an interact().
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Interactable​(com.badlogic.gdx.math.Vector2 position, com.badlogic.gdx.graphics.Texture texture, Area area, float width, float height, java.lang.Runnable action)
      Instantiates a new Interactable Item with the given initial parameters
      (package private) Interactable​(com.badlogic.gdx.math.Vector2 position, com.badlogic.gdx.graphics.Texture texture, Area area, float scale, java.lang.Runnable action)
      Instantiates a new Interactable Item with the given initial parameters
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) void interact()
      Indicate that the Character has interacted with the Item
      (package private) boolean isClose​(com.badlogic.gdx.math.Vector2 position)
      Determines if the described Vector2 represents an object that is sufficiently close to the Interactable
      • Methods inherited from class java.lang.Object

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

      • interactionThreshold

        private final float interactionThreshold
        The square of the maximum interaction distance; that is, the maximum distance, measured by the Euclidean metric, that a Character may be from an Interactable to fire an interact().
        See Also:
        isClose(Vector2)
      • action

        private final java.lang.Runnable action
        The action to execute after interact() has been finished. The execution should be deferred to LibGDX to avoid potential threading-related race conditions.
        See Also:
        Runnable.run(), Application.postRunnable(Runnable), interact()
    • Constructor Detail

      • Interactable

        private Interactable​(com.badlogic.gdx.math.Vector2 position,
                             com.badlogic.gdx.graphics.Texture texture,
                             Area area,
                             float width,
                             float height,
                             java.lang.Runnable action)
        Instantiates a new Interactable Item with the given initial parameters
        Parameters:
        position - The initial position of the Interactable, specified as in-game metre components
        texture - The initial Sprite Texture
        area - The Area into which the Interactable should be drawn
        width - The initial width, in in-game metres
        height - The initial height, in in-game metres
        action - The Runnable method to execute upon interaction
      • Interactable

        Interactable​(com.badlogic.gdx.math.Vector2 position,
                     com.badlogic.gdx.graphics.Texture texture,
                     Area area,
                     float scale,
                     java.lang.Runnable action)
        Instantiates a new Interactable Item with the given initial parameters
        Parameters:
        position - The initial position of the Interactable, specified as in-game metre components
        texture - The initial Sprite Texture
        area - The Area into which the Interactable should be drawn
        scale - The multiplier by which the size of the Texture should be scaled, preserving aspect ratio
        action - The Runnable method to execute upon interaction
    • Method Detail

      • interact

        void interact()
        Indicate that the Character has interacted with the Item
        See Also:
        action
      • isClose

        boolean isClose​(com.badlogic.gdx.math.Vector2 position)
        Determines if the described Vector2 represents an object that is sufficiently close to the Interactable
        Parameters:
        position - The position to test
        Returns:
        Is the given Vector2 within the defined Euclidean distance of the Interactable?
        See Also:
        interactionThreshold