-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathActor.java
55 lines (41 loc) · 1.38 KB
/
Actor.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
package p4_group_8_repo;
import javafx.scene.image.ImageView;
import javafx.scene.input.InputEvent;
import java.util.ArrayList;
public abstract class Actor extends ImageView{
public void move(double dx, double dy) {
setX(getX() + dx);
setY(getY() + dy);
}
public World getWorld() {
return (World) getParent();
}
public double getWidth() {
return this.getBoundsInLocal().getWidth();
}
public double getHeight() {
return this.getBoundsInLocal().getHeight();
}
public <A extends Actor> java.util.List<A> getIntersectingObjects(java.lang.Class<A> cls){
ArrayList<A> someArray = new ArrayList<A>();
for (A actor: getWorld().getObjects(cls)) {
if (actor != this && actor.intersects(this.getBoundsInLocal())) {
someArray.add(actor);
}
}
return someArray;
}
public void manageInput(InputEvent e) {
}
public <A extends Actor> A getOneIntersectingObject(java.lang.Class<A> cls) {
ArrayList<A> someArray = new ArrayList<A>();
for (A actor: getWorld().getObjects(cls)) {
if (actor != this && actor.intersects(this.getBoundsInLocal())) {
someArray.add(actor);
break;
}
}
return someArray.get(0);
}
public abstract void act(long now);
}