forked from GuillemFP/DoubleDragon3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModuleSceneTitle.cpp
207 lines (189 loc) · 6.13 KB
/
ModuleSceneTitle.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
#include "Application.h"
#include "ModuleInput.h"
#include "ModuleWindow.h"
#include "ModuleTextures.h"
#include "ModuleRender.h"
#include "ModuleAudio.h"
#include "ModuleFonts.h"
#include "ModuleFadeToBlack.h"
#include "ModuleSceneTitle.h"
#include "ModuleEntities.h"
#include "SDL/include/SDL_scancode.h"
#include "JsonHandler.h"
#include "Timer.h"
ModuleSceneTitle::ModuleSceneTitle(JSONParser* parser, bool active) : Module(MODULESCENE_TITLE, active), current_state(LOGO1)
{
if (parser->LoadObject(SCENE_SECTION_FIRST))
{
parser->GetAnimation(animated_title, "SegaLogo_Animation");
parser->UnloadObject();
}
timer = new Timer();
}
ModuleSceneTitle::~ModuleSceneTitle()
{
RELEASE(timer);
}
bool ModuleSceneTitle::Start()
{
bool ret = true;
LOG("Loading title scene");
App->renderer->camera.x = App->renderer->camera.y = 0;
switch (current_state)
{
case LOGO1:
if (App->parser->LoadObject(SCENE_SECTION_FIRST))
{
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");
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);
}
}
else
ret = false;
break;
case LOGO2:
if (App->parser->LoadObject(SCENE_SECTION_SECOND))
{
texture = App->textures->Load(App->parser->GetString("TexturePath"));
App->parser->LoadArrayInObject("BackgroundColor");
backcolor_r = App->parser->GetIntFromArray(0);
backcolor_g = App->parser->GetIntFromArray(1);
backcolor_b = App->parser->GetIntFromArray(2);
backcolor_a = App->parser->GetIntFromArray(3);
ffade_time = abs(App->parser->GetFloat("FadeTime"));
float seconds = abs(App->parser->GetFloat("TimeSeconds"));
ret = App->parser->UnloadObject();
if (ret == true)
{
seconds -= ffade_time;
seconds = (seconds > 0.0f) ? seconds : ffade_time;
timer->Start((Uint32)seconds * 1000);
}
}
else
ret = false;
break;
case TITLE_SCROLL:
if (App->parser->LoadObject(SCENE_SECTION_THIRD))
{
texture = App->textures->Load(App->parser->GetString("TexturePath"));
App->parser->GetRect(rect_back, "BackgroundRect");
App->parser->GetRect(rect_title, "TitleRect");
int speed = abs(App->parser->GetInt("TitleSpeed"));
fspeed_title = -(float)speed;
ispeed_camera = abs(App->parser->GetInt("CameraSpeed")) * App->window->GetScreenSize();
ffade_time = abs(App->parser->GetFloat("TransitionTime"));
float music_fade = App->parser->GetFloat("MusicFade");
const char* music_string = App->parser->GetString("MusicPath");
ret = App->parser->UnloadObject();
if (ret == true)
{
ifinalpos_cam = App->window->GetScreenWidth() - rect_back.w;
ipos_background = { 0,0 };
ipos_title = { (ifinalpos_cam * speed + (App->window->GetScreenWidth() - rect_title.w) / 2), 0 };
ifinalpos_cam *= App->window->GetScreenSize();
if (App->audio->isPlayingMusic() == false)
App->audio->PlayMusic(music_string, music_fade);
}
}
else
ret = false;
break;
case TITLE:
if (App->parser->LoadObject(SCENE_SECTION_THIRD))
{
texture = App->textures->Load(App->parser->GetString("TexturePath"));
App->parser->GetRect(rect_back, "BackgroundRect");
App->parser->GetRect(rect_title, "TitleRect");
App->parser->GetRect(rect_subtitle, "SubtitleRect");
ffade_time = abs(App->parser->GetFloat("FadeTime"));
y_text = App->parser->GetInt("PositionYText");
font_text = App->parser->GetInt("FontText");
string_text = App->parser->GetString("StringTextTitle");
ret = App->parser->UnloadObject();
if (ret == true)
{
ipos_background = { App->window->GetScreenWidth() - rect_back.w,0 };
ipos_title = { (App->window->GetScreenWidth() - rect_title.w) / 2,0 };
ipos_subtitle = { (App->window->GetScreenWidth() - rect_title.w) / 2,rect_title.h };
}
}
else
ret = false;
App->entities->ResetCoins();
break;
default:
ret = false;
break;
}
return ret;
}
bool ModuleSceneTitle::CleanUp()
{
LOG("Unloading title scene");
switch (current_state)
{
case LOGO1:
timer->Stop();
current_state = LOGO2;
break;
case LOGO2:
timer->Stop();
current_state = TITLE_SCROLL;
break;
case TITLE_SCROLL:
current_state = TITLE;
break;
case TITLE:
current_state = TITLE_SCROLL;
break;
}
App->textures->Unload(texture);
return true;
}
update_status ModuleSceneTitle::Update()
{
switch (current_state)
{
case LOGO1:
App->renderer->BlitScreenCentered(texture, &(animated_title.GetCurrentFrame()));
if (timer->MaxTimeReached() == true && App->fade->isFading() == false)
App->fade->FadeToBlack(this, this, ffade_time);
break;
case LOGO2:
App->renderer->DrawQuad(App->renderer->camera, backcolor_r, backcolor_g, backcolor_b, backcolor_a, false);
App->renderer->BlitScreenCentered(texture, NULL);
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 TITLE_SCROLL:
if (App->renderer->camera.x > ifinalpos_cam)
App->renderer->camera.x -= ispeed_camera;
App->renderer->Blit(texture, ipos_background, &rect_back);
App->renderer->Blit(texture, ipos_title, &rect_title, fspeed_title);
if ((App->input->GetKey(SDL_SCANCODE_RETURN) == KEY_DOWN || App->renderer->camera.x <= ifinalpos_cam) && App->fade->isFading() == false)
App->fade->FadeToWhite(this, this, ffade_time);
break;
case TITLE:
App->renderer->Blit(texture, ipos_background, &rect_back);
App->renderer->Blit(texture, ipos_title, &rect_title);
App->renderer->Blit(texture, ipos_subtitle, &rect_subtitle);
App->fonts->BlitScreenXCentered(font_text, y_text, string_text);
if (App->input->GetKey(SDL_SCANCODE_RETURN) == KEY_DOWN && App->fade->isFading() == false)
App->fade->FadeToBlack((Module*)App->scene_prestage, this);
break;
default:
break;
}
return UPDATE_CONTINUE;
}