source: lost-perception/collision/Bound.java

Last change on this file was ebd3538, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 6 years ago

Initial commit. This codebase for the Lost Perception game was created by decompiling code from a jar file.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1package collision;
2
3import java.awt.Graphics2D;
4import java.awt.Graphics;
5import java.awt.geom.Point2D;
6import java.awt.Point;
7import java.awt.geom.Rectangle2D;
8import java.awt.geom.AffineTransform;
9import main.MapObject;
10import java.awt.Rectangle;
11import java.awt.Shape;
12import java.awt.geom.Area;
13
14public 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}
Note: See TracBrowser for help on using the repository browser.