forked from GuillemFP/DoubleDragon3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModuleScenePreStage.cpp
221 lines (202 loc) · 6.93 KB
/
ModuleScenePreStage.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include "Application.h"
#include "ModuleInput.h"
#include "ModuleWindow.h"
#include "ModuleRender.h"
#include "ModuleTextures.h"
#include "ModuleAudio.h"
#include "ModuleFonts.h"
#include "ModuleFadeToBlack.h"
#include "ModuleScenePreStage.h"
#include "SDL/include/SDL_scancode.h"
#include "JsonHandler.h"
#include "Timer.h"
ModuleScenePreStage::ModuleScenePreStage(JSONParser* parser, bool active) : Module(MODULESCENE_PRESTAGE, active), current_state(HISTORY1)
{
if (parser->LoadObject(SCENE_SECTION_PRESTAGE))
{
parser->GetAnimation(animated_point, "Point_Animation");
parser->GetAnimation(face1, "Eyes_Animation");
parser->GetAnimation(face2, "Mouth_Animation");
parser->UnloadObject();
}
timer = new Timer();
}
ModuleScenePreStage::~ModuleScenePreStage()
{
RELEASE(timer);
}
bool ModuleScenePreStage::Start()
{
bool ret = true;
LOG("Loading pre-stage scene");
App->renderer->camera.x = App->renderer->camera.y = 0;
switch (current_state)
{
case HISTORY1:
if (App->parser->LoadObject(SCENE_SECTION_HISTORY1))
{
texture = App->textures->Load(App->parser->GetString("TexturePath"));
App->parser->GetRect(rect_map, "BackRect");
App->parser->GetPoint(ipos_map, "BackPos");
ffade_time = abs(App->parser->GetFloat("FadeTime"));
float seconds = abs(App->parser->GetFloat("TimeSeconds"));
int ilines = App->parser->GetInt("NumTextLines");
App->parser->LoadArrayInObject("TextLines");
for (int i = 0; i < ilines; i++)
{
lines.push_back(new TextLine());
App->fonts->FillTextLine(lines.back(), i);
}
ret = App->parser->UnloadObject();
if (ret == true)
{
seconds -= ffade_time;
seconds = (seconds > 0.0f) ? seconds : ffade_time;
timer->Start((Uint32)seconds * 1000);
}
}
App->audio->StopMusic();
break;
case HISTORY2:
case HISTORY3:
if (App->parser->LoadObject(SCENE_SECTION_HISTORY2))
{
texture = App->textures->Load(App->parser->GetString("TexturePath"));
App->parser->GetRect(rect_map, "BackRect");
App->parser->GetPoint(ipos_map, "BackPos");
App->parser->GetPoint(ipos_face1, "EyesOnFace");
App->parser->GetPoint(ipos_face2, "MouthOnFace");
ffade_time = abs(App->parser->GetFloat("FadeTime"));
float seconds = abs(App->parser->GetFloat("TimeSeconds"));
int ilines = App->parser->GetInt("NumTextLines");
ilines_print = App->parser->GetInt("FirstPrint");
App->parser->LoadArrayInObject("TextLines");
for (int i = 0; i < ilines; i++)
{
lines.push_back(new TextLine());
App->fonts->FillTextLine(lines.back(), i);
}
ret = App->parser->UnloadObject();
if (ret == true)
{
seconds -= ffade_time;
seconds = (seconds > 0.0f) ? seconds : ffade_time;
timer->Start((Uint32)seconds * 1000);
ipos_face1.y += ipos_map.y;
ipos_face1.x += (App->window->GetScreenWidth() - rect_map.w) / 2;
ipos_face2.y += ipos_map.y;
ipos_face2.x += (App->window->GetScreenWidth() - rect_map.w) / 2;
}
}
break;
case STAGE3:
if (App->parser->LoadObject(SCENE_SECTION_PRESTAGE3))
{
texture = App->textures->Load(App->parser->GetString("TexturePath"));
ffade_time = abs(App->parser->GetFloat("FadeTime"));
float seconds = abs(App->parser->GetFloat("TimeSeconds"));
float music_fade = App->parser->GetFloat("MusicFade");
const char* music_string = App->parser->GetString("MusicPath");
App->parser->GetRect(rect_map, "MapRect");
App->parser->GetRect(rect_mission, "MissionRect");
App->parser->GetRect(rect_country, "CountryRect");
App->parser->GetPoint(ipos_map, "MapPos");
App->parser->GetPoint(ipos_mission, "MissionPos");
App->parser->GetPoint(ipos_country, "CountryPos");
App->parser->GetPoint(ipos_point, "PointOnMap");
ret = App->parser->UnloadObject();
if (ret == true)
{
seconds -= ffade_time;
seconds = (seconds > 0.0f) ? seconds : ffade_time;
timer->Start((Uint32)seconds * 1000);
App->audio->PlayMusic(music_string, music_fade);
ipos_point.y += ipos_map.y;
ipos_point.x += (App->window->GetScreenWidth() - rect_map.w) / 2;
}
}
break;
default:
break;
}
return ret;
}
bool ModuleScenePreStage::CleanUp()
{
LOG("Unloading pre-stage scene");
App->textures->Unload(texture);
switch (current_state)
{
case HISTORY1:
timer->Stop();
for (std::vector<TextLine*>::iterator it = lines.begin(); it != lines.end(); ++it)
RELEASE(*it);
lines.clear();
current_state = HISTORY2;
break;
case HISTORY2:
case HISTORY3:
timer->Stop();
for (std::vector<TextLine*>::iterator it = lines.begin(); it != lines.end(); ++it)
RELEASE(*it);
lines.clear();
current_state = STAGE3;
break;
case STAGE3:
timer->Stop();
current_state = HISTORY1;
break;
default:
break;
}
return true;
}
update_status ModuleScenePreStage::Update()
{
switch (current_state)
{
case HISTORY1:
App->renderer->BlitScreenXCentered(texture, ipos_map.y, &rect_map);
for (std::vector<TextLine*>::iterator it = lines.begin(); it != lines.end(); ++it)
App->fonts->BlitScreenXCentered((*it)->id_font, (*it)->y, (*it)->line);
if ((App->input->GetKey(SDL_SCANCODE_RETURN) == KEY_DOWN || timer->MaxTimeReached() == true) && App->fade->isFading() == false)
App->fade->FadeToBlack(this, this, ffade_time);
break;
case HISTORY2:
App->renderer->BlitScreenXCentered(texture, ipos_map.y, &rect_map);
App->renderer->Blit(texture, ipos_face1, &(face1.GetCurrentFrame()));
App->renderer->Blit(texture, ipos_face2, &(face2.GetCurrentFrame()));
for (int i = 0; i < ilines_print; i++)
if (lines[i] != nullptr)
App->fonts->BlitScreenXCentered(lines[i]->id_font, lines[i]->y, lines[i]->line);
if (App->input->GetKey(SDL_SCANCODE_RETURN) == KEY_DOWN && App->fade->isFading() == false)
App->fade->FadeToBlack(this, this, ffade_time);
if (timer->MaxTimeReached() == true && App->fade->isFading() == false)
{
timer->Reset();
current_state = HISTORY3;
}
break;
case HISTORY3:
App->renderer->BlitScreenXCentered(texture, ipos_map.y, &rect_map);
App->renderer->Blit(texture, ipos_face1, &(face1.GetCurrentFrame()));
App->renderer->Blit(texture, ipos_face2, &(face2.GetCurrentFrame()));
for (int i = ilines_print; i < lines.size(); i++)
if (lines[i] != nullptr)
App->fonts->BlitScreenXCentered(lines[i]->id_font, lines[i]->y, lines[i]->line);
if ((App->input->GetKey(SDL_SCANCODE_RETURN) == KEY_DOWN || timer->MaxTimeReached() == true) && App->fade->isFading() == false)
App->fade->FadeToBlack(this, this, ffade_time);
break;
case STAGE3:
App->renderer->BlitScreenXCentered(texture, ipos_map.y, &rect_map);
App->renderer->BlitScreenXCentered(texture, ipos_mission.y, &rect_mission);
App->renderer->BlitScreenXCentered(texture, ipos_country.y, &rect_country);
App->renderer->Blit(texture, ipos_point, &(animated_point.GetCurrentFrame()));
if ((App->input->GetKey(SDL_SCANCODE_RETURN) == KEY_DOWN || timer->MaxTimeReached() == true) && App->fade->isFading() == false)
App->fade->FadeToBlack((Module*) App->scene_stage3, this, ffade_time);
break;
default:
break;
}
return UPDATE_CONTINUE;
}