-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameStruct.cpp
296 lines (221 loc) · 6.52 KB
/
gameStruct.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
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/***************************************************************************
** gameStruct é utilizada para todas as estruturas/classes relacionadas **
** ao Player, Inimigos, Objetos(?) e por aí vai **
** Criado por Lucas P. Stark **
** Nightmare Fiction Engine - NFE **
***************************************************************************/
#include "gameStruct.h"
entity::entity() {
modelNum = 0;
animSection = 0;
animCount = 0;
animOldSection = 0;
animOldCount = 0;
animType = 0;
animRepeat = true;
state = 0;
tmrAnim = 0;
}
entity::~entity() {
modelNum = 0;
animSection = 0;
animCount = 0;
animOldSection = 0;
animOldCount = 0;
animType = 0;
animRepeat = true;
state = 0;
tmrAnim = 0;
}
void entity::setModel(unsigned int modelNum) {
this->modelNum = modelNum;
}
void entity::setTmrAnim(unsigned int tmrAnim) {
this->tmrAnim = tmrAnim;
}
void entity::setAnimSection(unsigned int animSection) {
this->animSection = animSection;
}
void entity::setAnimType(unsigned int animType, bool animRepeat) {
this->animType = animType;
this->animRepeat = animRepeat;
this->animCount = 0;
}
void entity::setAnimCount(unsigned int animCount) {
this->animCount = animCount;
}
void entity::setAnimFrame(EMD_SEC2_DATA_T animFrame) {
this->animFrame = animFrame;
}
void entity::setAnimRotationDir(unsigned int animRotationDir) {
this->animRotationDir = animRotationDir;
}
void entity::setX(float x) {
this->x = x;
}
void entity::setY(float y) {
this->y = y;
}
void entity::setZ(float z) {
this->z = z;
}
void entity::setAngle(float angle) {
this->angle = angle;
}
void entity::setState(unsigned int state) {
this->state = state;
}
void entity::setHitPoints(unsigned int hitPoints) {
this->hitPoints = hitPoints;
}
unsigned int entity::getModel() { return modelNum; }
unsigned int entity::getTmrAnim() { return tmrAnim; }
unsigned int entity::getState() { return state; }
unsigned int entity::getHitPoints() { return hitPoints; }
unsigned int entity::getAnimSection() { return animSection; }
unsigned int entity::getAnimType() { return animType; }
unsigned int entity::getAnimCount() { return animCount; }
unsigned int entity::getAnimOldSection() { return animOldSection; }
unsigned int entity::getAnimOldCount() { return animOldCount; }
unsigned char entity::getAnimRotationDir() { return animRotationDir; }
EMD_SEC2_DATA_T entity::getAnimFrame() { return animFrame; }
bool entity::getAnimRepeat() { return animRepeat; }
float entity::getX() { return x; }
float entity::getY() { return y; }
float entity::getZ() { return z; }
float entity::getAngle() { return angle; }
enemy::enemy() {
type = 0;
}
enemy::~enemy() {
type = 0;
}
void enemy::setType(unsigned int type) { this->type = type; }
void enemy::setDelta(float delta) { this->delta = delta; }
unsigned int enemy::getType() { return type; }
float enemy::getDelta() { return delta; }
player::player() {
for (int i = 0; i < 8; i++) {
iID[i] = 0x0;
}
}
player::~player() {
for (int i = 0; i < 8; i++) {
iID[i] = 0x0;
}
}
void player::setItemID(unsigned char slot, unsigned int iID) {
if (slot >= 8)
return;
this->iID[slot] = iID;
}
void player::setCam(unsigned int cam) { this->cam = cam; }
unsigned int player::getItemID(unsigned char slot) {
if (slot >= 8)
return -1;
return iID[slot];
}
unsigned int player::getCam() { return cam; }
BITMAP::BITMAP() {
memset(bmpHeader, 0x0, 54);
bmpBuffer = NULL;
}
BITMAP::~BITMAP() {
delete [] bmpBuffer;
bmpBuffer = NULL;
}
void BITMAP::loaderFile(std::string fileName, int type) {
FILE *bmpFile = NULL;
bmpFile = fopen(fileName.c_str(), "rb");
if (bmpBuffer != NULL) {
delete [] bmpBuffer;
bmpBuffer = NULL;
}
if (bmpFile == NULL) {
std::cout << "File " << bmpFile << " not found " << std::endl;
return;
}
if ( fread (bmpHeader, 1, 54, bmpFile) != 54) {
std::cout << "Error while loading bitmap, not bitmap file (?) " << std::endl;
return;
}
if ((bmpHeader[0] != 'B') || (bmpHeader[1] != 'M')) {
std::cout << "Arquivo nao é um bitmap !" << std::endl;
return;
}
bmpDataInit = *(int*)&(bmpHeader[0x0A]);
bmpSize = *(int*)&(bmpHeader[0x22]);
bmpWidth = *(int*)&(bmpHeader[0x12]);
bmpHeight = *(int*)&(bmpHeader[0x16]);
bpp = *(short*)&(bmpHeader[0x1C]);
if (type == 1) {
bmpBuffer = new unsigned char [bmpHeight * bmpWidth * 4];
unsigned char *buffer = new unsigned char[bmpSize];
fread(buffer, 1, bmpSize, bmpFile);
unsigned int j = 0;
for (unsigned int i = 0; i < bmpSize; i+=3, j+= 4) {
if ((buffer[i] == 0) && (buffer[i+1] == 0) && (buffer[i+2] == 0)) {
bmpBuffer[j] = 0;
bmpBuffer[j+1] = 0;
bmpBuffer[j+2] = 0;
bmpBuffer[j+3] = 0;
} else {
bmpBuffer[j] = buffer[i];
bmpBuffer[j+1] = buffer[i+1];
bmpBuffer[j+2] = buffer[i+2];
bmpBuffer[j+3] = 255;
}
}
} else {
switch (bpp) {
case BITMAP_TYPE_MONO:
std::cout << "Mono support not implemented" << std::endl;
break;
case BITMAP_TYPE_16COLOR:
std::cout << "16 color support not implemented" << std::endl;
break;
case BITMAP_TYPE_256COLOR:
std::cout << "256 color support not implemented" << std::endl;
break;
case BITMAP_TYPE_16BPP:
std::cout << "16 BPP color support not implemented" << std::endl;
break;
case BITMAP_TYPE_24BPP:
bmpBuffer = new unsigned char [bmpSize];
fread(bmpBuffer, 1, bmpSize, bmpFile);
break;
case BITMAP_TYPE_32BPP: {
bmpBuffer = new unsigned char [bmpSize];
fread(bmpBuffer, 1, bmpSize, bmpFile);
}
break;
default:
std::cout << "Something is wrong with BITMAP bpp" << std::endl;
break;
}
}
fclose (bmpFile);
}
/*
* NFP - Nightamre Fiction Picture
*/
NFP::NFP() {
texture = NULL;
}
NFP::~NFP() {
if (texture != NULL) {
SDL_FreeSurface(texture);
texture = NULL;
}
}
bool NFP::loadImage(std::string fileName) {
texture = IMG_Load( fileName.c_str() );
if (texture == NULL) {
std::cout << "Error while loading " << fileName << " texture" << std::endl;
return false;
}
return true;
}
void* NFP::getPixelData() { return texture->pixels; }
int NFP::getWidth() { return texture->w; }
int NFP::getHeight() { return texture->h; }