Class Coordinate
- java.lang.Object
-
- com.bombinggames.wurfelengine.core.map.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 Summary
Constructors Constructor Description Coordinate()0,0,0,Coordinate(int x, int y, int z)Creates a coordiante refering to the given position on the map.Coordinate(Coordinate coord)Creates a new coordinate from an existing coordinate
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Coordinateadd(int[] vector)Add a vector to the coordinates.Coordinateadd(int x, int y, int z)Add a vector to the coordinates.Coordinateadd(com.badlogic.gdx.math.Vector3 vector)voidaddLight(GameView view, Side side, byte vertex, com.badlogic.gdx.graphics.Color color)Add light to the RenderStorage at this coordiantevoidaddLightToBackEdge(GameView view, Side side, com.badlogic.gdx.graphics.Color color)Add light to the back edge of a coordinate and it's neighbors-Coordinatecpy()booleandamage(byte amount)returns true if block got damagedvoiddestroy()destroys the block at the current position, replacing by air.floatdistanceTo(AbstractGameObject object)floatdistanceTo(Position point)floatdistanceToHorizontal(AbstractGameObject object)checks only x and y.floatdistanceToHorizontal(Position point)checks only x and y.floatdistanceToHorizontalSquared(AbstractGameObject object)checks only x and y.floatdistanceToHorizontalSquared(Position point)checks only x and y.floatdistanceToSquared(AbstractGameObject object)The result is squared for fast comparison.floatdistanceToSquared(Position pos)The result is squared for fast comparison.booleanequals(java.lang.Object obj)intgetBlock()To optain value use (byte) (255&(block>>8)bytegetBlockId()Get the block at the position.bytegetBlockValue()get the value of the block at this coordinateChunkgetChunk()intgetChunkX()The chunk coordinate.intgetChunkY()The chunk coordinate.CoordinategetCoord()May not be copy safe.java.util.LinkedList<AbstractEntity>getEntitiesInside()Get every entity on a coord.
Loads the chunk if not in memory.<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.<T> java.util.LinkedList<T>getEntitiesNearby(float radius, java.lang.Class<T> type)Get entities in radius.java.util.LinkedList<AbstractEntity>getEntitiesNearbyHorizontal(float radius)get entities in radius (horizontal only)<T> java.util.LinkedList<T>getEntitiesNearbyHorizontal(float radius, java.lang.Class<T> type)get entities in horizontal radius (like a pipe)AbstractBlockLogicExtensiongetLogic()get the logic to a block.static intgetNeighbourSide(float x, float y)Returns the field-id where the coordiantes are inside in relation to the current field.PointgetPoint()May not be copy safe.intgetProjectionSpaceX(GameView view, Camera camera)equals screen space when zoom=1 with a single, fullscreen camera.intgetProjectionSpaceY(GameView view, Camera camera)equals screen space when zoom=1 with a single camera.RenderCellgetRenderCell(RenderStorage rs)RenderChunkgetRenderChunk(GameView gameView)static CoordinategetShared()intgetViewSpcX()Calculate position in view space.intgetViewSpcY()Calculate position in view space.intgetX()Gets the X coordinateintgetY()Gets the Y coordinateintgetZ()intgetZClamp()Checks if the calculated value is inside the map dimensions and if not clamps it to the map dimensions.intgetZGrid()Get the z in block grid coordinates of the coordinate.floatgetZPoint()Get the z in game world coordinates.CoordinategoToNeighbour(int neighbourSide)Goes to the the neighbour with the specific side.inthashCode()booleanisInCube(Coordinate x1, Coordinate x2)Checks wether the coordinate is in a cube spanning by both coordinates.booleanisInMemoryAreaXY()Checks if the coordiantes are accessable with the currently loaded chunks.booleanisInMemoryAreaXYZ()Checks if the position is on the chunks currently in memory.booleanisObstacle()Coordinateset(int x, int y, int z)Coordinateset(Coordinate coord)voidsetBlock(byte id, byte value)Set a block in the map where the coordinate is pointing to.voidsetBlock(int block)Set a block in the map where the coordinate is pointing to.CoordinatesetFromPoint(Point from)avoids a new instance.voidsetValue(byte value)A change in the value overwrites the spritevalue.voidsetX(int x)Set the coordiantes X component.voidsetY(int y)Set the coordiantes Y component.voidsetZ(int z)Set the coordinates Z component.CoordinatetoCoord()Calculates it and creates new instance if not already in correct format then returns copy of itself.PointtoPoint()Copy safe.java.lang.StringtoString()
-
-
-
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:PositionGet the z in block grid coordinates of the coordinate. Faster than transforming to coordinate first.
-
getZPoint
public float getZPoint()
Description copied from interface:PositionGet the z in game world coordinates.
-
set
public Coordinate set(int x, int y, int z)
- Parameters:
x-y-z-- Returns:
-
set
public Coordinate set(Coordinate coord)
- Parameters:
coord-- 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:PositionGet the block at the position. Clamps positions over the map at topmost layer.- Specified by:
getBlockIdin interfacePosition- 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()
-
isInMemoryAreaXY
public boolean isInMemoryAreaXY()
Description copied from interface:PositionChecks 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:
isInMemoryAreaXYin interfacePosition- Returns:
-
isInMemoryAreaXYZ
public boolean isInMemoryAreaXYZ()
Description copied from interface:PositionChecks if the position is on the chunks currently in memory. Checks all axis'.- Specified by:
isInMemoryAreaXYZin interfacePosition- 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 onex2- 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 usegoToNeighbour(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 pixelsy- 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)
-
toCoord
public Coordinate toCoord()
Description copied from interface:PositionCalculates it and creates new instance if not already in correct format then returns copy of itself.
-
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:PositionCalculate position in view space.- Specified by:
getViewSpcXin interfacePosition- 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:PositionCalculate position in view space.- Specified by:
getViewSpcYin interfacePosition- 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:Positionequals screen space when zoom=1 with a single, fullscreen camera.- Specified by:
getProjectionSpaceXin interfacePosition- Returns:
-
getProjectionSpaceY
public int getProjectionSpaceY(GameView view, Camera camera)
Description copied from interface:Positionequals screen space when zoom=1 with a single camera.- Specified by:
getProjectionSpaceYin interfacePosition- Returns:
-
distanceTo
public float distanceTo(AbstractGameObject object)
- Specified by:
distanceToin interfacePosition- Returns:
- the distance from this point to the other object
-
distanceTo
public float distanceTo(Position point)
- Specified by:
distanceToin interfacePosition- Returns:
- the distance from this pos to the other pos in game coordinates
-
distanceToSquared
public float distanceToSquared(AbstractGameObject object)
Description copied from interface:PositionThe result is squared for fast comparison.- Specified by:
distanceToSquaredin interfacePosition- Returns:
- the distance from this point to the other object squared
- See Also:
Position.distanceTo(AbstractGameObject)
-
distanceToSquared
public float distanceToSquared(Position pos)
Description copied from interface:PositionThe result is squared for fast comparison.- Specified by:
distanceToSquaredin interfacePosition- Returns:
- the distance from this point to the other object squared
- See Also:
Position.distanceTo(Position)
-
distanceToHorizontal
public float distanceToHorizontal(AbstractGameObject object)
Description copied from interface:Positionchecks only x and y.- Specified by:
distanceToHorizontalin interfacePosition- Returns:
- the distance from this point to the other point only regarding horizontal components.
-
distanceToHorizontal
public float distanceToHorizontal(Position point)
Description copied from interface:Positionchecks only x and y.- Specified by:
distanceToHorizontalin interfacePosition- Returns:
- the distance from this pos to the other pos only regarding horizontal components.
-
distanceToHorizontalSquared
public float distanceToHorizontalSquared(AbstractGameObject object)
Description copied from interface:Positionchecks only x and y.- Specified by:
distanceToHorizontalSquaredin interfacePosition- 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:Positionchecks only x and y.- Specified by:
distanceToHorizontalSquaredin interfacePosition- 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:PositionThe chunk coordinate.
-
getChunkY
public int getChunkY()
Description copied from interface:PositionThe chunk coordinate.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.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:PositionGet entities in radius.- Specified by:
getEntitiesNearbyin interfacePosition- Type Parameters:
T- returns only object if type which is the filter- Parameters:
radius- in game dimension pixelstype- 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:
getEntitiesNearbyHorizontalin interfacePosition- 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:Positionget entities in horizontal radius (like a pipe)- Specified by:
getEntitiesNearbyHorizontalin interfacePosition- Parameters:
radius- in game dimension pixelstype- whitelist- Returns:
- every entitie in radius
-
getRenderChunk
public RenderChunk getRenderChunk(GameView gameView)
- Parameters:
gameView-- Returns:
-
getRenderCell
public RenderCell getRenderCell(RenderStorage rs)
- Parameters:
rs-- Returns:
- can return null
-
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 fromvertex-
-
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 fromside-
-
isObstacle
public boolean isObstacle()
- Returns:
-
getCoord
public Coordinate getCoord()
Description copied from interface:PositionMay not be copy safe.
-
-