-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcutscene.cpp
More file actions
112 lines (95 loc) · 2.74 KB
/
cutscene.cpp
File metadata and controls
112 lines (95 loc) · 2.74 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "cutscene.hpp"
namespace TerraNova {
namespace {
//const std::string CUTSCENE_BACKGROUND = "space-colony";
//const std::string CUTSCENE_BGM = "cutscene_bgm.ogg";
const std::string CUTSCENE_DIALOGUE = "chapters/1/cutscenes/opening.txt";
} // anonymous namespace
CutsceneScreen::CutsceneScreen(SDL_Renderer* ren) {
this->ren = ren;
dialogue = std::make_unique<Dialogue>(CUTSCENE_DIALOGUE);
dialogueBox = std::make_unique<DialogueBox>(ren, dialogue.get());
backgroundName = dialogueBox->BackgroundName();
if (backgroundName.empty()) {
std::cerr << "Error: dialogue box returned an empty background name. "
<< "A valid name is required for cutscenes." << std::endl;
}
SetBackground(backgroundName);
bgmName = dialogueBox->BGMName();
if (bgmName.empty()) {
std::cerr << "Error: dialogue box returned an empty BGM name. "
<< "A valid name is required for cutscenes." << std::endl;
}
Audio::PlayMusic(bgmName);
// should actually read this from some definition file
nextScreen = GAME_SCREEN;
}
CutsceneScreen::~CutsceneScreen() {
}
void CutsceneScreen::SetBackground(const std::string& filename) {
background.clear();
background.push_back(std::make_unique<UIElement>(ren,
File::JoinPaths({"backgrounds", filename}), 0, 0));
//std::cout << "Menu screen background set." << std::endl;
}
void CutsceneScreen::KeyPress(const SDL_Keycode key) {
switch(key) {
case SDLK_RETURN:
case SDLK_RIGHT: {
AdvanceDialogue();
return;
}
case SDLK_LEFT: {
BackstepDialogue();
return;
}
case SDLK_1: {
dialogueBox->MakeDecision(1);
return;
}
case SDLK_2: {
dialogueBox->MakeDecision(2);
return;
}
case SDLK_3: {
dialogueBox->MakeDecision(3);
return;
}
case SDLK_4: {
dialogueBox->MakeDecision(4);
return;
}
case SDLK_5: {
dialogueBox->MakeDecision(5);
return;
}
}
}
void CutsceneScreen::LeftClick(const int, const int) {
AdvanceDialogue();
}
void CutsceneScreen::RightClick(const int, const int) {
BackstepDialogue();
}
void CutsceneScreen::Render() {
for (auto& bg : background) bg->Render();
dialogueBox->Render();
}
void CutsceneScreen::AdvanceDialogue() {
bool endOfDialogue = dialogueBox->Advance();
if (dialogueBox->BackgroundName() != backgroundName)
backgroundName = dialogueBox->BackgroundName();
SetBackground(backgroundName);
if (dialogueBox->BGMName() != bgmName) {
bgmName = dialogueBox->BGMName();
Audio::PlayMusic(bgmName);
}
if (endOfDialogue) ScreenHandoff();
}
void CutsceneScreen::BackstepDialogue() {
dialogueBox->Backstep();
}
void CutsceneScreen::ScreenHandoff() {
wantScreen = nextScreen;
}
} // namespace TerraNova