[ebd3538] | 1 | package main;
|
---|
| 2 |
|
---|
| 3 | import java.awt.Graphics;
|
---|
| 4 | import collision.Bound;
|
---|
| 5 | import java.awt.Point;
|
---|
| 6 |
|
---|
| 7 | public class MapObject implements Comparable<MapObject>
|
---|
| 8 | {
|
---|
| 9 | public Point loc;
|
---|
| 10 | public int z;
|
---|
| 11 | private Bound bound;
|
---|
| 12 | private Bound selectionBound;
|
---|
| 13 |
|
---|
| 14 | public MapObject(final int x, final int y, final int z) {
|
---|
| 15 | this.loc = new Point(x, y);
|
---|
| 16 | this.z = z;
|
---|
| 17 | final Bound bound = null;
|
---|
| 18 | this.selectionBound = bound;
|
---|
| 19 | this.bound = bound;
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | public MapObject(final MapObject obj, final int x, final int y, final int z) {
|
---|
| 23 | this.loc = new Point(x, y);
|
---|
| 24 | this.z = z;
|
---|
| 25 | this.bound = obj.bound;
|
---|
| 26 | this.selectionBound = obj.selectionBound;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | public int getBoundX() {
|
---|
| 30 | return this.loc.x;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | public int getBoundY() {
|
---|
| 34 | return this.loc.y + this.z * 40;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | public int getMapX() {
|
---|
| 38 | return this.loc.x / 40;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | public int getMapY() {
|
---|
| 42 | return this.loc.y / 40;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | public int getSortX() {
|
---|
| 46 | return this.loc.x;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | public int getSortY() {
|
---|
| 50 | return this.loc.y;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | public double getSortZ() {
|
---|
| 54 | return this.z;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | public void draw(final Graphics g, final int x, final int y) {
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | @Override
|
---|
| 61 | public int compareTo(final MapObject obj) {
|
---|
| 62 | final double z = this.getSortZ();
|
---|
| 63 | final double objZ = obj.getSortZ();
|
---|
| 64 | if (z != objZ) {
|
---|
| 65 | return (int)(2.0 * (z - objZ));
|
---|
| 66 | }
|
---|
| 67 | final int yDif = this.getSortY() - obj.getSortY();
|
---|
| 68 | if (yDif != 0) {
|
---|
| 69 | return yDif;
|
---|
| 70 | }
|
---|
| 71 | if (this.getSortX() - obj.getSortX() != 0) {
|
---|
| 72 | return this.getSortX() - obj.getSortX();
|
---|
| 73 | }
|
---|
| 74 | if (this == obj) {
|
---|
| 75 | return 0;
|
---|
| 76 | }
|
---|
| 77 | return this.hashCode() - obj.hashCode();
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | public Bound getBound() {
|
---|
| 81 | return this.bound;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | public void setBound(final Bound a) {
|
---|
| 85 | this.bound = a;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | public Bound getSelectionBound() {
|
---|
| 89 | return this.selectionBound;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | public void setSelectionBound(final Bound a) {
|
---|
| 93 | this.selectionBound = a;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | public boolean intersects(final MapObject o) {
|
---|
| 97 | return o != null && this.bound != null && o.bound != null && this.bound.intersects(o.bound, this, o);
|
---|
| 98 | }
|
---|
| 99 | }
|
---|