-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCImage.h
515 lines (408 loc) · 13.1 KB
/
CImage.h
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
#ifndef CIMAGE_H
#define CIMAGE_H
#include "math.h"
#include "string.h"
#include "texture.h"
#include "CImage.h"
#include "Vec2F.h"
#include "SDL_HelperTypes.h"
#include "Common.h"
#include "Vec2F.h"
#include "SDL_HelperTypes.h"
struct CTexture {
Texture* Img;
int[100] BaseFilename;
};
#define GFX_Max 40
int CImage_ImageSlotsUsed = 0;
CTexture*[GFX_Max] CImage_Images;
bool CImage_ImgEnabled = false;
Texture* getTextureFromName(int* Name)
{
if (strcmp(Name, "fasterdave/background.png") == 0)
{
return newTextureHorz(0, 0, 1, 0, 0, 640, 360, 1.0,1.0);
}
if (strcmp(Name, "fasterdave/ladder.png") == 0)
{
return newTextureHorz(0, 1, 1, 960, 944, 64, 80, 1.0,1.0);
}
if (strcmp(Name, "fasterdave/key.png") == 0)
{
return newTextureHorz(0, 2, 1, 967, 0, 29, 14, 1.0,1.0);
}
if (strcmp(Name, "fasterdave/floortileset.png") == 0)
{
return newTextureHorzVert(0, 10, 9,10, 0, 360, 576, 640, 1.0,1.0);
}
if (strcmp(Name, "fasterdave/Character_character_climb.png") == 0)
{
return newTextureVert(0, 100, 15, 693, 0, 27, 525, 1.0,1.0);
}
if (strcmp(Name, "fasterdave/Character_character_run.png") == 0)
{
return newTextureVert(0, 150, 7, 640, 0, 27, 259, 1.0,1.0);
}
if (strcmp(Name, "fasterdave/Character_character_idle.png") == 0)
{
return newTextureVert(0, 160, 15, 720, 0, 25, 525, 1.0,1.0);
}
if (strcmp(Name, "fasterdave/Character_character_jump_up.png") == 0)
{
return newTextureVert(0, 180, 6, 667, 0, 26, 210, 1.0,1.0);
}
if (strcmp(Name, "fasterdave/enemy.png") == 0)
{
return newTextureHorzVert(0, 200, 3, 4, 745, 0, 96, 128, 1.0,1.0);
}
if (strcmp(Name, "fasterdave/orbs.png") == 0)
{
return newTextureVert(0, 250, 5, 841, 0, 128, 640, 1.0,1.0);
}
if (strcmp(Name, "blockstacker/background.png") == 0)
{
return newTextureHorz(1, 0, 1, 0, 0, 640, 360, 1.0,1.0);
}
if (strcmp(Name, "breakout/background.png") == 0)
{
return newTextureHorz(2, 0, 1, 0, 0, 640, 360, 1.0,1.0);
}
if (strcmp(Name, "breakout/paddle.png") == 0)
{
return newTextureHorz(2, 1, 1, 992, 1016, 32, 8, 1.0,1.0);
}
if (strcmp(Name, "breakout/ball.png") == 0)
{
return newTextureHorz(2, 2, 1, 1012, 0, 16, 16, 1.0,1.0);
}
if (strcmp(Name, "breakout/blocks.png") == 0)
{
return newTextureHorz(2, 3, 6, 0, 1008, 384, 16, 1.0,1.0);
}
if (strcmp(Name, "frog/background.png") == 0)
{
return newTextureHorz(3, 0, 1, 0, 0, 640, 360, 1.0,1.0);
}
if (strcmp(Name, "frog/player.png") == 0)
{
return newTextureHorzVert(3, 1, 3, 4, 701, 24, 96, 128, 1.0,1.0);
}
if (strcmp(Name, "frog/watergrass.png") == 0)
{
return newTextureHorzVert(3, 20, 6, 3, 866, 34, 96, 48, 1.0,1.0);
}
if (strcmp(Name, "frog/carblue.png") == 0)
{
return newTextureHorz(3, 50, 2, 56, 572, 78, 29, 1.0,1.0);
}
if (strcmp(Name, "frog/garbagetruck.png") == 0)
{
return newTextureHorz(3, 55, 2, 53, 638, 66, 29, 1.0,1.0);
}
if (strcmp(Name, "frog/ambulance.png") == 0)
{
return newTextureHorz(3, 60, 2, 71, 509, 66, 29, 1.0,1.0);
}
if (strcmp(Name, "frog/taxi.png") == 0)
{
return newTextureHorz(3, 65, 2, 44, 794, 78, 29, 1.0,1.0);
}
if (strcmp(Name, "frog/police.png") == 0)
{
return newTextureHorz(3, 70, 2, 46, 722, 74, 29, 1.0,1.0);
}
if (strcmp(Name, "frog/waterplant.png") == 0)
{
return newTextureHorz(3, 75, 2, 727, 275, 32, 16, 1.0,1.0);
}
if (strcmp(Name, "frog/apple.png") == 0)
{
return newTextureHorz(3, 80, 1, 723, 206, 16, 16, 1.0,1.0);
}
if (strcmp(Name, "frog/lemon.png") == 0)
{
return newTextureHorz(3, 85, 1, 792, 206, 16, 16, 1.0,1.0);
}
if (strcmp(Name, "frog/cherry.png") == 0)
{
return newTextureHorz(3, 90, 1, 759, 206, 16, 16, 1.0,1.0);
}
if (strcmp(Name, "invaders/background.png") == 0)
{
return newTextureHorz(4, 0, 1, 0, 0, 640, 360, 1.0,1.0);
}
if (strcmp(Name, "invaders/bullet.png") == 0)
{
return newTextureHorz(4, 5, 2, 751, 80, 32, 10, 1.0,1.0);
}
if (strcmp(Name, "invaders/explosion.png") == 0)
{
return newTextureHorz(4, 10, 7, 67, 771, 560, 80, 1.0,1.0);
}
if (strcmp(Name, "invaders/asteroid-01.png") == 0)
{
return newTextureHorz(4, 20, 1, 748, 210, 67, 63, 1.0,1.0);
}
if (strcmp(Name, "invaders/enemy1.png") == 0)
{
return newTextureHorz(4, 25, 5, 29, 376, 240, 48, 1.0,1.0);
}
if (strcmp(Name, "invaders/enemy2.png") == 0)
{
return newTextureHorz(4, 35, 4, 41, 445, 192, 48, 1.0,1.0);
}
if (strcmp(Name, "invaders/enemy3.png") == 0)
{
return newTextureHorz(4, 40, 4, 41, 517, 192, 48, 1.0,1.0);
}
if (strcmp(Name, "invaders/player.png") == 0)
{
return newTextureHorz(4, 45, 5, 203, 646, 240, 48, 1.0,1.0);
}
if (strcmp(Name, "pang/background.png") == 0)
{
return newTextureHorz(5, 0, 1, 0, 0, 640, 360, 1.0,1.0);
}
if (strcmp(Name, "pang/backgroundsub.png") == 0)
{
return newTextureHorz(5, 3, 1, 0, 345, 640, 15, 1.0,1.0);
}
if (strcmp(Name, "pang/character.png") == 0)
{
return newTextureHorzVert(5, 5, 12, 8, 23, 364, 624, 576, 1.0,1.0);
}
if (strcmp(Name, "pang/weapon.png") == 0)
{
return newTextureVert(5, 50, 2, 34, 953, 800, 66, 1.0,1.0);
}
if (strcmp(Name, "pang/ball.png") == 0)
{
return newTextureHorz(5, 55, 1, 789, 174, 45, 45, 1.0,1.0);
}
if (strcmp(Name, "main/frame.png") == 0)
{
return newTextureHorz(6, 0, 1, 0, 0, 512, 102, 1.0,1.0);
}
if (strcmp(Name, "main/outerframe.png") == 0)
{
return newTextureHorz(6, 1, 1, 0, 922, 512, 102, 1.0,1.0);
}
if (strcmp(Name, "main/medal.png") == 0)
{
return newTextureHorz(6, 2, 1, 513, 0, 77, 122, 1.0,1.0);
}
if (strcmp(Name, "gamepreview/gamepreview.png") == 0)
{
return newTextureHorzVert(7, 0, 3, 3, 0, 0, 160*3, 90*3, 1.0,1.0);
}
if (strcmp(Name, "gamepreview/gamepreview2.png") == 0)
{
return newTextureHorzVert(7, 20, 3, 3, 0, 484, 320*3, 180*3, 1.0,1.0);
}
if (strcmp(Name, "ramit/background.png") == 0)
{
return newTextureHorz(8, 0, 1, 0, 0, 640, 360, 1.0,1.0);
}
if (strcmp(Name, "snakey/background.png") == 0)
{
return newTextureHorz(9, 0, 1, 0, 0, 640, 360, 1.0,1.0);
}
return NULL;
}
void CImage_Init()
{
CImage_ImgEnabled = true;
CImage_ImageSlotsUsed = 0;
for (int i=0; i < GFX_Max; i++)
CImage_Images[i] = NULL;
}
int CImage_LoadImage(int* FileName)
{
int result = -1;
if(CImage_ImgEnabled)
for (int i=0; i < GFX_Max; i++)
{
if(CImage_Images[i] == NULL)
{
Texture *Img = getTextureFromName(FileName);
if(Img)
{
CImage_ImageSlotsUsed++;
CImage_Images[i] = (CTexture*) malloc(sizeof(CTexture));
strcpy(CImage_Images[i]->BaseFilename, FileName);
CImage_Images[i]->Img = Img;
result = i;
break;
}
}
}
return result;
}
void CImage_UnLoadImage(int GFXID)
{
if(!CImage_ImgEnabled)
return;
if ((GFXID < 0) || (GFXID >= GFX_Max))
return;
if (CImage_Images[GFXID] != NULL)
{
freeTexture(CImage_Images[GFXID]->Img);
free(CImage_Images[GFXID]);
CImage_Images[GFXID] = NULL;
CImage_ImageSlotsUsed--;
}
}
void CImage_UnloadImages()
{
for (int i=0; i < GFX_Max; i++)
CImage_UnLoadImage(i);
}
SDL_Point* CImage_ImageSizeTex(Texture *Texture)
{
SDL_Point *Result = (SDL_Point*) malloc(sizeof(SDL_Point));
Result->x = -1;
Result->y = -1;
if(!CImage_ImgEnabled)
return Result;
if(Texture == NULL)
return Result;
Result->x = Texture->width;
Result->y = Texture->height;
return Result;
}
SDL_Point* CImage_ImageSize(int GFXID)
{
SDL_Point *Result = (SDL_Point*) malloc(sizeof(SDL_Point));
Result->x = -1;
Result->y = -1;
if((GFXID < 0) || (GFXID >= GFX_Max))
return Result;
free(Result);
return CImage_ImageSizeTex(CImage_Images[GFXID]->Img);
}
void CImage_DrawImageTex(Texture *aTexture,int AnimTile, SDL_Rect* Src, SDL_Rect* Dst)
{
if(!CImage_ImgEnabled)
return;
if(aTexture == NULL)
return;
int texw = aTexture->width;
int texh = aTexture->height;
if ((Src == NULL) && (Dst == NULL))
{
drawTextureZoomed(aTexture, AnimTile, ScreenWidth / 2, ScreenHeight / 2, (float)ScreenWidth / texw, (float)ScreenHeight / texh);
}
else
{
if ((Src != NULL) && (Dst == NULL))
{
drawTextureZoomed(aTexture,AnimTile,ScreenWidth / 2 , ScreenHeight / 2, (float)ScreenWidth / Src->w, (float)ScreenHeight / Src->h);
}
else
{
if ((Src == NULL) && (Dst != NULL))
{
drawTextureZoomed(aTexture,AnimTile, Dst->x + texw /2, Dst->y + texh / 2, (float)Dst->w / texw, (float)Dst->h / texh);
}
else
{
drawTextureZoomed(aTexture,AnimTile, Dst->x + Src->w/2, Dst->y + Src->h / 2, (float)Dst->w / Src->w, (float)Dst->h / Src->h);
}
}
}
}
void CImage_DrawImage(int GFXID, int AnimTile, SDL_Rect* Src, SDL_Rect* Dst)
{
if((GFXID < 0) || (GFXID >= GFX_Max))
return;
CImage_DrawImageTex(CImage_Images[GFXID]->Img, AnimTile, Src, Dst);
}
//fuze used center points for positions and a floating point scale vector
void CImage_DrawImageFuzeTex(Texture *aTexture, int AnimTile, bool CenterImagePos, int Posx, int Posy, float Angle, float Scalex, float Scaley,int TintR, int TintG, int TintB, int Alpha)
{
if(!CImage_ImgEnabled)
return;
if(aTexture == NULL)
return;
SDL_Rect Dst;
if(!CenterImagePos)
{
Dst.x = (int)(Posx + ((aTexture->width / aTexture->framesHorz * Scalex) / 2));
Dst.y = (int)(Posy + ((aTexture->height / aTexture->framesVert * Scaley) / 2));
}
else
{
Dst.x = Posx;
Dst.y = Posy;
}
//Draw
bool needRotation = ((fabs(Angle) >= epsilion) || (fabs(Angle) <= -epsilion));
bool needScale = ((fabs(Scalex) <= 1.0 - epsilion) || (fabs(Scalex) >= 1.0 + epsilion) || (fabs(Scaley) <= 1.0 - epsilion) || (fabs(Scaley)>= 1.0 + epsilion));
set_multiply_color(make_color_rgba(TintR, TintG, TintB, Alpha));
if(needRotation && needScale)
drawTextureRotatedZoomed(aTexture,AnimTile, Dst.x, Dst.y, Scalex, Scaley, Angle);
else
{
if(needScale)
{
drawTextureZoomed(aTexture,AnimTile, Dst.x, Dst.y, Scalex, Scaley);
}
else
{
if(needRotation)
{
drawTextureRotated(aTexture,AnimTile, Dst.x, Dst.y, Angle);
}
else
{
drawTexture(aTexture, AnimTile, Dst.x, Dst.y);
}
}
}
set_multiply_color(make_color_rgba(255, 255, 255, 255));
}
//fuze used center points for positions and a floating point scale vector
void CImage_DrawImageFuzeSrcRectTintFloat(int GFXID, int AnimTile, bool CenterImagePos, int Posx, int Posy, float Angle, float Scalex, float Scaley, float TintR, float TintG, float TintB, float Alpha)
{
if((GFXID < 0) || (GFXID >= GFX_Max))
return;
CImage_DrawImageFuzeTex(CImage_Images[GFXID]->Img,AnimTile, CenterImagePos, Posx, Posy, Angle, Scalex, Scaley, (int)floor(255.0 * TintR) , (int)floor(255.0 * TintG), (int)floor(255.0 * TintB) , (int)floor(255.0 * Alpha));
}
void CImage_DrawImageFuzeSrcRectTintFloatTex(Texture* Texture, int AnimTile, bool CenterImagePos, int Posx, int Posy, float Angle, float Scalex, float Scaley,float TintR, float TintG, float TintB, float Alpha)
{
if(Texture == NULL)
return;
CImage_DrawImageFuzeTex(Texture, AnimTile, CenterImagePos, Posx, Posy, Angle, Scalex, Scaley, (int)floor(255.0 * TintR) , (int)floor(255.0 * TintG), (int)floor(255.0 * TintB) , (int)floor(255.0 * Alpha));
}
//fuze used center points for positions and a floating point scale vector
void CImage_DrawImageFuzeTintFloat(int GFXID, int AnimTile, bool CenterImagePos, int Posx, int Posy, float Angle, float Scalex, float Scaley,float TintR, float TintG, float TintB, float Alpha)
{
if((GFXID < 0) || (GFXID >= GFX_Max))
return;
CImage_DrawImageFuzeTex(CImage_Images[GFXID]->Img, AnimTile, CenterImagePos, Posx, Posy, Angle, Scalex, Scaley, (int)floor(255.0 * TintR) , (int)floor(255.0 * TintG), (int)floor(255.0 * TintB) , (int)floor(255.0 * Alpha));
}
void CImage_DrawImageFuzeTintFloatTex(Texture *Texture, int AnimTile, bool CenterImagePos, int Posx, int Posy, float Angle, float Scalex, float Scaley,float TintR, float TintG, float TintB, float Alpha)
{
if(Texture == NULL)
return;
CImage_DrawImageFuzeTex(Texture, AnimTile, CenterImagePos, Posx, Posy, Angle, Scalex, Scaley, (int)floor(255.0 * TintR) , (int)floor(255.0 * TintG), (int)floor(255.0 * TintB) , (int)floor(255.0 * Alpha));
}
void CImage_DrawImageFuze(int GFXID,int AnimTile, bool CenterImagePos, int Posx, int Posy, float Angle, float Scalex, float Scaley,float TintR, float TintG, float TintB, float Alpha)
{
if((GFXID < 0) || (GFXID >= GFX_Max))
return;
CImage_DrawImageFuzeTex(CImage_Images[GFXID]->Img,AnimTile, CenterImagePos, Posx, Posy, Angle, Scalex, Scaley, (int)floor(255.0 * TintR) , (int)floor(255.0 * TintG), (int)floor(255.0 * TintB) , (int)floor(255.0 * Alpha));
}
Texture* CImage_GetImage(int GFXID)
{
if((GFXID < 0) || (GFXID >= GFX_Max))
return NULL;
if (CImage_Images[GFXID] == NULL)
return NULL;
return CImage_Images[GFXID]->Img;
}
void CImage_DeInit()
{
CImage_UnloadImages();
}
#endif