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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear the collision map.boolean
collides(double x, double y, double w, double h)
Check if a rectangle overlaps colliding areas.boolean
collides(int x, int y)
Check if a location is marked with collision.boolean
collides(Rectangle2D shape)
Check if a rectangle overlaps colliding areas.int
Get the height of the collision map.int
getWidth()
Get the width of the collision map.void
init(int width, int height)
Initialize the collision map to desired size.boolean
leavesZone(Rectangle2D shape)
Check if a rectangle is at least partially outside the map.void
printaround(int x, int y, int size)
Print the area around the (x,y) useful for debugging.void
setCollide(int x, int y)
Set a position in the collision map to static collision.void
setCollisionData(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:
true
if shape is at least partially outside the map,false
otherwise
-
collides
Check if a rectangle overlaps colliding areas.- Parameters:
shape
- checked area- Returns:
true
if the shape enters in any of the non trespassable areas of the map,false
otherwise
-
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:
true
if the shape enters in any of the non trespassable areas of the map,false
otherwise
-
collides
public boolean collides(int x, int y)Check if a location is marked with collision.- Parameters:
x
- x coordinatey
- y coordinate- Returns:
true
if 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
-