-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameOver.cpp
72 lines (64 loc) · 1.77 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
65
66
67
68
69
70
71
72
#include "GameOver.h"
#include "GameStart.h"
#include "EventStep.h"
#include "EventView.h"
#include "Event.h"
#include "GameManager.h"
#include "LogManager.h"
#include "ResourceManager.h"
#include "WorldManager.h"
#include "LevelManager.h"
#include "Player.h"
GameOver::GameOver() {
//p.setPosition(df::Vector(40, 12));
p.getAnimation().getSprite()->setColor(df::BLACK);
setAltitude(3);
setType("GameOver");
//links to the "game over" sprite
printf("gameOver constructor");
; if (setSprite("gameover") == 0) {
time_to_live = getAnimation().getSprite()->getFrameCount() * getAnimation().getSprite()->getSlowdown();
}
else {
time_to_live = 0;
}
setColor(df::YELLOW);
//Sets location
df::Vector pos(p.getPosition());
setPosition(pos);
printf("inserting into levelmanager");
levelM.insertProtected(this);
printf("inserted into levelmanager");
}
//Handles event
int GameOver::eventHandler(const df::Event* p_e) {
if (p_e->getType() == df::STEP_EVENT) {
step();
return 1;
}
return 0;//Ignore
}
//Message count down
void GameOver::step() {
time_to_live--;
if (time_to_live <= 0) {
WM.markForDelete(this);
}
}
//Resets game for Game Start
GameOver::~GameOver() {
//Removes Enemies and ViewObjects
df::ObjectListIterator i(new df::ObjectList(WM.getAllObjects()));
for (i.first(); !i.isDone(); i.next()) {
df::Object* p_o = i.currentObject();
if (p_o->getType() != "Player" && p_o->getType() != "Reticle" && p_o->getType() != "GameOver") {
std::cout << p_o->getType() << "\n";
WM.markForDelete(p_o);
}
}
exit(0);
}
//Draws game over screen
int GameOver::draw() {
return df::Object::draw();
}