-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameManager.pde
88 lines (66 loc) · 2.01 KB
/
GameManager.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
public class GameManager {
public static final int NOT_STARTED = 1;
public static final int FLYING = 2;
public static final int FALLEN = 3;
public static final int FINALIZED = 4;
private int state = NOT_STARTED;
public int getState() {
return state;
}
/**
*maximal y coordinate of the flier.
*If this coordinate grows further (i. e. flier falls too low),
*the game is considered lost
*/
private float maxFlierDescent;
/**
*minimal y coordinate of the flier.
*If this coordinate grows further (i. e. flier falls too low),
*he would not fit to the screen, bul the game will continue
*/
private float minFlierDescent;
public boolean flierOverflown() {
return flier.getPosition().y < minFlierDescent;
}
public boolean flierFallen() {
return flier.getPosition().y > maxFlierDescent;
}
private Flier flier;
private InputAdapter input;
private EffectManager effectManager;
private Camera2D camera2d;
private PVector initFlSpeed = new PVector(0, 0);
public GameManager() throws IOException {
PVector _pos = new PVector(sketchWidth()/2, sketchHeight()/2);
camera2d = new Camera2D(new PVector(_pos.x,_pos.y));
minFlierDescent = 0;
maxFlierDescent = sketchHeight();
flier = new Flier(_pos, initFlSpeed);
camera2d.add(flier);
input = new InputAdapter(new SoundManager());
effectManager = new EffectManager();
effectManager.add(new ParticleManager());
camera2d.add(effectManager);
state = NOT_STARTED;
//TODO maybe this should be moved in some other place
start();
}
public void start()throws IOException {
state = FLYING;
}
public void manage() {
if (frameCount % 15 == 0)
flier.setSpeed(input.getFlierSpeed());
flier.move();
effectManager.manageAll();
camera2d.setPosition(flier.getPosition());
if (flierFallen()) {
state = FALLEN;
}
}
public void draw() {
effectManager.drawAll();
flier.draw();
ellipseMode(CENTER);
}
};