-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathState.pde
67 lines (51 loc) · 1.49 KB
/
State.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
public abstract class State {
private String name;
private PApplet context;
private StateSingleton currentState;
private Star[] stars;
public State(String name, PApplet context) {
this.name = name;
this.context = context;
this.context.registerMethod("mouseEvent", this);
this.context.registerMethod("keyEvent", this);
this.currentState = StateSingleton.getInstance(context);
this.stars = new Star[500];
for (int i = 0; i < this.stars.length; i++) {
this.stars[i] = new Star();
}
}
abstract public void setup();
abstract void draw();
abstract void mouseEvent(MouseEvent event);
abstract void keyEvent(KeyEvent event);
protected void drawBackground(color c) {
cam.beginHUD();
translate(0, -200);
background(c);
translate(width/2, height/2);
for (int i = 0; i < stars.length; i++) {
stars[i].update();
stars[i].show();
}
cam.endHUD();
}
protected void setCurrentState(String state) {
this.currentState.state = state;
this.currentState.states.get(state).setup();
}
protected String getCurrentState() {
return this.currentState.state;
}
protected void setCurrentScore(int score) {
this.currentState.setScore(score);
}
protected int getCurrentScore() {
return this.currentState.getScore();
}
protected boolean isActive() {
return this.name.equals(getCurrentState());
}
public String getName() {
return this.name;
}
}