[ebd3538] | 1 | package collision;
|
---|
| 2 |
|
---|
| 3 | import java.awt.Graphics2D;
|
---|
| 4 | import java.awt.Graphics;
|
---|
| 5 | import java.awt.geom.Point2D;
|
---|
| 6 | import java.awt.Point;
|
---|
| 7 | import java.awt.geom.Rectangle2D;
|
---|
| 8 | import java.awt.geom.AffineTransform;
|
---|
| 9 | import main.MapObject;
|
---|
| 10 | import java.awt.Rectangle;
|
---|
| 11 | import java.awt.Shape;
|
---|
| 12 | import java.awt.geom.Area;
|
---|
| 13 |
|
---|
| 14 | public class Bound extends Area
|
---|
| 15 | {
|
---|
| 16 | public Bound(final Shape s) {
|
---|
| 17 | super(s);
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | public boolean intersects(final Rectangle o, final MapObject parent) {
|
---|
| 21 | if (o == null) {
|
---|
| 22 | return false;
|
---|
| 23 | }
|
---|
| 24 | Area a;
|
---|
| 25 | if (parent == null) {
|
---|
| 26 | a = this;
|
---|
| 27 | }
|
---|
| 28 | else {
|
---|
| 29 | a = this.createTransformedArea(new AffineTransform(1.0f, 0.0f, 0.0f, 1.0f, parent.getBoundX(), parent.getBoundY()));
|
---|
| 30 | }
|
---|
| 31 | return a.intersects(o);
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | public boolean contains(final Rectangle o, final MapObject parent) {
|
---|
| 35 | if (o == null) {
|
---|
| 36 | return false;
|
---|
| 37 | }
|
---|
| 38 | Area a;
|
---|
| 39 | if (parent == null) {
|
---|
| 40 | a = this;
|
---|
| 41 | }
|
---|
| 42 | else {
|
---|
| 43 | a = this.createTransformedArea(new AffineTransform(1.0f, 0.0f, 0.0f, 1.0f, parent.getBoundX(), parent.getBoundY()));
|
---|
| 44 | }
|
---|
| 45 | return a.contains(o);
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | public boolean intersects(final Bound o, final MapObject parent, final MapObject oParent) {
|
---|
| 49 | if (o == null) {
|
---|
| 50 | return false;
|
---|
| 51 | }
|
---|
| 52 | Area a1;
|
---|
| 53 | if (parent == null) {
|
---|
| 54 | a1 = this;
|
---|
| 55 | }
|
---|
| 56 | else {
|
---|
| 57 | a1 = this.createTransformedArea(new AffineTransform(1.0f, 0.0f, 0.0f, 1.0f, parent.getBoundX(), parent.getBoundY()));
|
---|
| 58 | }
|
---|
| 59 | Area a2;
|
---|
| 60 | if (oParent == null) {
|
---|
| 61 | a2 = o;
|
---|
| 62 | }
|
---|
| 63 | else {
|
---|
| 64 | a2 = o.createTransformedArea(new AffineTransform(1.0f, 0.0f, 0.0f, 1.0f, oParent.getBoundX(), oParent.getBoundY()));
|
---|
| 65 | }
|
---|
| 66 | final Area intersection = new Area(a1);
|
---|
| 67 | intersection.intersect(a2);
|
---|
| 68 | return !intersection.isEmpty();
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | public boolean contains(final Bound o, final MapObject parent, final MapObject oParent) {
|
---|
| 72 | if (o == null) {
|
---|
| 73 | return false;
|
---|
| 74 | }
|
---|
| 75 | Area a1;
|
---|
| 76 | if (parent == null) {
|
---|
| 77 | a1 = this;
|
---|
| 78 | }
|
---|
| 79 | else {
|
---|
| 80 | a1 = this.createTransformedArea(new AffineTransform(1.0f, 0.0f, 0.0f, 1.0f, parent.getBoundX(), parent.getBoundY()));
|
---|
| 81 | }
|
---|
| 82 | Area a2;
|
---|
| 83 | if (oParent == null) {
|
---|
| 84 | a2 = o;
|
---|
| 85 | }
|
---|
| 86 | else {
|
---|
| 87 | a2 = o.createTransformedArea(new AffineTransform(1.0f, 0.0f, 0.0f, 1.0f, oParent.getBoundX(), oParent.getBoundY()));
|
---|
| 88 | }
|
---|
| 89 | final Area combined = new Area(a1);
|
---|
| 90 | combined.add(a2);
|
---|
| 91 | return combined.equals(a1);
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | public boolean contains(final Point p, final MapObject parent) {
|
---|
| 95 | Area a;
|
---|
| 96 | if (parent == null) {
|
---|
| 97 | a = this;
|
---|
| 98 | }
|
---|
| 99 | else {
|
---|
| 100 | a = this.createTransformedArea(new AffineTransform(1.0f, 0.0f, 0.0f, 1.0f, parent.getBoundX(), parent.getBoundY()));
|
---|
| 101 | }
|
---|
| 102 | return a.contains(p);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | public void draw(final Graphics g, final int x, final int y, final MapObject parent) {
|
---|
| 106 | final Area a1 = this.createTransformedArea(new AffineTransform(1.0f, 0.0f, 0.0f, 1.0f, x + parent.getBoundX(), y + parent.getBoundY()));
|
---|
| 107 | ((Graphics2D)g).draw(a1);
|
---|
| 108 | }
|
---|
| 109 | }
|
---|