Class Point

  • All Implemented Interfaces:
    Position, java.io.Serializable


    public class Point
    extends com.badlogic.gdx.math.Vector3
    implements Position
    A point is a single position in the game world not bound to the grid. Use this for entities.
    Since:
    WE1.1
    See Also:
    Serialized Form
    • Field Summary

      • Fields inherited from class com.badlogic.gdx.math.Vector3

        x, X, y, Y, z, Z, Zero
    • Constructor Summary

      Constructors 
      Constructor Description
      Point​()
      Creates a point refering to a position in the game world.
      Point​(float posX, float posY, float height)
      Creates a point refering to a position in the game world.
      Point​(com.badlogic.gdx.math.Vector3 vec)  
      Point​(Point point)
      Copy-constructor.
    • Constructor Detail

      • Point

        public Point​()
        Creates a point refering to a position in the game world. Points at 0,0,0.
      • Point

        public Point​(float posX,
                     float posY,
                     float height)
        Creates a point refering to a position in the game world.
        Parameters:
        posX - The distance from the left border of the map (game space)
        posY - The distance from the top border of the map (game space)
        height - The distance from ground (game space)
      • Point

        public Point​(com.badlogic.gdx.math.Vector3 vec)
        Parameters:
        vec -
      • Point

        public Point​(Point point)
        Copy-constructor. This constructor copies the values.
        Parameters:
        point - the source of the copy
    • Method Detail

      • getShared

        public static Point getShared​()
        A shared object to pass values without using the heap.
        Returns:
      • getZ

        public float getZ​()
        Get the height (z-value) of the coordinate.
        Returns:
        game dimension
      • getZGrid

        public int getZGrid​()
        Description copied from interface: Position
        Get the z in block grid coordinates of the coordinate. Faster than transforming to coordinate first.
        Specified by:
        getZGrid in interface Position
        Returns:
        in grid coordinates.
      • getZPoint

        public float getZPoint​()
        Description copied from interface: Position
        Get the z in game world coordinates.
        Specified by:
        getZPoint in interface Position
        Returns:
      • setZ

        public void setZ​(float height)
        Parameters:
        height -
      • toCoord

        public Coordinate toCoord​()
        returns coordinate aquivalent. Removes floating of block.
        Looks complicated but has runtime O(const). You should avoid this method in loops or the update method because it uses the heap.
        Specified by:
        toCoord in interface Position
        Returns:
        coordinate aquivalent, copy safe
      • getCoord

        public Coordinate getCoord​()
        Description copied from interface: Position
        May not be copy safe.
        Specified by:
        getCoord in interface Position
        Returns:
        may not be copy safe
      • getPoint

        public Point getPoint​()
        Description copied from interface: Position
        May not be copy safe.
        Specified by:
        getPoint in interface Position
        Returns:
        may not be copy safe
      • toPoint

        public Point toPoint​()
        Description copied from interface: Position
        Calculates it and creates new instance if not already in correct format then return a copy of itself.
        Specified by:
        toPoint in interface Position
        Returns:
        the point representation. Copy safe.
      • getX

        public float getX​()
        Get the game world position from left
        Returns:
      • getY

        public float getY​()
        Get the game world position from top.
        Returns:
      • getDistanceToCellCenterX

        public float getDistanceToCellCenterX​()
        Distance to cell center.
        Returns:
        the offset to the coordinates center.
      • getDistanceToCellCenterY

        public float getDistanceToCellCenterY​()
        Distance to cell center.
        Returns:
        the offset to the coordinates center.
      • getDistanceToCellCenterZ

        public float getDistanceToCellCenterZ​()
        Distance to cell center.
        Returns:
        the offset to the coordinates center.
      • getBlockId

        public byte getBlockId​()
        Description copied from interface: Position
        Get the block at the position. Clamps positions over the map at topmost layer.
        Specified by:
        getBlockId in interface Position
        Returns:
        If the coordiante is not in memory will crash.
      • getBlock

        public int getBlock​()
        Returns:
      • cpy

        public Point cpy​()
        avoid this method because it creates a new instance.
        Specified by:
        cpy in interface Position
        Overrides:
        cpy in class com.badlogic.gdx.math.Vector3
        Returns:
      • getViewSpcX

        public int getViewSpcX​()
        Description copied from interface: Position
        Calculate position in view space.
        Specified by:
        getViewSpcX in interface Position
        Returns:
        Returns the center of the projected (screen) x-position where the object is rendered without regarding the camera. It also adds the cell offset.
      • getViewSpcY

        public int getViewSpcY​()
        Description copied from interface: Position
        Calculate position in view space.
        Specified by:
        getViewSpcY in interface Position
        Returns:
        Returns the center of the projected (view space) y-position where the object is rendered without regarding the camera.
      • getProjectionSpaceX

        public int getProjectionSpaceX​(GameView view,
                                       Camera camera)
        Description copied from interface: Position
        equals screen space when zoom=1 with a single, fullscreen camera.
        Specified by:
        getProjectionSpaceX in interface Position
        Returns:
      • getProjectionSpaceY

        public int getProjectionSpaceY​(GameView view,
                                       Camera camera)
        Description copied from interface: Position
        equals screen space when zoom=1 with a single camera.
        Specified by:
        getProjectionSpaceY in interface Position
        Returns:
      • isInMemoryAreaXY

        public boolean isInMemoryAreaXY​()
        Description copied from interface: Position
        Checks if the coordiantes are accessable with the currently loaded chunks. Does not check for z axis (horizontal only). So the position can be udner or over the map.
        Specified by:
        isInMemoryAreaXY in interface Position
        Returns:
      • isInMemoryAreaXYZ

        public boolean isInMemoryAreaXYZ​()
        Description copied from interface: Position
        Checks if the position is on the chunks currently in memory. Checks all axis'.
        Specified by:
        isInMemoryAreaXYZ in interface Position
        Returns:
        true if inside a chunk. false if currently not loaded or outside range.
      • add

        public Point add​(float[] vector)
        Add a vector to the position
        Parameters:
        vector - all values in game world values
        Returns:
        returns itself
      • add

        public Point add​(com.badlogic.gdx.math.Vector2 vector)
        Add a vector to the position
        Parameters:
        vector - all values in game world values
        Returns:
        returns itself
      • add

        public Point add​(com.badlogic.gdx.math.Vector3 vector)
        Add a vector to the position
        Overrides:
        add in class com.badlogic.gdx.math.Vector3
        Parameters:
        vector - all values in game world values
        Returns:
        returns itself
      • add

        public Point add​(float x,
                         float y,
                         float z)
        Add a vector to the position
        Overrides:
        add in class com.badlogic.gdx.math.Vector3
        Parameters:
        x - x value to add
        y - y value to add
        z - height to add
        Returns:
        returns itself
      • setToCenterOfCell

        public Point setToCenterOfCell​()
        Relative to the current coordiante field set the offset.
        Returns:
      • distanceTo

        public float distanceTo​(Position pos)
        Specified by:
        distanceTo in interface Position
        Parameters:
        pos -
        Returns:
        the distance from this point to the other point in game world coordinates
      • distanceTo

        public float distanceTo​(Point point)
        Parameters:
        point -
        Returns:
        the distance from this point to the other point in game coordinates
      • distanceTo

        public float distanceTo​(AbstractGameObject object)
        Specified by:
        distanceTo in interface Position
        Parameters:
        object -
        Returns:
        the distance from this point to the other object
      • distanceToSquared

        public float distanceToSquared​(Point point)
        The result is squared for fast comparison.
        Parameters:
        point -
        Returns:
        the distance from this point to the other point in game coordinates squared
      • distanceToHorizontal

        public float distanceToHorizontal​(Point point)
        checks only x and y.
        Parameters:
        point -
        Returns:
        the distance from this point to the other point only regarding horizontal components.
      • distanceToHorizontalSquared

        public float distanceToHorizontalSquared​(Point point)
        checks only x and y.
        Parameters:
        point -
        Returns:
        the distance from this point to the other point only regarding horizontal components.
      • distanceToHorizontal

        public float distanceToHorizontal​(AbstractGameObject object)
        checks only x and y.
        Specified by:
        distanceToHorizontal in interface Position
        Parameters:
        object -
        Returns:
        the distance from this point to the other point only regarding horizontal components.
      • distanceToHorizontal

        public float distanceToHorizontal​(Position pos)
        Description copied from interface: Position
        checks only x and y.
        Specified by:
        distanceToHorizontal in interface Position
        Returns:
        the distance from this pos to the other pos only regarding horizontal components.
      • distanceToHorizontalSquared

        public float distanceToHorizontalSquared​(AbstractGameObject object)
        checks only x and y.
        Specified by:
        distanceToHorizontalSquared in interface Position
        Parameters:
        object -
        Returns:
        the distance from this point to the other point only regarding horizontal components.
      • distanceToHorizontalSquared

        public float distanceToHorizontalSquared​(Position pos)
        Description copied from interface: Position
        checks only x and y.
        Specified by:
        distanceToHorizontalSquared in interface Position
        Returns:
        the distance from this pos to the other pos squared only regarding horizontal components.
      • getEntitiesNearby

        public java.util.ArrayList<AbstractEntity> getEntitiesNearby​(float radius)
        get entities in radius
        Parameters:
        radius - in game dimension pixels
        Returns:
        every entitie in radius
      • getEntitiesNearbyHorizontal

        public java.util.LinkedList<AbstractEntity> getEntitiesNearbyHorizontal​(float radius)
        Description copied from interface: Position
        get entities in radius (horizontal only)
        Specified by:
        getEntitiesNearbyHorizontal in interface Position
        Parameters:
        radius - in game dimension pixels
        Returns:
        every entitie in radius
      • getEntitiesNearbyHorizontal

        public <T> java.util.LinkedList<T> getEntitiesNearbyHorizontal​(float radius,
                                                                       java.lang.Class<T> type)
        Description copied from interface: Position
        get entities in horizontal radius (like a pipe)
        Specified by:
        getEntitiesNearbyHorizontal in interface Position
        Parameters:
        radius - in game dimension pixels
        type - whitelist
        Returns:
        every entitie in radius
      • getChunkX

        public int getChunkX​()
        Description copied from interface: Position
        The chunk coordinate.
        Specified by:
        getChunkX in interface Position
        Returns:
      • getChunkY

        public int getChunkY​()
        Description copied from interface: Position
        The chunk coordinate.
        Specified by:
        getChunkY in interface Position
        Returns:
      • canSee

        public boolean canSee​(Point p,
                              float maxdistance)
        Parameters:
        p -
        maxdistance - game space in meters
        Returns:
      • set

        public Point set​(Point point)
        overwrites the coordinates with values from another point. Faster then creating a new object-
        Parameters:
        point - is not modified
        Returns:
        itself for chaining
      • getEntitiesNearby

        public <T> java.util.LinkedList<T> getEntitiesNearby​(float radius,
                                                             java.lang.Class<T> type)
        Description copied from interface: Position
        Get entities in radius.
        Specified by:
        getEntitiesNearby in interface Position
        Type Parameters:
        T - returns only object if type which is the filter
        Parameters:
        radius - in game dimension pixels
        type - the type you want to filter
        Returns:
        every entitie in radius
      • setFromCoord

        public Point setFromCoord​(Coordinate coord)
        Set x,y,z based on a coordinate.
        Parameters:
        coord -
        Returns:
      • isObstacle

        public boolean isObstacle​()
        Returns: