123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package me.hammerle.supersnuvi.util;
- import static me.hammerle.supersnuvi.util.CollisionBox.createScaledTileBox;
- public abstract class CollisionObject
- {
- public final static CollisionObject NULL_BOX = new CollisionBox(0.0f, 0.0f, 0.0f, 0.0f);
- public final static CollisionObject DEFAULT_TILE_BOX = createScaledTileBox(0.0f, 0.0f, 1.0f, 1.0f);
-
- public enum Type
- {
- LINE, BOX
- }
-
- public abstract Type getType();
- public abstract CollisionObject copy();
- public abstract void save();
- public abstract CollisionObject reset();
-
- public abstract float getWidth();
- public abstract float getHeight();
-
- public abstract float getMinX();
- public abstract float getMaxX();
- public abstract float getMinY();
- public abstract float getMaxY();
-
- public abstract CollisionObject expand(float x, float y);
-
- public final CollisionObject offset(float x, float y)
- {
- offsetX(x);
- offsetY(y);
- return this;
- }
-
- public abstract CollisionObject offsetX(float x);
- public abstract CollisionObject offsetY(float y);
-
- public abstract boolean isColliding(CollisionObject cb);
-
- public final boolean mayCollide(CollisionObject cb)
- {
- // box intersect test, even for lines, prevents failures
- float minX1 = Math.min(cb.getMinX(), cb.getMaxX());
- float minY1 = Math.min(cb.getMinY(), cb.getMaxY());
- float maxX1 = Math.max(cb.getMinX(), cb.getMaxX());
- float maxY1 = Math.max(cb.getMinY(), cb.getMaxY());
-
- float minX2 = Math.min(getMinX(), getMaxX());
- float minY2 = Math.min(getMinY(), getMaxY());
- float maxX2 = Math.max(getMinX(), getMaxX());
- float maxY2 = Math.max(getMinY(), getMaxY());
-
- return maxX1 > minX2 && maxX2 > minX1 && maxY1 > minY2 && maxY2 > minY1;
- }
- }
|