Search in sources :

Example 6 with Point

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

the class ComponentCollision method checkPoint.

/**
 * Check others element at specified point.
 *
 * @param objectA The collidable reference.
 * @param acceptedElements The current elements to check.
 * @param point The point to check.
 */
private void checkPoint(Collidable objectA, Map<Point, List<Collidable>> acceptedElements, Point point) {
    final List<Collidable> others = acceptedElements.get(point);
    for (int o = 0; o < others.size(); o++) {
        final Collidable objectB = others.get(o);
        // Ensures not already collided with object with other point (because of subdivision mapping)
        if (objectB.isEnabled() && objectA != objectB && done.get(objectA) != objectB) {
            final List<CollisionCouple> collisions = objectA.collide(objectB);
            final int count = collisions.size();
            for (int i = 0; i < count; i++) {
                toNotify.add(new Collided(objectA, objectB, collisions.get(i)));
                done.put(objectA, objectB);
            }
        }
    }
}
Also used : Point(com.b3dgs.lionengine.geom.Point)

Example 7 with Point

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

the class ComponentCollision method checkOthers.

/**
 * Check others element.
 *
 * @param objectA The collidable reference.
 * @param current The current group to check.
 */
private void checkOthers(Collidable objectA, Entry<Point, List<Collidable>> current) {
    final List<Integer> accepted = objectA.getAccepted();
    final int count = accepted.size();
    for (int i = 0; i < count; i++) {
        final Integer acceptedGroup = accepted.get(i);
        // Others to compare only in accepted group
        if (collidables.containsKey(acceptedGroup)) {
            checkOthers(objectA, current, acceptedGroup);
        }
    }
}
Also used : Point(com.b3dgs.lionengine.geom.Point)

Example 8 with Point

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

the class ComponentCollision method checkGroup.

/**
 * Check elements in group.
 *
 * @param current The elements in group.
 */
private void checkGroup(Entry<Point, List<Collidable>> current) {
    final List<Collidable> elements = current.getValue();
    final int count = elements.size();
    for (int i = 0; i < count; i++) {
        final Collidable collidable = elements.get(i);
        if (collidable.isEnabled()) {
            checkOthers(elements.get(i), current);
        }
    }
}
Also used : Point(com.b3dgs.lionengine.geom.Point)

Example 9 with Point

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

the class ComponentCollision method checkOthers.

/**
 * Check others element.
 *
 * @param objectA The collidable reference.
 * @param current The current group to check.
 * @param acceptedGroup The accepted group.
 */
private void checkOthers(Collidable objectA, Entry<Point, List<Collidable>> current, Integer acceptedGroup) {
    final Map<Point, List<Collidable>> acceptedElements = collidables.get(acceptedGroup);
    final Point point = current.getKey();
    if (acceptedElements.containsKey(point)) {
        checkPoint(objectA, acceptedElements, point);
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Point(com.b3dgs.lionengine.geom.Point)

Example 10 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 x The horizontal location.
 * @param y The vertical location.
 * @param collidable The collidable reference.
 */
private void addPoints(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);
    addPoint(new Point(minX, minY), collidable);
    if (minX != maxX && minY == maxY) {
        addPoint(new Point(maxX, minY), collidable);
    } else if (minX == maxX && minY != maxY) {
        addPoint(new Point(minX, maxY), collidable);
    } else if (minX != maxX) {
        addPoint(new Point(minX, maxY), collidable);
        addPoint(new Point(maxX, minY), collidable);
        addPoint(new Point(maxX, maxY), collidable);
    }
}
Also used : Point(com.b3dgs.lionengine.geom.Point) 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