This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoundary.java
63 lines (57 loc) · 1.54 KB
/
Boundary.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* A boundary object in the Restaurant (e.g. furniture)
*
* <p>The boundary object is "represented" as an imaginary rectangle. The user cannot walk on top of it
*
* Last edit: 6/4/2020
* @author Celeste
* @version 1.0
* @since 1.0
*/
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class Boundary extends GraphicComponent {
/**
* The direction that the player must face to enter the station
*/
protected char requiredDir;
/**
* Constructs a boundary object
* @param x x-coordinate (top-left corner)
* @param y y-coordinate (top-left corner)
* @param w width of the boundary object
* @param h height of the boundary object
* @param dir the direction that a character must face in order to hit the boundary
*/
public Boundary(int x, int y, int w, int h, char dir) {
x_coord = x;
y_coord = y;
width = w;
height = h;
requiredDir = dir;
}
public Boundary(int x, int y, int w, int h) {
x_coord = x;
y_coord = y;
width = w;
height = h;
}
@Override
public void draw(Graphics g) {}
/**
* @param figure the Character to detect collision for
* @return whether a given Character has collided with this boundary object
*/
public boolean isColliding(Character figure) {
return figure.getDirection() == requiredDir &&
figure.getX() <= x_coord + width &&
figure.getX() + figure.width >= x_coord &&
figure.getY() <= y_coord + height &&
figure.getY() + figure.height >= y_coord;
}
@Override
protected boolean withinCoordinates() {
return false;
}
}