-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtutorial_scene.cpp
74 lines (62 loc) · 2.01 KB
/
tutorial_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "tutorial_scene.h"
#include "goal.h"
#include "score.h"
#include "player.h"
#include "pupper.h"
#include "screen_config.h"
#include "home_scene.h"
extern Scene * current_scene;
extern std::unique_ptr<Home_scene> home;
Tutorial_scene::Tutorial_scene(sdlxx::Sdl_renderer& renderer)
: _overlay{"resources/overlay.bmp", renderer}
{
std::cout << "tutorial constructed!";
}
void Tutorial_scene::update()
{
Player* player = nullptr;
Pupper* pupper = nullptr;
Goal * mailbox = nullptr;
if (player == nullptr) {
for (auto& object : scene_objects) {
if (object->isPlayer) {
player = dynamic_cast<Player*>(object.get());
}
if (object->isPupper) {
pupper = dynamic_cast<Pupper*>(object.get());
}
if (object->isGoal) {
mailbox = dynamic_cast<Goal*>(object.get());
}
}
}
for (auto& object : scene_objects) { object->update(); }
for (auto a = scene_objects.begin(); a < scene_objects.end(); ++a) {
for (auto b = scene_objects.begin(); b < scene_objects.end(); ++b) {
// Don't collide with yourself
if (a == b) { continue; }
if ((**a).collides_with(**b)) { (**a).collide(**b); }
}
}
for (auto it = scene_objects.begin(); it != scene_objects.end();) {
if ((**it).should_be_destroyed()) { it = scene_objects.erase(it); }
else {
++it;
}
}
// If the player brings the pupper to the mailbox
if (player->collides_with(*mailbox) ) {
if (pupper->isHeld()) {
scene_objects.clear();
current_scene = home.get();
}
}
}
void Tutorial_scene::draw(sdlxx::Sdl_renderer& renderer)
{
// sdlxx::Sdl_texture overlay{"resources/overlay.bmp", renderer};
renderer.copy(_overlay, 0, 0);
for (auto& object : scene_objects) { object->draw(renderer); }
Score::sharedInstance().draw(renderer);
std::cout << "Drawing the overlay\n";
}