-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModuleStartScreen.cpp
147 lines (112 loc) · 3.31 KB
/
ModuleStartScreen.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
#include "ModuleStartScreen.h"
#include "Application.h"
#include "ModuleTextureManager.h"
#include "ModuleFadeToBlack.h"
#include "ModuleRenderer.h"
#include "ModuleInput.h"
#include "ModuleAudio.h"
#include "ModuleLevel1.h"
ModuleStartScreen::ModuleStartScreen(bool startEnabled) : Module(startEnabled) {
name = "Start S";
}
ModuleStartScreen::~ModuleStartScreen() {}
bool ModuleStartScreen::Start() {
bool ret = true;
// Unicorn Animation
unicorn_anim.PushBack({ 5,2,112,160 });
unicorn_anim.PushBack({ 122,2,120,160 });
unicorn_anim.PushBack({ 248,2,120,160 });
unicorn_anim.speed = 0.1f;
// title rect
title = { 235,165,236,67 };
// text rect
text = { 2,168,216,128 };
// selector rect
selector.PushBack({ 236,240,13,16 });
selector.PushBack({ 236,300,13,16 });
selector.speed = 0;
selector.Reset();
tex = App->textures->Load("Assets/sprites/menus/Menu-Spritesheet.png");
if (tex == nullptr) {
ret = false;
}
++activeTextures; ++totalTextures;
App->render->camera.x = 0;
App->render->camera.y = 0;
selectorPos = {68,116};
if (current_anim != &unicorn_anim) {
current_anim = &unicorn_anim;
unicorn_anim.Reset();
}
// Playing opening music
App->audio->PlayMusic("Assets/music/soundtrack/opening.ogg");
// Load choose option sound
chooseFx = App->audio->LoadFx("Assets/music/events/chooseoption.wav");
++activeFx; ++totalFx;
// Load start event sound
startFx = App->audio->LoadFx("Assets/music/events/start.wav");
++activeFx; ++totalFx;
return ret;
}
update_status ModuleStartScreen::Update(){
update_status ret = update_status::UPDATE_CONTINUE;
if ((App->input->keyboard[SDL_SCANCODE_W] == KEY_DOWN || App->input->keyboard[SDL_SCANCODE_UP] == KEY_DOWN || App->input->pads[0].up == true)
&& selectorPos.y != 116) {
selectorPos = { 68,116 };
App->audio->PlayFx(chooseFx, 0);
}
if ((App->input->keyboard[SDL_SCANCODE_S] == KEY_DOWN || App->input->keyboard[SDL_SCANCODE_DOWN] == KEY_DOWN || App->input->pads[0].down == true)
&& selectorPos.y != 135) {
selectorPos = { 68,135 };
App->audio->PlayFx(chooseFx, 0);
}
if ((App->input->keyboard[SDL_SCANCODE_RETURN] == KEY_DOWN || App->input->pads[0].a == true) && App->transition->hasEnded()) {
switch (selectorPos.y) {
case 116: {
selector.speed = 0.2;
App->audio->PlayFx(startFx, 0);
App->transition->FadeToBlack(this, (Module*)App->selector, 60);
} break;
case 135: {
} break;
default:
break;
}
}
return ret;
}
update_status ModuleStartScreen::PostUpdate() {
update_status ret = UPDATE_CONTINUE;
// Blit unicorn
if (!App->render->Blit(tex, 81, 50, &unicorn_anim.GetCurrentFrame(), 1, false)) {
ret = UPDATE_ERROR;
}
// Blit title
if (!App->render->Blit(tex, 11, 16, &title, 1, false)) {
ret = UPDATE_ERROR;
}
// Blit text
if (!App->render->Blit(tex, 24, 87, &text, 1, false)) {
ret = UPDATE_ERROR;
}
// Blit selector
if (!App->render->Blit(tex, selectorPos.x, selectorPos.y, &selector.GetCurrentFrame(), 1, false)) {
ret = UPDATE_ERROR;
}
return ret;
}
bool ModuleStartScreen::CleanUp() {
bool ret = true;
activeTextures = activeFx = 0;
if (!App->textures->Unload(tex)) {
LOG("Start Screen -> Error unloading the texture.");
ret = false;
}
--totalTextures;
App->audio->UnloadFx(chooseFx);
--totalFx;
App->audio->UnloadFx(startFx);
--totalFx;
App->audio->StopMusic();
return ret;
}