Module hanyaeger

Class YaegerEntity

java.lang.Object
com.github.hanyaeger.core.YaegerGameObject
com.github.hanyaeger.api.entities.YaegerEntity
All Implemented Interfaces:
Rotatable, Effectable, Anchorable, Bounded, DragRepositoryAccessor, EventInitiator, GameNode, Placeable, Removable, SceneChild, Initializable, com.github.hanyaeger.core.scenes.DimensionsProvider, TimerListProvider
Direct Known Subclasses:
CompositeEntity, ShapeEntity, SpriteEntity

A YaegerEntity is the base class for all things that can be drawn on a YaegerScene.
  • Constructor Details

  • Method Details

    • setCursor

      public void setCursor(javafx.scene.Cursor cursor)
      Set the cursor to be shown. This cursor will be applied to the whole YaegerScene.
      Parameters:
      cursor - the Cursor to be shown
    • getCursor

      public javafx.scene.Cursor getCursor()
      Return the Cursor that is currently being used. If this YaegerEntity is not yet part of a YaegerScene, this method will return null.
      Returns:
      the Cursor
    • setVisible

      public void setVisible(boolean visible)
      Change the visibility of this YaegerEntity. The value can be either true or false. Use the method setOpacity(double) to set the transparency of the YaegerEntity.
      Parameters:
      visible - a boolean representing the visibility if the YaegerEntity
    • isVisible

      public boolean isVisible()
      Return the visibility of this YaegerEntity.
      Returns:
      the visibility of this YaegerEntity as a boolean
    • setOpacity

      public void setOpacity(double opacity)
      Specifies how opaque (that is, solid) the YaegerEntity appears. An Entity with 0% opacity is fully translucent. That is, while it is still visible and rendered, you generally won't be able to see it.

      Opacity is specified as a value between 0 and 1. Values less than 0 are treated as 0, values greater than 1 are treated as 1.

      Parameters:
      opacity - a double between 0 and 1
    • getOpacity

      public double getOpacity()
      Return the opacity of this YaegerEntity, meaning how opaque (that is, solid) the YaegerEntity appears. An YaegerEntity with 0% opacity is fully translucent. That is, while it is still visible and rendered, you generally won't be able to see it.

      Opacity is specified as a value between 0 and 1. Values less than 0 are treated as 0, values greater than 1 are treated as 1.

      Returns:
      the opacity of this YaegerEntity
    • distanceTo

      public double distanceTo(YaegerEntity entity)
      Calculates the distance to a given YaegerEntity. This distance is based on the AnchorPoint of the Entities and not on the shortest distance between them.
      Parameters:
      entity - the YaegerEntity to which the distance should be calculated.
      Returns:
      The distance as a double
    • distanceTo

      public double distanceTo(Coordinate2D location)
      Calculates the distance between the AnchorPoint of this YaegerEntity and the given Coordinate2D.
      Parameters:
      location - the Coordinate2D to which the distance should be calculated
      Returns:
      the distance as a double
    • angleTo

      public double angleTo(YaegerEntity entity)
      Computes the angle (in degrees) between the unit vector that originates at the getAnchorLocation() point of this YaegerEntity and the vector with its origin at that same getAnchorLocation() that points towards the getAnchorLocation() of the specified YaegerEntity. Note that the unit vector points downwards, so:
      • If otherLocation is directly below the reference point of this YaegerEntity, the angle will be 0 degrees.
      • If otherLocation is directly above the reference point of this YaegerEntity, the angle will be 180 degrees.
      • If otherLocation is directly to the right of the reference point of this YaegerEntity, the angle will be 90 degrees.
      • If otherLocation is directly to the left of the reference point of this YaegerEntity, the angle will be 270 degrees.
      Parameters:
      entity - the YaegerEntity of the other vector
      Returns:
      the angle between the two vectors measured in degrees, NaN if any of the two vectors is a zero vector
      Throws:
      NullPointerException - if the specified location is null
    • angleTo

      public double angleTo(Coordinate2D otherLocation)
      Computes the angle (in degrees) between the unit vector that originates at the getAnchorLocation() of this YaegerEntity and the vector with its origin at that same getAnchorLocation() that points towards the specified Coordinate2D. Note that the unit vector points downwards, so:
      • If otherLocation is directly below the reference point of this YaegerEntity, the angle will be 0 degrees.
      • If otherLocation is directly above the reference point of this YaegerEntity, the angle will be 180 degrees.
      • If otherLocation is directly to the right of the reference point of this YaegerEntity, the angle will be 90 degrees.
      • If otherLocation is directly to the left of the reference point of this YaegerEntity, the angle will be 270 degrees.
      Parameters:
      otherLocation - the Coordinate2D of the other vector
      Returns:
      the angle between the two vectors measured in degrees, NaN if any of the two vectors is a zero vector
      Throws:
      NullPointerException - if the specified otherLocation is null
    • addToEntityCollection

      public void addToEntityCollection(EntityCollection collection)
      Add this YaegerEntity to the EntityCollection, which will make it part of the YaegerGame. Since an EntityCollection contains different lists of Entities, a YaegerEntity itself is responsible for knowing to which list it should be added.

      Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.

      Parameters:
      collection - the EntityCollection to which this YaegerEntity should add itself
    • applyTranslationsForAnchorPoint

      public void applyTranslationsForAnchorPoint()
      A YaegerEntity's location is defined by its anchorLocation and its anchorPoint. For most implementation of YaegerEntity, the default anchorPoint is TOP_LEFT. Using a different anchorpoint will mean a translation will be applied. Its anchorLocation will remain te same.

      Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.

    • init

      public void init(com.google.inject.Injector injector)
      Specified by:
      init in interface Initializable
      Parameters:
      injector - the Injector used for Dependency Injection

      Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.

    • setAnchorPoint

      public void setAnchorPoint(AnchorPoint anchorPoint)
      Description copied from interface: Anchorable
      Set the AnchorPoint of this Placeable. The AnchorPoint can be used for aligning the YaegerEntity, and will be used to set the given x, y-coordinate. By default, a Placeable will use the top-left as its anchor-point.
      Specified by:
      setAnchorPoint in interface Anchorable
      Parameters:
      anchorPoint - the AnchorPoint of this YaegerEntity
    • getAnchorPoint

      public AnchorPoint getAnchorPoint()
      Description copied from interface: Anchorable
      Return the AnchorPoint of this Placeable.
      Specified by:
      getAnchorPoint in interface Anchorable
      Returns:
      the AnchorPoint of this Placeable
    • setAnchorLocation

      public void setAnchorLocation(Coordinate2D anchorLocation)
      Description copied from interface: Placeable
      Set the Coordinate2D where the AnchorPoint of this YaegerEntity will be placed, within the YaegerScene.
      Specified by:
      setAnchorLocation in interface Placeable
      Parameters:
      anchorLocation - the Coordinate2D that should be used
    • getAnchorLocation

      public Coordinate2D getAnchorLocation()
      Description copied from interface: Placeable
      Return the Coordinate2D where the AnchorPoint of this YaegerEntity is placed, within the YaegerScene.
      Specified by:
      getAnchorLocation in interface Placeable
      Returns:
      the Coordinate2D that is currently being used
    • setAnchorLocationX

      public void setAnchorLocationX(double x)
      Description copied from interface: Placeable
      Set the x-coordinate of the AnchorLocation of this YaegerEntity;
      Specified by:
      setAnchorLocationX in interface Placeable
      Parameters:
      x - the x-coordinate as a double
    • setAnchorLocationY

      public void setAnchorLocationY(double y)
      Description copied from interface: Placeable
      Set the y-coordinate of the AnchorLocation of this YaegerEntity;
      Specified by:
      setAnchorLocationY in interface Placeable
      Parameters:
      y - the y-coordinate as a double
    • remove

      public void remove()
      Description copied from interface: Removable
      Perform all necessary actions to remove the entity.
      Specified by:
      remove in interface Removable
    • getTimers

      public List<Timer> getTimers()
      Description copied from interface: TimerListProvider
      Return the List of Timer instances.
      Specified by:
      getTimers in interface TimerListProvider
      Returns:
      the List of Timer instances
    • transferCoordinatesToNode

      public void transferCoordinatesToNode()
      Description copied from interface: Placeable
      Transfer the x and y-coordinate of this YaegerEntity to its JavaFX Node and apply the requested transformations.

      Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.

      Specified by:
      transferCoordinatesToNode in interface Placeable
    • attachEventListener

      public void attachEventListener(javafx.event.EventType eventType, javafx.event.EventHandler eventHandler)
      Description copied from interface: EventInitiator
      Attach an EventHandler for the given EventType.

      Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.

      Specified by:
      attachEventListener in interface EventInitiator
      Parameters:
      eventType - the EventType that should trigger the given EventHandler
      eventHandler - the EventHandler that should be called whenever an event of type EventType occurs
    • applyEntityProcessor

      public void applyEntityProcessor(EntityProcessor processor)
      Apply an EntityProcessor to this YaegerEntity. An EntityProcessor is most likely a lambda expression passed by a parent object.

      Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.

      Parameters:
      processor - an instance of EntityProcessor, most likely a lambda expression that should be called for processing this YaegerEntity
    • addToParent

      public void addToParent(EntityProcessor processor)
      The Node encapsulated by this YaegerEntity should be added to a parent Node to be displayed on the screen and become part of the YaegerScene.

      Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.

      Parameters:
      processor - an instance of EntityProcessor, most likely a lambda expression that can be used for adding this node as a child to a parent node
    • getInitializationBuffer

      public InitializationBuffer getInitializationBuffer()
      Description copied from interface: Rotatable
      Return an instance of InitializationBuffer to be used whenever a Node is unavailable to apply the rotation.
      Specified by:
      getInitializationBuffer in interface Rotatable
      Returns:
      An instance of InitializationBuffer.
    • getDragNDropRepository

      public DragNDropRepository getDragNDropRepository()
      Description copied from interface: DragRepositoryAccessor
      Return the DragNDropRepository that was set on this DragRepositoryAccessor.

      Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.

      Specified by:
      getDragNDropRepository in interface DragRepositoryAccessor
      Returns:
      the instance of DragNDropRepository
    • setViewOrder

      public void setViewOrder(double viewOrder)
      Set the viewOrder of this YaegerEntity. The viewOrder defines the rendering order of this YaegerEntity within the YaegerScene. The lower the viewOrder, the closer the YaegerEntity is to the front of the YaegerScene.

      By default, a YaegerEntity will receive the viewOrder of ViewOrders.VIEW_ORDER_ENTITY_DEFAULT. A YaegerEntity that is part of an TileMap will default to the value 100 to ensure it is placed behind other Entities.

      Parameters:
      viewOrder - the value of viewOrder as a double
    • getViewOrder

      public double getViewOrder()
      Return the viewOrder of this YaegerEntity. The viewOrder defines the rendering order of this YaegerEntity within the YaegerScene. The lower the viewOrder, the closer the YaegerEntity is to the front of the YaegerScene.

      By default, a YaegerEntity will receive the viewOrder of ViewOrders.VIEW_ORDER_ENTITY_DEFAULT. A YaegerEntity that is part of an TileMap will default to the value 100 to ensure it is placed behind other Entities.

      Returns:
      the value of viewOrder as a double
    • getLocationInScene

      protected Coordinate2D getLocationInScene()
      Calculate the absolute location of this YaegerEntity in the scene. Because CompositeEntity uses a relative coordinate system, this method is needed to make calculations for entities that are part of a CompositeEntity.
      Returns:
      a Coordinate2D with the absolute coordinates of the YaegerEntity.
    • getRootPane

      public javafx.scene.layout.Pane getRootPane()
      Return the root pane to which this YaegerEntity is added.

      Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.

      Returns:
      the root pane, which is an instance of Pane
    • setRootPane

      public void setRootPane(javafx.scene.layout.Pane rootPane)
      Set the root pane to which this YaegerEntity is added.

      Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.

      Parameters:
      rootPane - the root pane, which is an instance of Pane
    • setDragNDropRepository

      @Inject public void setDragNDropRepository(DragNDropRepository dragNDropRepository)
      Set the DragNDropRepository to be used.
      Specified by:
      setDragNDropRepository in interface DragRepositoryAccessor
      Parameters:
      dragNDropRepository - the DragNDropRepository to be used
    • getSceneWidth

      public double getSceneWidth()
      Description copied from interface: SceneChild
      Return the width of the YaegerScene that this Entity is part of. For both a StaticScene and DynamicScene, the full width is always visible. In case of a ScrollableDynamicScene, this is not the case, since it can be larger that the viewable area.
      Specified by:
      getSceneWidth in interface SceneChild
      Returns:
      the width of this YaegerScene as a double
    • getSceneHeight

      public double getSceneHeight()
      Description copied from interface: SceneChild
      Return the height of the YaegerScene that this Entity is part of. For both a StaticScene and DynamicScene, the full height is always visible. In case of a ScrollableDynamicScene, this is not the case, since it can be larger that the viewable area.
      Specified by:
      getSceneHeight in interface SceneChild
      Returns:
      the height of this YaegerScene as a double