Search in sources :

Example 1 with Point

use of com.b3dgs.lionengine.geom.Point in project lionengine by b3dgs.

the class ComponentCollision method removePoints.

/**
 * Remove point and adjacent points depending of the collidable max collision size.
 *
 * @param x The horizontal location.
 * @param y The vertical location.
 * @param collidable The collidable reference.
 */
private void removePoints(double x, double y, Collidable collidable) {
    final int minX = (int) Math.floor(x / REDUCE_FACTOR);
    final int minY = (int) Math.floor(y / REDUCE_FACTOR);
    final int maxX = (int) Math.floor((x + collidable.getMaxWidth()) / REDUCE_FACTOR);
    final int maxY = (int) Math.floor((y + collidable.getMaxHeight()) / REDUCE_FACTOR);
    removePoint(new Point(minX, minY), collidable);
    if (minX != maxX && minY == maxY) {
        removePoint(new Point(maxX, minY), collidable);
    } else if (minX == maxX && minY != maxY) {
        removePoint(new Point(minX, maxY), collidable);
    } else if (minX != maxX) {
        removePoint(new Point(minX, maxY), collidable);
        removePoint(new Point(maxX, minY), collidable);
        removePoint(new Point(maxX, maxY), collidable);
    }
}
Also used : Point(com.b3dgs.lionengine.geom.Point) Point(com.b3dgs.lionengine.geom.Point)

Example 2 with Point

use of com.b3dgs.lionengine.geom.Point in project lionengine by b3dgs.

the class MouseMoveAwt method getCursorLocation.

/**
 * Get the buttons number.
 *
 * @return The buttons number.
 */
private static Point getCursorLocation() {
    try {
        final PointerInfo a = MouseInfo.getPointerInfo();
        final java.awt.Point b = a.getLocation();
        return new Point((int) b.getX(), (int) b.getY());
    } catch (final HeadlessException exception) {
        Verbose.exception(exception);
        return new Point();
    }
}
Also used : PointerInfo(java.awt.PointerInfo) HeadlessException(java.awt.HeadlessException) Point(com.b3dgs.lionengine.geom.Point)

Example 3 with Point

use of com.b3dgs.lionengine.geom.Point in project lionengine by b3dgs.

the class MouseMoveAwt method getCursorLocation.

/**
 * Get the buttons number.
 *
 * @return The buttons number.
 */
private static Point getCursorLocation() {
    try {
        final PointerInfo a = MouseInfo.getPointerInfo();
        final java.awt.Point b = a.getLocation();
        return new Point((int) b.getX(), (int) b.getY());
    } catch (final HeadlessException exception) {
        Verbose.exception(exception);
        return new Point();
    }
}
Also used : PointerInfo(java.awt.PointerInfo) HeadlessException(java.awt.HeadlessException) Point(com.b3dgs.lionengine.geom.Point)

Example 4 with Point

use of com.b3dgs.lionengine.geom.Point in project lionengine by b3dgs.

the class ComponentCollision method getInside.

/**
 * Get elements inside area.
 *
 * @param area The area used.
 * @return The elements inside area.
 */
public Collection<Collidable> getInside(Area area) {
    final Collection<Collidable> inside = new HashSet<>();
    final Collection<Point> points = getPoints(area);
    for (final Map<Point, List<Collidable>> groups : collidables.values()) {
        for (final Point point : points) {
            final List<Collidable> elements = groups.get(point);
            if (elements != null) {
                checkInside(elements, area, inside);
            }
        }
    }
    return inside;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Point(com.b3dgs.lionengine.geom.Point) HashSet(java.util.HashSet)

Example 5 with Point

use of com.b3dgs.lionengine.geom.Point in project lionengine by b3dgs.

the class ComponentCollision method addPoints.

/**
 * Add point and adjacent points depending of the collidable max collision size.
 *
 * @param transformable The transformable reference.
 * @param collidable The collidable reference.
 */
private void addPoints(Transformable transformable, Collidable collidable) {
    final int minX = getIndex(transformable.getX() - collidable.getMaxWidth());
    final int minY = getIndex(transformable.getY() - collidable.getMaxHeight());
    final int maxX = getIndex(transformable.getX() + collidable.getMaxWidth());
    final int maxY = getIndex(transformable.getY() + collidable.getMaxHeight());
    for (int x = minX; x <= maxX; x++) {
        for (int y = minY; y <= maxY; y++) {
            addPoint(cache(x, y), collidable);
        }
    }
}
Also used : Point(com.b3dgs.lionengine.geom.Point)

Aggregations

Point (com.b3dgs.lionengine.geom.Point)12 HeadlessException (java.awt.HeadlessException)2 PointerInfo (java.awt.PointerInfo)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2