-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModuleSceneIntro.cpp
More file actions
198 lines (163 loc) · 5.43 KB
/
ModuleSceneIntro.cpp
File metadata and controls
198 lines (163 loc) · 5.43 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
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
//=================================
// forward declared dependencies
//=================================
// included dependencies
#include "ModuleSceneIntro.h"
#include "Application.h"
#include "ModuleAudio.h"
#include "ModuleFadeToBlack.h"
#include "ModuleInput.h"
#include "ModuleRender.h"
#include "ModuleTextures.h"
#include "ModuleSceneSpace.h"
//=================================
// the actual class
ModuleSceneIntro::ModuleSceneIntro(Application *app, bool start_enabled) : Module(app, start_enabled)
{
intro = NULL;
numbers = NULL;
fx = 0;
// From numbers_coins animation
numbers_coins.frames.pushBack({ 0, 0, 8, 7 });
numbers_coins.frames.pushBack({ 8, 0, 8, 7 });
numbers_coins.frames.pushBack({ 16, 0, 8, 7 });
numbers_coins.frames.pushBack({ 24, 0, 8, 7 });
numbers_coins.frames.pushBack({ 32, 0, 8, 7 });
numbers_coins.frames.pushBack({ 40, 0, 8, 7 });
numbers_coins.frames.pushBack({ 48, 0, 8, 7 });
numbers_coins.frames.pushBack({ 56, 0, 8, 7 });
numbers_coins.frames.pushBack({ 64, 0, 8, 7 });
numbers_coins.frames.pushBack({ 72, 0, 8, 7 });
numbers_coins.speed = 0.0f;
numbers_coins.loop = false;
press_space_glow.frames.pushBack({ 0, 0, 160, 7 });
press_space_glow.frames.pushBack({ 0, 8, 160, 7 });
press_space_glow.frames.pushBack({ 0, 16, 160, 7 });
press_space_glow.frames.pushBack({ 0, 24, 160, 7 });
press_space_glow.frames.pushBack({ 0, 32, 160, 7 });
press_space_glow.frames.pushBack({ 0, 32, 160, 7 });
press_space_glow.frames.pushBack({ 0, 32, 160, 7 });
press_space_glow.frames.pushBack({ 0, 32, 160, 7 });
press_space_glow.frames.pushBack({ 0, 32, 160, 7 });
press_space_glow.frames.pushBack({ 0, 32, 160, 7 });
press_space_glow.frames.pushBack({ 0, 40, 160, 7 });
press_space_glow.frames.pushBack({ 0, 48, 160, 7 });
press_space_glow.frames.pushBack({ 0, 56, 160, 7 });
press_space_glow.frames.pushBack({ 0, 0, 160, 7 });
press_space_glow.speed = 0.15f;
press_space_glow.loop = true;
}
ModuleSceneIntro::~ModuleSceneIntro()
{ }
// Load assets
bool ModuleSceneIntro::start()
{
LOG("Loading Intro assets");
bool ret = true;
app->input->keyboard_enabled = true;
intro = app->textures->load("Images/IntroTuned2.png");
numbers = app->textures->load("Sprites/NumbersBlue.png");
press_space_to_start = app->textures->load("Images/PressSpaceToStartBlack.png");
app->audio->playMusic("Music/Intro.ogg", 0.0f);
fx = app->audio->loadFx("Sounds/Coin.ogg");
app->renderer->camera.x = app->renderer->camera.y = 0;
numbers_coins.current_frame = app->coins;
//DTM ANIMATION
ticks = 0;
seconds = 0;
rects[10] = { 0, 0, SCREEN_WIDTH * SCREEN_SIZE, SCREEN_HEIGHT * SCREEN_SIZE }; // full screen rect
for (unsigned int i = 0; i < 6; i++)
{
rects[i] = { 420 * SCREEN_SIZE, 76 * SCREEN_SIZE, 56 * SCREEN_SIZE, 56 * SCREEN_SIZE };
}
source_rects[0] = { 9, 3, 74, 75 };
source_rects[1] = { 92, 27, 70, 75 };
source_rects[2] = { 153, 3, 74, 75 };
source_rects[3] = { 227, 3, 87, 75 };
source_rects[4] = { 314, 3, 82, 75 };
source_rects[5] = { 396, 3, 65, 75 };
//rects[0] = { 0, 0, 0, 0 }; //
title = app->textures->load("Images/RtypeLogo.png");
return ret;
}
// Delete assets
bool ModuleSceneIntro::cleanUp()
{
LOG("Unloading Intro scene");
app->textures->unload(intro);
app->textures->unload(numbers);
app->textures->unload(press_space_to_start);
app->textures->unload(title);
return true;
}
// Update: draw background
update_status ModuleSceneIntro::update()
{
// start animation
if (ticks < 216) //420)
{
if (ticks < 80) // move letters to the left
{
for (unsigned int i = 7; i > 0; i--)
{
rects[i - 1].x -= 5 * SCREEN_SIZE;
SDL_RenderCopy(app->renderer->renderer, title, &source_rects[i - 1], &rects[i - 1]);
}
}
else if (ticks < 100) // small pause
{
for (unsigned int i = 7; i > 0; i--)
{
SDL_RenderCopy(app->renderer->renderer, title, &source_rects[i - 1], &rects[i - 1]);
}
}
else if (ticks < 156) // move letters to the right
{
for (unsigned int i = 7; i > 0; i--)
{
rects[i - 1].x += (i - 1) * SCREEN_SIZE;
SDL_RenderCopy(app->renderer->renderer, title, &source_rects[i - 1], &rects[i - 1]);
}
}
else if (ticks < 216) // move letters to the right
{
for (unsigned int i = 7; i > 0; i--)
{
rects[i - 1].y += SCREEN_SIZE;
SDL_RenderCopy(app->renderer->renderer, title, &source_rects[i - 1], &rects[i - 1]);
}
}
// update ticks counter
ticks++;
}
else
{
// Draw everything
app->renderer->blit(intro, 0 * SCALE_FACTOR, 0 * SCALE_FACTOR, NULL);
if (app->coins > 0)
app->renderer->blit(press_space_to_start, 200 * SCALE_FACTOR, 97 * SCALE_FACTOR, &(press_space_glow.getCurrentFrame()));
// Coins visualization
unsigned int units = app->coins % 10;
numbers_coins.current_frame = units;
app->renderer->blit(numbers, 348 * SCALE_FACTOR, 113 * SCALE_FACTOR, &(numbers_coins.getCurrentFrame()));
unsigned int tens = (app->coins / 10) % 10;
numbers_coins.current_frame = tens;
app->renderer->blit(numbers, 340 * SCALE_FACTOR, 113 * SCALE_FACTOR, &(numbers_coins.getCurrentFrame()));
if (app->input->keyboard_enabled == true)
{
if (app->input->getKey(SDL_SCANCODE_SPACE) == KEY_UP && app->coins > 0)
{
app->input->keyboard_enabled = false;
app->coins--;
app->fade->fadeToBlack(this, app->scene, 3.0f);
}
if (app->input->getKey(SDL_SCANCODE_C) == KEY_UP && app->coins < 99)
{
app->audio->playFx(fx);
app->coins++;
numbers_coins.current_frame = app->coins;
}
}
}
return UPDATE_CONTINUE;
}