-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scene.pde
59 lines (53 loc) · 1.44 KB
/
Scene.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
class Scene {
public String name = "default";
PVector origin = new PVector( 0, 0 );
private ArrayList<Object> objects = new ArrayList<Object>();
private ArrayList<Object> toDelete = new ArrayList<Object>();
private ArrayList<Object> toAdd = new ArrayList<Object>();
void addObj( Object obj ) {
if ( obj == null ) return;
obj.m_scene = this;
toAdd.add( obj );
}
void removeObj( Object obj ) {
if ( obj == null ) return;
toDelete.add( obj );
}
ArrayList<Object> getObjByBehaviour( BehaviourType t ) {
ArrayList<Object> result = new ArrayList<Object>();
for ( int i = 0; i < objects.size(); i++ ) {
if ( objects.get(i).hasBehaviour( t ) ) result.add( objects.get(i) );
}
return result;
}
ArrayList<Behaviour> getBehaviours( BehaviourType t ) {
ArrayList<Behaviour> result = new ArrayList<Behaviour>();
for ( int i = 0; i < objects.size(); i++ ) {
Behaviour b = objects.get(i).getBehaviour( t );
if ( b != null ) result.add( b );
}
return result;
}
void update() {
for ( Object obj : objects ) {
obj.update();
}
for ( Object toDel : toDelete ) {
objects.remove( toDel );
}
toDelete.clear();
for ( Object newObj : toAdd ) {
objects.add( newObj );
}
toAdd.clear();
}
void draw() {
for ( Object obj : objects ) {
pushMatrix();
pushStyle();
obj.draw();
popStyle();
popMatrix();
}
}
}