-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleDeath.cpp
More file actions
166 lines (139 loc) · 3.52 KB
/
Copy pathModuleDeath.cpp
File metadata and controls
166 lines (139 loc) · 3.52 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
#define _CRT_SECURE_NO_WARNINGS
#include "Globals.h"
#include <iostream>
#include <fstream>
#include "Application.h"
#include "ModuleRender.h"
#include "ModuleDeath.h"
#include "ModuleInput.h"
#include "ModuleTextures.h"
#include "ModuleAudio.h"
#include "ModulePhysics.h"
#include "ModuleFadeToBlack.h"
#include "ModuleFonts.h"
#include "ModuleScene.h"
ModuleDeath::ModuleDeath(Application* app, bool start_enabled) : Module(app, start_enabled)
{
// Initialise all the internal class variables, at least to NULL pointer
//ranking.
}
ModuleDeath::~ModuleDeath()
{
// You should do some memory cleaning here, if required
}
bool ModuleDeath::Start()
{
LOG("Loading Death assets");
bool ret = true;
// Set camera position
App->renderer->camera.x = App->renderer->camera.y = 0;
// Load textures
img = App->textures->Load("pinball/title1.png");
const char fontText[] = "ABCDEFGHIJKLNOPQRSTUVXYZ0123456789:!? ";
score = App->scene_intro->currentScore;
OutFileRank(ranking);
//SwapRank(ranking);
AddScore(ranking, score);
return ret;
}
bool ModuleDeath::CleanUp()
{
LOG("Unloading Death scene");
App->textures->Unload(img);
InFileRank(ranking);
return true;
}
update_status ModuleDeath::Update()
{
//App->renderer->Blit(img, 0, 0);
App->fonts->BlitText(422, 75, App->fonts->white, "RANKING");
char scoreFont[10] = { "\0" };
for (int i = 0; i < 5; i++) {
if (ranking[i].name == "YOU") {
App->fonts->BlitText(310, 150 * (i + 1), App->fonts->yellow, ranking[i].name.c_str());
sprintf_s(scoreFont, 10, "%7d", ranking[i].score);
App->fonts->BlitText(520, 150 * (i + 1), App->fonts->yellow, scoreFont);
}
else {
App->fonts->BlitText(310, 150 * (i + 1), App->fonts->white, ranking[i].name.c_str());
sprintf_s(scoreFont, 10, "%7d", ranking[i].score);
App->fonts->BlitText(520, 150 * (i + 1), App->fonts->white, scoreFont);
}
}
// If user presses SPACE, enable RayCast
if (App->input->GetKey(SDL_SCANCODE_SPACE) == KEY_DOWN)
{
App->fade->FadeBlack(this, (Module*)App->scene_intro, 90);
}
if (App->input->GetKey(SDL_SCANCODE_R) == KEY_DOWN)
{
ResetRank(ranking);
}
// Keep playing
return UPDATE_CONTINUE;
}
void ModuleDeath::AddScore(Scores l[], int score) {
if (l[4].score <= score) {
l[4].name = "YOU";
l[4].score = score;
}
SwapRank(l);
}
void ModuleDeath::SwapRank(Scores l[]) {
int temp_score;
string temp_name;
for (int i = 0; i < 4; i++) {
if (l[i].score< l[i+1].score) {
//Swap scores
temp_score = l[i].score;
l[i].score = l[i + 1].score;
l[i + 1].score = temp_score;
//Swap names
temp_name = l[i].name;
l[i].name = l[i + 1].name;
l[i + 1].name = temp_name;
i = -1;
}
else {
continue;
}
}
}
void ModuleDeath::InFileRank(Scores l[]) {
//Copy the highscore to appear on scene_intro
App->scene_intro->highScore = l[0].score;
// Ranking text
ofstream myfile;
myfile.open("RANKING.txt");
for (int i = 0; i < 5; i++) {
myfile << l[i].name << "\n";
}
for (int i = 0; i < 5; i++) {
myfile << l[i].score << "\n";
}
myfile.close();
}
void ModuleDeath::OutFileRank(Scores l[]) {
ifstream myfile;
myfile.open("RANKING.txt");
string line;
int i = 0;
string a[10];
while (getline(myfile, line)) {
a[i] = line;
i++;
}
for (int j = 0; j < 5; j++) {
//l[j].name = (a[j]);
l[j].score = (int)atoi(a[j+5].c_str());
l[j].name = a[j];
}
myfile.close();
}
void ModuleDeath::ResetRank(Scores l[]) {
ranking[0] = { "XAVI", 1000 };
ranking[1] = { "HECTOR", 990 };
ranking[2] = { "JULS", 690 };
ranking[3] = { "JAN", 420 };
ranking[4] = { "YOU", 0 };
}