RuneHive-Game
Loading...
Searching...
No Matches
SquareArea.java
Go to the documentation of this file.
1package com.runehive.game.world.position.impl;
2
3import com.runehive.game.world.position.Area;
4import com.runehive.game.world.position.Position;
5import com.runehive.util.Utility;
6
7public final class SquareArea extends Area {
8
9 /** The name of this area. */
10 private final String name;
11
12 /** The south-west {@code X} corner of the square. */
13 private final int swX;
14
15 /**
16 * The south-west {@code Y} corner of the square.
17 */
18 private final int swY;
19
20 /**
21 * The north-east {@code X} corner of the square.
22 */
23 private final int neX;
24
25 /**
26 * The north-east {@code Y} corner of the square.
27 */
28 private final int neY;
29
30 /**
31 * The {@code Z} level of the box.
32 */
33 private final int height;
34
35 /**
36 * Creates a new {@code SquareArea} with a default height of {@code 0}.
37 *
38 * @param swX
39 * the south-west {@code X} corner of the square.
40 * @param swY
41 * the south-west {@code Y} corner of the square.
42 * @param neX
43 * the north-east {@code X} corner of the square.
44 * @param neY
45 * the north-east {@code Y} corner of the square.
46 */
47 public SquareArea(int swX, int swY, int neX, int neY) {
48 this("Unknown", swX, swY, neX, neY, 0);
49 }
50
51 /**
52 * Creates a new {@code SquareArea} with a default height of {@code 0}.
53 *
54 * @param name
55 * The name of this area.
56 *
57 * @param swX
58 * the south-west {@code X} corner of the square.
59 * @param swY
60 * the south-west {@code Y} corner of the square.
61 * @param neX
62 * the north-east {@code X} corner of the square.
63 * @param neY
64 * the north-east {@code Y} corner of the square.
65 */
66 public SquareArea(String name, int swX, int swY, int neX, int neY) {
67 this(name, swX, swY, neX, neY, 0);
68 }
69
70 /**
71 * Creates a new {@code SquareArea}.
72 *
73 * @param name
74 * The name of this area.
75 *
76 * @param swX
77 * the south-west {@code X} corner of the square.
78 * @param swY
79 * the south-west {@code Y} corner of the square.
80 * @param neX
81 * the north-east {@code X} corner of the square.
82 * @param neY
83 * the north-east {@code Y} corner of the square.
84 * @param height
85 * the {@code Height} level of the square.
86 */
87 public SquareArea(String name, int swX, int swY, int neX, int neY, int height) {
88 this.name = name;
89 this.swX = swX;
90 this.swY = swY;
91 this.neX = neX;
92 this.neY = neY;
93 this.height = height;
94 }
95
96 /**
97 * @return The name of this area.
98 */
99 public String getName() {
100 return name;
101 }
102
103 /**
104 * @return the neX
105 */
106 public int getNeX() {
107 return neX;
108 }
109
110 /**
111 * @return the neY
112 */
113 public int getNeY() {
114 return neY;
115 }
116
117 /**
118 * @return the swX
119 */
120 public int getSwX() {
121 return swX;
122 }
123
124 /**
125 * @return the swY
126 */
127 public int getSwY() {
128 return swY;
129 }
130
131 /**
132 * @return the z
133 */
134 public int getZ() {
135 return height;
136 }
137
138 @Override
139 public boolean inArea(Position position) {
140 return position.getX() >= swX && position.getX() <= neX && position.getY() >= swY && position.getY() <= neY;
141 }
142
143 @Override
145 final int dx = Math.abs(getNeX() - getSwX()) + 1;
146 final int dy = Math.abs(getNeY() - getSwY()) + 1;
147 return new Position(getSwX() + Utility.random(dx), getSwY() + Utility.random(dy));
148 }
149
150}
Handles checking if mobs are in a certain area.
Definition Area.java:13
Represents a single tile on the game world.
Definition Position.java:14
final String name
The name of this area.
final int swY
The south-west Y corner of the square.
final int height
The Z level of the box.
final int neY
The north-east Y corner of the square.
final int neX
The north-east X corner of the square.
SquareArea(String name, int swX, int swY, int neX, int neY, int height)
Creates a new SquareArea.
SquareArea(int swX, int swY, int neX, int neY)
Creates a new SquareArea with a default height of 0.
final int swX
The south-west X corner of the square.
SquareArea(String name, int swX, int swY, int neX, int neY)
Creates a new SquareArea with a default height of 0.
Handles miscellaneous methods.
Definition Utility.java:27
static int random(int bound)
Definition Utility.java:239