Class CollisionDetection

java.lang.Object
games.stendhal.common.CollisionDetection

public class CollisionDetection extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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
    Check if a rectangle overlaps colliding areas.
    int
    Get the height of the collision map.
    int
    Get the width of the collision map.
    void
    init​(int width, int height)
    Initialize the collision map to desired size.
    boolean
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 map
      height - 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 coordinate
      y - y coordinate
    • setCollisionData

      public void setCollisionData(LayerDefinition collisionLayer)
      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-coordinate
      y - y-coordinate
      size - size of surroundings
    • leavesZone

      public boolean leavesZone(Rectangle2D shape)
      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

      public boolean collides(Rectangle2D shape)
      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-position
      y - y-position
      w - width
      h - 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 coordinate
      y - y coordinate
      Returns:
      true if the map position is a collision tile, otherwise false
    • 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