source: lost-perception/main/MapObject.java@ 57674f3

Last change on this file since 57674f3 was a10d422, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 4 years ago

Create a working makefile target for MapEditor

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