-
Notifications
You must be signed in to change notification settings - Fork 1
/
GameObject.pde
65 lines (54 loc) · 1.42 KB
/
GameObject.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
class GameObject {
PVector worldPos;//position in the world
PVector dim; //width and height of player
ArrayList<Component> components;
String type;
GameObject(String tp) {
this.worldPos = new PVector(0, 0);
this.dim = new PVector(0, 0);
components = new ArrayList<Component>();
type = tp;
}
void update() {
for (int i=0; i< components.size(); i++) {
Component comp = components.get(i);
comp.update();
}
}
void updateEarly(){
for (int i=0; i< components.size(); i++) {
Component comp = components.get(i);
comp.updateEarly();
}
}
void updateLate(){
for (int i=0; i< components.size(); i++) {
Component comp = components.get(i);
comp.updateLate();
}
}
public boolean hasComponent(String kind) {
for (int i=0; i< components.size(); i++) {
Component c = (Component) components.get(i);
if (c.type == kind) {
return true;
}
}//end of for loop
return false;
}//end of hasComponent()
public Component getComponent(String kind) {
for (int i=0; i< components.size(); i++) {
Component c = (Component) components.get(i);
if (c.type == kind) {
return c;
}
}
return null;
}//end of getComponent
public void beginComponents(){
for (int i=0; i< components.size(); i++) {
Component c = (Component) components.get(i);
c.begin();
}
}
}//end of Class