-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScene.cpp
52 lines (39 loc) · 1.51 KB
/
Scene.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
#include "Scene.h"
std::string filename = "labyrinth/Labirinth.txt";
void Scene::init() {
labyrinth = Labyrinth(filename);
auto pacman = std::unique_ptr<Entity>(new PacMan());
auto blinky = std::unique_ptr<Entity>(new Ghost(13, 14, 3, 4, 0.020f * 2, 0));
auto pinky = std::unique_ptr<Entity>(new Ghost(13, 17, 23, 4, 0.017f * 2, 1));
auto inky = std::unique_ptr<Entity>(new Ghost(11, 17, 26, 32, 0.014f * 2, 2));
auto clyde = std::unique_ptr<Entity>(new Ghost(15, 17, 1, 32, 0.011f * 2, 3));
blinky->teleport(15, 14);
entities.push_back(std::move(pacman));
entities.push_back(std::move(blinky));
entities.push_back(std::move(pinky));
entities.push_back(std::move(inky));
entities.push_back(std::move(clyde));
delay = 0;
}
void Scene::draw(sf::RenderWindow *window) {
for (auto &&entity: entities)
entity->draw(window, labyrinth);
}
void Scene::loop(sf::RenderWindow *window) {
for (auto &&entity: entities)
if (!entity->render(delay, entities, window, labyrinth))
Scene::init();
}
void Scene::create(sf::RenderWindow *window) {
for (int i = 0; i < Labyrinth::getSizeX(); i++) {
for (int j = 0; j < Labyrinth::getSizeY(); j++) {
Resources::LabyrinthPieces[labyrinth.getValue(i, j)]->setPosition(i * 16.0f, j * 16.0f);
window->draw(*Resources::LabyrinthPieces[labyrinth.getValue(i, j)]);
}
}
draw(window);
}
void Scene::key(int code) {
for (auto &&entity: entities)
entity->key(code);
}