-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGameOver.cpp
64 lines (51 loc) · 1.23 KB
/
GameOver.cpp
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
//
// GameOver.cpp
//
// Engine includes.
#include "DisplayManager.h"
#include "EventStep.h"
#include "GameManager.h"
#include "LogManager.h"
#include "WorldManager.h"
// Game includes.
#include "DisplayManager.h"
#include "GameOver.h"
GameOver::GameOver() {
setType("GameOver");
// Put in center of screen.
int world_horiz = (int) DM.getHorizontal();
int world_vert = (int) DM.getVertical();
df::Vector p((float)(world_horiz/2.0f), (float) (world_vert/2.0f));
setPosition(p);
// Exit after about 3 seconds.
time_to_live = 100;
// Make like a View Object
setSolidness(df::SPECTRAL);
setAltitude(df::MAX_ALTITUDE);
// Register for step event.
#ifdef DF_REGISTER_INTEREST
registerInterest(df::STEP_EVENT);
#endif
}
// Handle event.
// Return 0 if ignored, else 1.
int GameOver::eventHandler(const df::Event *p_e) {
if (p_e->getType() == df::STEP_EVENT) {
step();
return 1;
}
// If get here, have ignored this event.
return 0;
}
// Count down to end of message.
void GameOver::step() {
time_to_live--;
if (time_to_live <= 0) {
WM.markForDelete(this);
GM.setGameOver();
}
}
int GameOver::draw() {
DM.drawString(getPosition(), "Game Over!", df::CENTER_JUSTIFIED, df::WHITE);
return 0;
}