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 Coordinate
add(int[] vector)
Add a vector to the coordinates.Coordinate
add(int x, int y, int z)
Add a vector to the coordinates.Coordinate
add(com.badlogic.gdx.math.Vector3 vector)
void
addLight(GameView view, Side side, byte vertex, com.badlogic.gdx.graphics.Color color)
Add light to the RenderStorage at this coordiantevoid
addLightToBackEdge(GameView view, Side side, com.badlogic.gdx.graphics.Color color)
Add light to the back edge of a coordinate and it's neighbors-Coordinate
cpy()
boolean
damage(byte amount)
returns true if block got damagedvoid
destroy()
destroys the block at the current position, replacing by air.float
distanceTo(AbstractGameObject object)
float
distanceTo(Position point)
float
distanceToHorizontal(AbstractGameObject object)
checks only x and y.float
distanceToHorizontal(Position point)
checks only x and y.float
distanceToHorizontalSquared(AbstractGameObject object)
checks only x and y.float
distanceToHorizontalSquared(Position point)
checks only x and y.float
distanceToSquared(AbstractGameObject object)
The result is squared for fast comparison.float
distanceToSquared(Position pos)
The result is squared for fast comparison.boolean
equals(java.lang.Object obj)
int
getBlock()
To optain value use (byte) (255&(block>>8)byte
getBlockId()
Get the block at the position.byte
getBlockValue()
get the value of the block at this coordinateChunk
getChunk()
int
getChunkX()
The chunk coordinate.int
getChunkY()
The chunk coordinate.Coordinate
getCoord()
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)AbstractBlockLogicExtension
getLogic()
get the logic to a block.static int
getNeighbourSide(float x, float y)
Returns the field-id where the coordiantes are inside in relation to the current field.Point
getPoint()
May not be copy safe.int
getProjectionSpaceX(GameView view, Camera camera)
equals screen space when zoom=1 with a single, fullscreen camera.int
getProjectionSpaceY(GameView view, Camera camera)
equals screen space when zoom=1 with a single camera.RenderCell
getRenderCell(RenderStorage rs)
RenderChunk
getRenderChunk(GameView gameView)
static Coordinate
getShared()
int
getViewSpcX()
Calculate position in view space.int
getViewSpcY()
Calculate position in view space.int
getX()
Gets the X coordinateint
getY()
Gets the Y coordinateint
getZ()
int
getZClamp()
Checks if the calculated value is inside the map dimensions and if not clamps it to the map dimensions.int
getZGrid()
Get the z in block grid coordinates of the coordinate.float
getZPoint()
Get the z in game world coordinates.Coordinate
goToNeighbour(int neighbourSide)
Goes to the the neighbour with the specific side.int
hashCode()
boolean
isInCube(Coordinate x1, Coordinate x2)
Checks wether the coordinate is in a cube spanning by both coordinates.boolean
isInMemoryAreaXY()
Checks if the coordiantes are accessable with the currently loaded chunks.boolean
isInMemoryAreaXYZ()
Checks if the position is on the chunks currently in memory.boolean
isObstacle()
Coordinate
set(int x, int y, int z)
Coordinate
set(Coordinate coord)
void
setBlock(byte id, byte value)
Set a block in the map where the coordinate is pointing to.void
setBlock(int block)
Set a block in the map where the coordinate is pointing to.Coordinate
setFromPoint(Point from)
avoids a new instance.void
setValue(byte value)
A change in the value overwrites the spritevalue.void
setX(int x)
Set the coordiantes X component.void
setY(int y)
Set the coordiantes Y component.void
setZ(int z)
Set the coordinates Z component.Coordinate
toCoord()
Calculates it and creates new instance if not already in correct format then returns copy of itself.Point
toPoint()
Copy safe.java.lang.String
toString()
-
-
-
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.
-
getZPoint
public float getZPoint()
Description copied from interface:Position
Get 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:Position
Get the block at the position. Clamps positions over the map at topmost layer.- Specified by:
getBlockId
in 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: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 interfacePosition
- 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 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:Position
Calculates 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:Position
Calculate position in view space.- Specified by:
getViewSpcX
in 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:Position
Calculate position in view space.- Specified by:
getViewSpcY
in 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:Position
equals screen space when zoom=1 with a single, fullscreen camera.- Specified by:
getProjectionSpaceX
in interfacePosition
- 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 interfacePosition
- Returns:
-
distanceTo
public float distanceTo(AbstractGameObject object)
- Specified by:
distanceTo
in interfacePosition
- Returns:
- the distance from this point to the other object
-
distanceTo
public float distanceTo(Position point)
- Specified by:
distanceTo
in interfacePosition
- Returns:
- the distance from this pos to the other pos in game coordinates
-
distanceToSquared
public float distanceToSquared(AbstractGameObject object)
Description copied from interface:Position
The result is squared for fast comparison.- Specified by:
distanceToSquared
in 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:Position
The result is squared for fast comparison.- Specified by:
distanceToSquared
in 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:Position
checks only x and y.- Specified by:
distanceToHorizontal
in 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:Position
checks only x and y.- Specified by:
distanceToHorizontal
in 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:Position
checks only x and y.- Specified by:
distanceToHorizontalSquared
in 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:Position
checks only x and y.- Specified by:
distanceToHorizontalSquared
in 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:Position
The chunk coordinate.
-
getChunkY
public int getChunkY()
Description copied from interface:Position
The chunk coordinate.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in 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:Position
Get entities in radius.- Specified by:
getEntitiesNearby
in 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:
getEntitiesNearbyHorizontal
in 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:Position
get entities in horizontal radius (like a pipe)- Specified by:
getEntitiesNearbyHorizontal
in 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:Position
May not be copy safe.
-
-