This repository has been archived by the owner on Jul 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresources.cpp
338 lines (312 loc) · 8.21 KB
/
resources.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
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
/*
Contains the resources and functions for using this program. Mostly SDL_Surfaces and such.
Copyright James Russell 2010
*/
//INCLUDES//
#include "resources.h"
//External function definitions.//
extern const int AC_NONE;
extern const int AC_CK;
extern const int AC_A;
extern void AC_QuitEngine(void);
extern SDL_Surface *AC_LoadTex(const char *AC_TexFilename,Uint8 AC_TypeFlag=AC_NONE,Uint8 CK_R=0,Uint8 CK_G=0,Uint8 CK_B=0,bool AC_RLE=true);
////////////////RESOURCES////////////////
//SDL_Surfaces.//
SDL_Surface *AC_Screen;
SDL_Surface *AC_BG;
SDL_Surface *AC_FPSSurf;
SDL_Surface *AC_DigiClock_Sec_Ones;
SDL_Surface *AC_DigiClock_Sec_Tens;
SDL_Surface *AC_DigiClock_Min_Ones;
SDL_Surface *AC_DigiClock_Min_Tens;
SDL_Surface *AC_DigiClock_Hrs_Ones;
SDL_Surface *AC_DigiClock_Hrs_Tens;
SDL_Surface *AC_DigiClock_Colon;
SDL_Surface *AC_DigiClock_Cover;
SDL_Surface *AC_SecondHandSurfRotate;
SDL_Surface *AC_SecondHandSurf;
SDL_Surface *AC_SecondHandCover;
SDL_Surface *AC_UpOrDownSurf;
SDL_Surface *AC_NoteLinesSurfs[8];
SDL_Surface *AC_ArrowUp;
SDL_Surface *AC_ArrowDown;
SDL_Surface *AC_LightOn;
SDL_Surface *AC_ButtonOn;
SDL_Surface *AC_ButtonOff;
SDL_Surface *AC_CreditSurf;
SDL_Surface *AC_Logo;
//SDL_ttf font.
TTF_Font *AC_Font_Digital;
TTF_Font *AC_Font_ArialBig;
TTF_Font *AC_Font_ArialSmall;
//SDL_mixer sound chunks.
Mix_Chunk *AC_S_Ring;
Mix_Chunk *AC_S_Beep;
////////////////FUNCTIONS////////////////
//Load all surfaces.//
bool AC_LoadAllSurfs(void)
{
//Load the background image.
AC_BG=AC_LoadTex("media/BG.png");
//If it failed...
if(AC_BG==NULL)
{
//Return false.
return false;
}
//Load the colon texture.
AC_DigiClock_Colon=AC_LoadTex("media/colon.png",AC_CK,255,255,255);
//If it didn't load...
if(AC_DigiClock_Colon==NULL)
{
//Return false.
return false;
}
//Load the cover texture.
AC_DigiClock_Cover=AC_LoadTex("media/cover.png",AC_A);
//If it didn't load...
if(AC_DigiClock_Cover==NULL)
{
//Return false.
return false;
}
//Load the second hand texture.
AC_SecondHandSurf=AC_LoadTex("media/second.png",AC_A);
//If it failed...
if(AC_SecondHandSurf==NULL)
{
//Return false.
return false;
}
//Load the second hand cover.
AC_SecondHandCover=AC_LoadTex("media/secondhand_cover.png",AC_A);
//If it failed...
if(AC_SecondHandCover==NULL)
{
//Return false.
return false;
}
//Load the arrow up and down texture.
AC_ArrowUp=AC_LoadTex("media/arrow_up.png",AC_A);
AC_ArrowDown=AC_LoadTex("media/arrow_down.png",AC_A);
//If they both didn't load...
if(AC_ArrowUp==NULL || AC_ArrowDown==NULL)
{
//Return false.
return false;
}
//Load the light on texture.
AC_LightOn=AC_LoadTex("media/light_on.png",AC_A);
//If it failed...
if(!AC_LightOn)
{
//Return false.
return false;
}
//Load the "Button On" texture.
AC_ButtonOn=AC_LoadTex("media/button_on.png",AC_NONE);
//If it failed...
if(!AC_ButtonOn)
{
//Return false.
return false;
}
//Load the "Button Off" texture.
AC_ButtonOff=AC_LoadTex("media/button_off.png",AC_NONE);
//If it failed...
if(!AC_ButtonOff)
{
//Return false.
return false;
}
//Load the logo.
AC_Logo=AC_LoadTex("media/logo.png",AC_A);
//If it didn't load...
if(!AC_Logo)
{
//Return false.
return false;
}
//Say they all loaded.
printf("All textures loaded.\n");
//Then return true for success.
return true;
}
//Free surfaces.//
void AC_FreeAllSurfs(void)
{
//Free them surfaces, man.
//AND DON'T HOLD BACK!
SDL_FreeSurface(AC_BG);
SDL_FreeSurface(AC_FPSSurf);
SDL_FreeSurface(AC_DigiClock_Sec_Ones);
SDL_FreeSurface(AC_DigiClock_Sec_Tens);
SDL_FreeSurface(AC_DigiClock_Min_Ones);
SDL_FreeSurface(AC_DigiClock_Min_Tens);
SDL_FreeSurface(AC_DigiClock_Hrs_Ones);
SDL_FreeSurface(AC_DigiClock_Hrs_Tens);
SDL_FreeSurface(AC_DigiClock_Colon);
SDL_FreeSurface(AC_DigiClock_Cover);
SDL_FreeSurface(AC_SecondHandSurfRotate);
SDL_FreeSurface(AC_SecondHandSurf);
SDL_FreeSurface(AC_SecondHandCover);
SDL_FreeSurface(AC_UpOrDownSurf);
for(int count=0;count<8;count++)
{
SDL_FreeSurface(AC_NoteLinesSurfs[count]);
}
SDL_FreeSurface(AC_ArrowUp);
SDL_FreeSurface(AC_ArrowDown);
SDL_FreeSurface(AC_LightOn);
SDL_FreeSurface(AC_ButtonOff);
SDL_FreeSurface(AC_ButtonOn);
SDL_FreeSurface(AC_CreditSurf);
SDL_FreeSurface(AC_Logo);
}
//Open fonts.//
bool AC_OpenFonts(void)
{
//Open the font.
AC_Font_Digital=TTF_OpenFont("media/DS_DIGI.TTF",65);
//If it failed to open...
if(AC_Font_Digital==NULL)
{
//Say so and why.
printf("***Error opening font: %s***\n",TTF_GetError());
//Then return false.
return false;
}
//Then open the arial font with a big setting.
AC_Font_ArialBig=TTF_OpenFont("media/LiberationSans-Bold.ttf",20);
//If it failed...
if(AC_Font_ArialBig==NULL)
{
//Say so and why.
printf("***Error opening font: %s***\n",TTF_GetError());
//Then return false.
return false;
}
//Open the small font, for note writing.
AC_Font_ArialSmall=TTF_OpenFont("media/LiberationSans-Regular.ttf",12);
//If it failed...
if(AC_Font_ArialSmall==NULL)
{
//Say so and why.
printf("***Error opening font: %s***\n",TTF_GetError());
//Then return false.
return false;
}
//Otherwise, it must of worked.
//Say so.
printf("Loaded fonts.\n");
//Then return true.
return true;
}
//Close fonts.//
void AC_CloseFonts(void)
{
//If the digital font was loaded...
if(!AC_Font_Digital)
{
//Just close the font.
TTF_CloseFont(AC_Font_Digital);
//Just to be sure.
AC_Font_Digital=NULL;
}
//If the big arial font was loaded...
if(!AC_Font_ArialBig)
{
//Then close the big font.
TTF_CloseFont(AC_Font_ArialBig);
//Just to be sure.
AC_Font_ArialBig=NULL;
}
//If the small arial font was loaded...
if(!AC_Font_ArialSmall)
{
//Then close the small arial font.
TTF_CloseFont(AC_Font_ArialSmall);
//Just to be sure.
AC_Font_ArialSmall=NULL;
}
}
//Free resources.//
void AC_FreeResources(void)
{
//Free the fonts.
AC_CloseFonts();
//Free the sound chunks.
AC_FreeSoundChunks();
//Free the surfs.
AC_FreeAllSurfs();
}
//Open all resources.//
bool AC_OpenAllResources(void)
{
//Load the textures.
//If it failed...
if(AC_LoadAllSurfs()==false)
{
//Say so.
printf("***Error loading textures.***\n");
//Return false for fail.
return false;
}
//Load all the fonts used.
//If that failed...
if(AC_OpenFonts()==false)
{
//Say so.
printf("***Error loading fonts.***\n");
//Return false for fail.
return false;
}
//Load the sounds.
//If that failed...
if(AC_LoadSoundChunks()==false)
{
//Say so.
printf("***Error loading sounds.***\n");
//Return false for fail.
return false;
}
//Otherwise, all the resources must of been loaded.
//Say so.
printf("All resources loaded.\n");
//Return true for success.
return true;
}
//Load sound chunks.//
bool AC_LoadSoundChunks(void)
{
//Load the beep sound effect.
AC_S_Beep=Mix_LoadWAV("media/beep.wav");
//If it failed...
if(!AC_S_Beep)
{
//Say so and why.
printf("***Failed to load sound: %s***\n",Mix_GetError());
//Return false.
return false;
}
//Load the ring sound effect.
AC_S_Ring=Mix_LoadWAV("media/ring.wav");
//If it failed...
if(!AC_S_Ring)
{
//Say so and why.
printf("***Failed to load sound: %s***\n",Mix_GetError());
//Return false.
return false;
}
//Return true for success.
return true;
}
//Free the sound chunks.//
void AC_FreeSoundChunks(void)
{
//Free the chunks.
Mix_FreeChunk(AC_S_Beep);
Mix_FreeChunk(AC_S_Ring);
}
////////////////EOF////////////////