Class Coordinate

  • All Implemented Interfaces:
    Position, java.io.Serializable
    Direct Known Subclasses:
    PfNode


    public class Coordinate
    extends java.lang.Object
    implements Position
    A coordinate is a reference to a specific cell in the map. The coordinate uses a continously height value. The Z coordinate value can be calculated.
    See Also:
    Serialized Form
    • Constructor Detail

      • Coordinate

        public Coordinate​()
        0,0,0,
      • Coordinate

        public Coordinate​(int x,
                          int y,
                          int z)
        Creates a coordiante refering to the given position on the map.
        Parameters:
        x - The x value as coordinate.
        y - The y value as coordinate.
        z - The z value as coordinate.
      • Coordinate

        public Coordinate​(Coordinate coord)
        Creates a new coordinate from an existing coordinate
        Parameters:
        coord - the Coordinate you want to copy
    • Method Detail

      • getShared

        public static Coordinate getShared​()
      • getX

        public int getX​()
        Gets the X coordinate
        Returns:
      • getY

        public int getY​()
        Gets the Y coordinate
        Returns:
      • getZ

        public int getZ​()
        Returns:
      • 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:
      • set

        public Coordinate set​(int x,
                              int y,
                              int z)
        Parameters:
        x -
        y -
        z -
        Returns:
      • setFromPoint

        public Coordinate setFromPoint​(Point from)
        avoids a new instance.
        Parameters:
        from -
        Returns:
        See Also:
        toCoord()
      • getZClamp

        public int getZClamp​()
        Checks if the calculated value is inside the map dimensions and if not clamps it to the map dimensions.
        Returns:
        See Also:
        getZ()
      • setX

        public void setX​(int x)
        Set the coordiantes X component.
        Parameters:
        x -
      • setY

        public void setY​(int y)
        Set the coordiantes Y component.
        Parameters:
        y -
      • setZ

        public void setZ​(int z)
        Set the coordinates Z component.
        Parameters:
        z -
      • setBlock

        public void setBlock​(int block)
        Set a block in the map where the coordinate is pointing to.
        Parameters:
        block - the block you want to set.
      • setBlock

        public void setBlock​(byte id,
                             byte value)
        Set a block in the map where the coordinate is pointing to.
        Parameters:
        id -
        value -
      • add

        public Coordinate add​(int[] vector)
        Add a vector to the coordinates.
        Parameters:
        vector - integer coordinates stored as float
        Returns:
        the new coordinates which resulted of the addition
      • add

        public Coordinate add​(com.badlogic.gdx.math.Vector3 vector)
        Parameters:
        vector -
        Returns:
      • add

        public Coordinate add​(int x,
                              int y,
                              int z)
        Add a vector to the coordinates.
        Parameters:
        x -
        y -
        z -
        Returns:
        the new coordiantes which resulted of the addition
      • getBlock

        public int getBlock​()
        To optain value use (byte) (255&(block>>8)
        Returns:
        first byte id, second value, third is health.
      • 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.
      • getBlockValue

        public byte getBlockValue​()
        get the value of the block at this coordinate
        Returns:
      • getLogic

        public AbstractBlockLogicExtension getLogic​()
        get the logic to a block.
        Returns:
        can return null if the block has no logic
      • cpy

        public Coordinate cpy​()
        Specified by:
        cpy in interface Position
        Returns:
        a copy of this coordinate
      • 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.
      • isInCube

        public boolean isInCube​(Coordinate x1,
                                Coordinate x2)
        Checks wether the coordinate is in a cube spanning by both coordinates.
        Parameters:
        x1 - lower one
        x2 - bigger one.
        Returns:
      • getNeighbourSide

        public static int getNeighbourSide​(float x,
                                           float y)
        Returns the field-id where the coordiantes are inside in relation to the current field. Field id count clockwise, starting with the top with 0. If you want to get the neighbour you can use goToNeighbour(int) with the parameter found by this function. The numbering of the sides:
        7 \ 0 / 1
        -------
        6 | 8 | 2
        -------
        5 / 4 \ 3
        Run time: O(1)
        Parameters:
        x - game-space-coordinates, value in pixels
        y - game-space-coordinates, value in pixels
        Returns:
        Returns the fieldnumber of the coordinates. 8 is the field itself.
        See Also:
        goToNeighbour(int)
      • goToNeighbour

        public final Coordinate goToNeighbour​(int neighbourSide)
        Goes to the the neighbour with the specific side. Modifies the coordinate.
          \ 0/
        7  \/1
        \  /\  /
        6\/8 \/2
         /\  /\
        /  \/ 3\
          5/\
          / 4\

        Runtime: O(const)
        Parameters:
        neighbourSide - the side number of the given coordinates
        Returns:
        itself for chaining
      • toPoint

        public Point toPoint​()
        Copy safe. Creates new instance. O(const)
        Specified by:
        toPoint in interface Position
        Returns:
        the coordiante's origin is the center. You should avoid this method because it uses the heap.
      • toCoord

        public Coordinate toCoord​()
        Description copied from interface: Position
        Calculates it and creates new instance if not already in correct format then returns copy of itself.
        Specified by:
        toCoord in interface Position
        Returns:
        the coordinate representation. Copy safe
      • getEntitiesInside

        public java.util.LinkedList<AbstractEntity> getEntitiesInside​()
        Get every entity on a coord.
        Loads the chunk if not in memory. Should be used with care with generated content because new chunks can also trigger this recursively.
        Returns:
        a list with the entitys
      • getEntitiesInside

        public <T> java.util.LinkedList<T> getEntitiesInside​(java.lang.Class<T> type)
        Get every entity on this coord of the wanted type.
        Loads the chunk if not in memory. Should be used with care with generated content because new chunks can also trigger this recursively.
        Type Parameters:
        T - the class you want to filter.
        Parameters:
        type - the class you want to filter.
        Returns:
        a list with the entitys of the wanted type
      • 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:
      • distanceTo

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

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

        public float distanceToHorizontal​(Position point)
        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)
        Description copied from interface: Position
        checks only x and y.
        Specified by:
        distanceToHorizontalSquared in interface Position
        Returns:
        the distance from this point to the other point squared only regarding horizontal components.
      • distanceToHorizontalSquared

        public float distanceToHorizontalSquared​(Position point)
        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.
      • destroy

        public void destroy​()
        destroys the block at the current position, replacing by air.
      • damage

        public boolean damage​(byte amount)
        returns true if block got damaged
        Parameters:
        amount - value between 0 and 100
        Returns:
      • 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:
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode​()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString​()
        Overrides:
        toString in class java.lang.Object
      • setValue

        public void setValue​(byte value)
        A change in the value overwrites the spritevalue.
        Parameters:
        value -
      • 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
      • getEntitiesNearbyHorizontal

        public java.util.LinkedList<AbstractEntity> getEntitiesNearbyHorizontal​(float radius)
        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
      • getRenderChunk

        public RenderChunk getRenderChunk​(GameView gameView)
        Parameters:
        gameView -
        Returns:
      • addLight

        public void addLight​(GameView view,
                             Side side,
                             byte vertex,
                             com.badlogic.gdx.graphics.Color color)
        Add light to the RenderStorage at this coordiante
        Parameters:
        view -
        side -
        color - only read from
        vertex -
      • addLightToBackEdge

        public void addLightToBackEdge​(GameView view,
                                       Side side,
                                       com.badlogic.gdx.graphics.Color color)
        Add light to the back edge of a coordinate and it's neighbors-
        Parameters:
        view -
        color - only read from
        side -
      • isObstacle

        public boolean isObstacle​()
        Returns:
      • 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