-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDisplayList.pde
72 lines (56 loc) · 1.93 KB
/
DisplayList.pde
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
64
65
66
67
68
69
70
71
72
class DisplayList {
List objects = new LinkedList();
public void add(DisplayObject o) {
objects.add(o);
}
public void update() {
ListIterator it = objects.listIterator();
while (it.hasNext()) {
DisplayObject fo = (DisplayObject)it.next();
fo.update(it);
}
}
public void hitTest() {
// Compare all pairs
ListIterator lit = objects.listIterator(0);
ArrayList newObjects = new ArrayList();
FlyingObject l, r = null;
Object x;
if (!noHit) {
while (lit.hasNext()) {
x = lit.next();
if (!(x instanceof FlyingObject)) continue;
l = (FlyingObject)x;
if (l.remove) continue;
ListIterator rit = objects.listIterator(lit.nextIndex());
while (rit.hasNext()) {
x = rit.next();
if (!(x instanceof FlyingObject)) continue;
r = (FlyingObject)x;
if (r.remove) continue;
if (l.intersects(r)) {
l.collide(r, newObjects);
r.collide(l, newObjects);
break;
}
}
}
}
// Remove dead objects.
Iterator it = objects.iterator();
while (it.hasNext()) {
DisplayObject fo = (DisplayObject)it.next();
if (fo.remove) {
println("yanking " + fo.getClass().getName());
it.remove();
}
}
// Add new objects.
it = newObjects.iterator();
while (it.hasNext())
objects.add(it.next());
}
public Iterator iterator() {
return objects.iterator();
}
}