-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathres_mgr.h
More file actions
85 lines (64 loc) · 1.38 KB
/
res_mgr.h
File metadata and controls
85 lines (64 loc) · 1.38 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
#ifndef RESMGR
#define RESMGR
enum EResType
{
ERT_Begin = 0,
ERT_Alien = 0,
ERT_Explosion = 1,
ERT_Player = 2,
ERT_Shot = 3,
ERT_End = 4,
ERT_Num = 4,
};
struct RESARRAY
{
EResType eType;
const char* path;
} ResArray[] = {
{ ERT_Alien, "alien.gif" },
{ ERT_Explosion, "explosion.gif" },
{ ERT_Player, "player.gif" },
{ ERT_Shot, "shot.gif" },
};
class ResMgr
{
public:
bool Init()
{
for(int i=ERT_Begin; i<ERT_End; ++i)
_images[i] = 0;
for(int i=0; i<sizeof(ResArray)/sizeof(RESARRAY); ++i)
if( !LoadData(ResArray[i].eType, ResArray[i].path) ) return false;
return true;
}
void Destroy()
{
for(int i=ERT_Begin; i<ERT_End; ++i)
ReleaseData(i);
}
bool LoadData(int type_, const char* path_)
{
if( type_ < ERT_Begin || type_ >= ERT_End ) return false;
if( _images[type_] != 0 )
ReleaseData(type_);
_images[type_] = IMG_Load(path_);
if( 0 == _images[type_] ) return false;
SDL_SetColorKey(_images[type_], SDL_SRCCOLORKEY, *(Uint8 *)(_images[type_]->pixels));
return true;
}
void ReleaseData(int type_)
{
if( type_ < ERT_Begin || type_ >= ERT_End ) return;
if( 0 == _images[type_] ) return;
SDL_FreeSurface(_images[type_]);
_images[type_] = 0;
}
SDL_Surface* GetSurface(int type_)
{
if( type_ < ERT_Begin || type_ >= ERT_End ) return 0;
return _images[type_];
}
private:
SDL_Surface* _images[ERT_Num];
};
#endif