-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDungeonScene.cpp
More file actions
82 lines (71 loc) · 2.59 KB
/
DungeonScene.cpp
File metadata and controls
82 lines (71 loc) · 2.59 KB
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
#include "DungeonScene.hpp"
#include "Game.hpp"
DungeonScene::DungeonScene(Game* g, sf::RenderWindow* w, sceneTypes sT, std::string name, std::string description) :
ScenePlayable(g,w,sT,name,description),
_topDoor(0,sf::Vector2f(120,16),directions::up),
_botDoor(0,sf::Vector2f(120,144),directions::down),
_leftDoor(0,sf::Vector2f(16,80),directions::left),
_rightDoor(0,sf::Vector2f(224,80),directions::right)
{
_sceneIniCoord = sf::Vector2f(FLT_MAX,FLT_MAX);
}
DungeonScene::~DungeonScene() {
}
void DungeonScene::init(sf::Vector2f sceneIniCoord = sf::Vector2f(0,0)) {
sf::Vector2f aux = _sceneIniCoord;
ScenePlayable::init(sceneIniCoord);
if (sceneIniCoord == aux) return;
if (aux == sf::Vector2f(FLT_MAX,FLT_MAX)) {
auto mapDoors = _map.getDungeonDoors();
for (auto it = mapDoors.begin(); it != mapDoors.end(); ++it) addDoor(*(*it).first,(*it).second);
addProp(&_topDoor);
addProp(&_botDoor);
addProp(&_leftDoor);
addProp(&_rightDoor);
}
_topDoor.setIniCoord(_sceneIniCoord);
_botDoor.setIniCoord(_sceneIniCoord);
_leftDoor.setIniCoord(_sceneIniCoord);
_rightDoor.setIniCoord(_sceneIniCoord);
_topDoor.setScene(this);
_botDoor.setScene(this);
_leftDoor.setScene(this);
_rightDoor.setScene(this);
if (DataManager::getBool(_sceneName+std::to_string(directions::up ), false)) _topDoor.openWithKey();
if (DataManager::getBool(_sceneName+std::to_string(directions::down ), false)) _botDoor.openWithKey();
if (DataManager::getBool(_sceneName+std::to_string(directions::left ), false)) _leftDoor.openWithKey();
if (DataManager::getBool(_sceneName+std::to_string(directions::right), false)) _rightDoor.openWithKey();
}
void DungeonScene::update(float deltaTime) {
ScenePlayable::update(deltaTime);
if (_enemies.empty()) openDoors();
else closeDoors();
}
void DungeonScene::render(sf::RenderTarget* target) {
ScenePlayable::render(target);
}
sceneTypes DungeonScene::getType(){
return sceneTypes::dungeon;
}
void DungeonScene::addDoor(DungeonDoor door,directions dir) {
if (dir == directions::up) _topDoor = door;
else if (dir == directions::down) _botDoor = door;
else if (dir == directions::left) _leftDoor = door;
else if (dir == directions::right) _rightDoor = door;
else {
std::cout << "Wrong direction adding a door " << std::endl;
exit(EXIT_FAILURE);
}
}
void DungeonScene::openDoors() {
_topDoor.open();
_botDoor.open();
_leftDoor.open();
_rightDoor.open();
}
void DungeonScene::closeDoors() {
_topDoor.close();
_botDoor.close();
_leftDoor.close();
_rightDoor.close();
}