-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameManager.pde
executable file
·138 lines (121 loc) · 4.76 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
class GameManager implements Tickable{
ArrayList timelines = new ArrayList<Timeline>();
ArrayList bursts = new ArrayList<Burst>();
ArrayList enemies = new ArrayList<Enemy>();
ArrayList bullets = new ArrayList<Bullet>();
int startTime, pauseTime, currentTime, lastTime; //Handles timeline management and smooth pausing.
public int score;
boolean paused;
boolean start(){
reset();
startTime = tickTime;
currentTime = tickTime; //Makes sure the game starts with a clean slate.
paused = false;
player.reset();
this.timelines.add(new Timeline("core-main"));
startTime = tickTime;
for(Object obj : timelines.toArray()){
Timeline line = (Timeline) obj;
line.start(tickTime - startTime);
}
//println(timelines.size());
return true;
}
boolean tick(int time){
return tick();
}
boolean tick() { //Good lord I haven't even gotten to the bullets the player spawns. I cry.
if(esc_key == 1 && gameState == 2){
esc_key++;
pause.reset();
gameState = 3;
}
lastTime = currentTime;
if(!paused){
currentTime = tickTime;
}
//println(currentTime - lastTime);
player.move(currentTime - lastTime);
player.drawUnder();
for (Object obj : timelines.toArray()){ //Tick each of the four types of timeline (enemies not implemented yet). Remove them if their tick doesn't succeed (false result).
Timeline line = (Timeline) obj;
if(! line.tick(currentTime - lastTime)){
println("removed a timeline?!");
timelines.remove(line);
}
}
for (Object obj : bursts.toArray ()) {
Burst burst = (Burst) obj;
if(!burst.tick(currentTime - lastTime))
bursts.remove(burst);
}
for (Object obj : enemies.toArray ()) {
Enemy enemy = (Enemy) obj;
if(enemy.tick(currentTime - lastTime)){
enemy.draw();
player.collide(enemy);
}else{
//println("enemy deleted");
enemies.remove(enemy);
}
}
for (Object obj : bullets.toArray ()) {
Bullet bullet = (Bullet) obj;
if (bullet.tick(currentTime - lastTime)) {
bullet.draw();
player.collide(bullet);
} else {
//println("bullet deleted");
bullets.remove(bullet);
}
}
player.draw();
//println(timelines.size());
if(timelines.size() == 0 && bursts.size() == 0 && enemies.size() == 0 && bullets.size() == 0){ //If the round ends in a victory, then do this.
endMenu.rescore();
if(menu.bestWinScore < window.score) //And update the victory end highscore.
menu.bestWinScore = window.score;
menu.won = true;
gameState = 5;
}
return true;
}
void pause(){
if(!paused){
pauseTime = tickTime;
paused = true;
}
}
void resume(){
if(paused){
startTime += tickTime - pauseTime;
currentTime += tickTime - pauseTime;
paused = false;
}
}
void interrupt(){
resume();
}
void notifyDead(){ //Called by player upon death.
endMenu.rescore();
if((manager.currentTime - manager.startTime)/1000f > menu.bestTime){ //Handles best-time scenarios.
if(((manager.currentTime - manager.startTime)/1000f == menu.bestTime && (window.score > menu.bestTimeScore)) || (manager.currentTime - manager.startTime)/1000f > menu.bestTime)
menu.bestTimeScore = window.score;
menu.bestTime = (manager.currentTime - manager.startTime)/1000f;
}
if(window.score > menu.bestScore){ //Handles best score scenarios.
if(((window.score == menu.bestScore) && (manager.currentTime - manager.startTime)/1000f > menu.bestScoreTime) || (window.score > menu.bestScore))
menu.bestScoreTime = (manager.currentTime - manager.startTime)/1000f;
menu.bestScore = window.score;
}
menu.scored = true; //Only one variable for both since it's guaranteed after the first death both will be set.
gameState = 4;
}
void reset(){
timelines.clear();
bursts.clear();
enemies.clear();
bullets.clear();
paused = false;
}
}