-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModuleContinue.cpp
More file actions
265 lines (208 loc) · 6.27 KB
/
ModuleContinue.cpp
File metadata and controls
265 lines (208 loc) · 6.27 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#include "Globals.h"
#include "Application.h"
#include "ModuleTextures.h"
#include "ModuleRender.h"
#include "ModuleGameOver.h"
#include "ModuleContinue.h"
#include "ModuleFadeToBlack.h"
#include "ModuleAudio.h"
#include "ModuleUI.h"
#include "ModulePlayer.h"
#include "ModulePlayer2.h"
#include "ModulePlayerUnit.h"
//#include "ModulePlayer2Unit.h"
#include "SDL/include/SDL_timer.h"
#include "SDL\include\SDL_render.h"
#define MAX_FRAMES 8 // animations and sprite sheet limits
#define FIRE_FRAMES 14
#define NUMBERS 10
#define MAX_ALPHA 255.0f
#define MIN_ALPHA 0.0f
ModuleContinue::ModuleContinue()
{
//background image
backgroundRect = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT };
//continue letters
continueRect = { 0, 64, 240, 32 };
//fire anim
for (int i = 0; i < MAX_FRAMES; i++)
{
for (int j = 0; j < FIRE_FRAMES; j++)
{
if (j < MAX_FRAMES)
fireAnim[i].PushBack({ 32 * j, 96, 32, 32 });
else
fireAnim[i].PushBack({ 32 * (j - MAX_FRAMES), 128, 32, 32 });
}
fireAnim[i].speed = 0.25f;
}
//numbers
for (int i = 0; i < NUMBERS; i++)
{
if (i < MAX_FRAMES)
numbersAnim.PushBack({ 32 * i, 0, 32, 32 });
else
numbersAnim.PushBack({ 32 * (i - MAX_FRAMES), 32, 32, 32 });
}
}
ModuleContinue::~ModuleContinue()
{ }
bool ModuleContinue::Start()
{
LOG("-------- Loading continue scene");
//SDL_SetRenderDrawBlendMode(App->render->renderer, SDL_BLENDMODE_ADD);
//disable
/*if (App->player->IsEnabled())
App->player->Disable();
if (App->player2->IsEnabled())
App->player2->Disable();
if (App->playerUnit->IsEnabled())
App->playerUnit->Disable();
if (App->player2Unit->IsEnabled())
App->player2Unit->Disable();*/
//alpha
//number = 9;
cycle = true;
normalized = 2.5f;
alpha = 255.0f;
//graphics
backgroundTexture = App->textures->Load("assets/Graphics/Screens/Continue/Backgrounds.png");
continueTexture = App->textures->Load("assets/Graphics/Screens/Continue/Anims.png");
//audio
App->audio->LoadAudio("assets/Audio/Music/Continue.ogg", "continueSong", MUSIC);
App->audio->ControlAudio("continueSong", MUSIC, PLAY);
App->audio->LoadAudio("assets/Audio/SFX/Screens/Continue_Countdown.wav", "Countdown", SFX);
start_time = SDL_GetTicks(); //next letter counter
next = 0;
timeBetweenFrames = 10; //in ms
row = 0;
nextPrint = true;
nextNumber = 9;
return true;
}
update_status ModuleContinue::Update()
{
if (App->input->keyboard[SDL_SCANCODE_RETURN] == 1)
{
//App->player[0]->lives--;
App->player[0]->lives = 3;
App->player[1]->lives = 3;
App->fade->FadeToBlack(this, (Module*)App->readyScreen, 0.8f);
App->moduleUI->coins--;
}
// background blink anim
if (cycle)
{
alpha = alpha - normalized;
if (alpha == MIN_ALPHA)
cycle = false;
SDL_SetTextureAlphaMod(backgroundTexture, alpha);
App->render->Blit(backgroundTexture, 0, 0, &backgroundRect);
}
else
{
alpha = alpha + normalized;
if (alpha == MAX_ALPHA)
cycle = true;
SDL_SetTextureAlphaMod(backgroundTexture, alpha);
App->render->Blit(backgroundTexture, 0, 0, &backgroundRect);
}
//fire anim
/*for (int i = 0; i <= MAX_FRAMES; i++)
{
if (!fireAnim[i].finish)
{
App->render->Blit(continueTexture, 21 + 32 * i, 96, &fireAnim[i].GetCurrentFrame());
}
else
{
App->render->Blit(continueTexture, 253, 96, &fireAnim[i].GetCurrentFrame());
}
}*/
//index of fireAnims current frame incrementer
int incrementOrder[20][4][6] = //here for testing //row,next,i
{
{ {0}, {-1}, {7}, {1,2,3,4,5,6} }, //-1 indicates its prints nothing,no frame increment
{ {0}, {1}, {7}, {2,3,4,5,6} },
{ {0}, {1}, {2,7}, {3,4,5,6} },
{ {0}, {1}, {2,7}, {3,4,5,6} },
{ {0}, {1}, {2,7}, {3,4,5,6} },
{ {0,4}, {1}, {2,7}, {3,5,6} },
{ {0,4}, {1,5}, {2,7}, {3,6} },
{ { 0,4 },{ 1,5 },{ 2,6,7 },{ 3 } },
{ { 0,4 },{ 1,5 },{ 2,6,7 },{ 3 } },
{ { 0,4 },{ 1,5 },{ 2,6,7 },{ 3 } },
{ { 0,4 },{ 1,5 },{ 2,6,7 },{ 3 } },
{ { 0,4 },{ 1,5 },{ 2,6,7 },{ 3 } },
{ { 0,4 },{ 1,5 },{ 2,6,7 },{ 3 } },
//this is not really tested, step frame is needed in shot factory
{ { 0,4 },{ 1,5 },{ 2,6,7 },{ 3 } },
{ { 0,4 },{ 1,5 },{ 2,6,7 },{ 3 } },
{ { 0,4 },{ 1,5 },{ 2,6,7 },{ 3 } },
{ { 0,4 },{ 1,5 },{ 2,6,7 },{ 3 } },
{ { 0,4 },{ 1,5 },{ 2,6,7 },{ 3 } },
{ { 0,4 },{ 1,5 },{ 2,6,7 },{ 3 } },
//and fires progressive disappears //not completed yet
};
//increments by time
now = SDL_GetTicks() - start_time;
if (now >= timeBetweenFrames && row < 19)
{
next++;
start_time = SDL_GetTicks();
if (next > 3) //cycles of 4 frames
{
row++;
next = 0;
}
nextPrint = true;
}
Animation* current_animation;
SDL_Rect fireFrame;
//prints the frames always (current frame)
for (int i = 0; i < 8; ++i)
{
current_animation = &fireAnim[i];
fireFrame = current_animation->frames[(int)current_animation->current_frame];
App->render->Blit(continueTexture, firePositions[i], 96, &fireFrame);
}
//still not really fine, but seems to be a good way
if (nextPrint)
{
for (int i = 0; i < 7; ++i) //this works fine, show the correct positions and frames
{ //but we need increment the frames too, only one time per index
current_animation = &fireAnim[incrementOrder[row][next][i]];
if (incrementOrder[row][next][i] == 0 && i != 0) //if index is the first frame, ignore, if not, break
{ //for initials conditions on index 0, we need it first
nextPrint = false;
break;
}
current_animation->current_frame += 1.0f;
}
}
if (row >= 19) //loops forever
{
App->audio->ControlAudio("Countdown", SFX, PLAY);
row = 0, next = 0; // nextPrint = true;
nextNumber--;
for (int i = 0; i < 8; ++i) fireAnim[i].current_frame = 0;
};
// continue rect
App->render->Blit(continueTexture, 16, 96, &continueRect);
// numbers anim
App->render->Blit(continueTexture, 256, 96, &numbersAnim.frames[nextNumber]);
if (nextNumber <= 0)
App->fade->FadeToBlack(App->continueScreen, App->gameOverScreen, 0.8f);
return UPDATE_CONTINUE;
}
bool ModuleContinue::CleanUp()
{
LOG("Unloading continue scene assets");
App->textures->Unload(backgroundTexture);
App->textures->Unload(continueTexture);
App->audio->UnloadAudio("continueSong", MUSIC);
App->audio->UnloadAudio("Countdown", SFX);
//resets all fireframes positions
for (int i = 0; i < 8; ++i) fireAnim[i].current_frame = 0;
return true;
}