Package games.stendhal.common
Class CollisionDetection
java.lang.Object
games.stendhal.common.CollisionDetection
This class loads the map and allow you to determine if a player collides or
not with any of the non trespasable areas of the world.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear the collision map.booleancollides(double x, double y, double w, double h) Check if a rectangle overlaps colliding areas.booleancollides(int x, int y) Check if a location is marked with collision.booleancollides(Rectangle2D shape) Check if a rectangle overlaps colliding areas.intGet the height of the collision map.intgetWidth()Get the width of the collision map.voidinit(int width, int height) Initialize the collision map to desired size.booleanleavesZone(Rectangle2D shape) Check if a rectangle is at least partially outside the map.voidprintaround(int x, int y, int size) Print the area around the (x,y) useful for debugging.voidsetCollide(int x, int y) Set a position in the collision map to static collision.voidsetCollisionData(LayerDefinition collisionLayer) Fill the collision map from layer data.
-
Constructor Details
-
CollisionDetection
public CollisionDetection()
-
-
Method Details
-
clear
public void clear()Clear the collision map. -
init
public void init(int width, int height) Initialize the collision map to desired size.- Parameters:
width- width of the mapheight- height of the map
-
setCollide
public void setCollide(int x, int y) Set a position in the collision map to static collision.- Parameters:
x- x coordinatey- y coordinate
-
setCollisionData
Fill the collision map from layer data.- Parameters:
collisionLayer- static collision information
-
printaround
public void printaround(int x, int y, int size) Print the area around the (x,y) useful for debugging.- Parameters:
x- x-coordinatey- y-coordinatesize- size of surroundings
-
leavesZone
Check if a rectangle is at least partially outside the map.- Parameters:
shape- area to be checked- Returns:
trueif shape is at least partially outside the map,falseotherwise
-
collides
Check if a rectangle overlaps colliding areas.- Parameters:
shape- checked area- Returns:
trueif the shape enters in any of the non trespassable areas of the map,falseotherwise
-
collides
public boolean collides(double x, double y, double w, double h) Check if a rectangle overlaps colliding areas.- Parameters:
x- x-positiony- y-positionw- widthh- height- Returns:
trueif the shape enters in any of the non trespassable areas of the map,falseotherwise
-
collides
public boolean collides(int x, int y) Check if a location is marked with collision.- Parameters:
x- x coordinatey- y coordinate- Returns:
trueif the map position is a collision tile, otherwisefalse
-
getWidth
public int getWidth()Get the width of the collision map.- Returns:
- width
-
getHeight
public int getHeight()Get the height of the collision map.- Returns:
- height
-