1
/***************************************************************************
3
- description: pause screen for the games
6
copyright : (C) 2003 by Jesse Andrews
7
email : jdandr2@uky.edu
8
***************************************************************************/
10
/***************************************************************************
12
* This program is free software; you can redistribute it and/or modify *
13
* it under the terms of the GNU General Public License as published by *
14
* the Free Software Foundation; either version 2 of the License, or *
15
* (at your option) any later version. *
17
***************************************************************************/
23
SDL_Surface *up, *down, *left, *right;
24
SDL_Rect rectUp, rectDown, rectLeft, rectRight;
26
extern settings localsettings;
28
void pause_load_media(void) {
30
pause_sfx = LoadSound( "tock.wav" );
32
up = LoadImage("up.png", IMG_ALPHA);
33
rectUp.w = up->w; rectUp.h = up->h;
35
down = LoadImage("down.png", IMG_ALPHA);
36
rectDown.w = down->w; rectDown.h = down->h;
38
left = LoadImage("left.png", IMG_ALPHA);
39
rectLeft.w = left->w; rectLeft.h = left->h;
41
right = LoadImage("right.png", IMG_ALPHA);
42
rectRight.w = right->w; rectRight.h = right->h;
44
f1 = LoadFont( ttf_font, 24 );
45
f2 = LoadFont( ttf_font, 36 );
48
void pause_unload_media(void) {
50
Mix_FreeChunk(pause_sfx);
52
SDL_FreeSurface(down);
53
SDL_FreeSurface(left);
54
SDL_FreeSurface(right);
59
void pause_draw_info(void) {
63
rectLeft.y = rectRight.y = 200;
64
rectDown.y = rectUp.y = 300;
66
rectLeft.x = rectDown.x = 320 - (7*16) - rectLeft.w - 4;
67
rectRight.x = rectUp.x = 320 + (7*16) + 4;
71
SDL_BlitSurface(left, NULL, screen, &rectLeft);
72
SDL_BlitSurface(right, NULL, screen, &rectRight);
74
SDL_BlitSurface(down, NULL, screen, &rectDown);
75
SDL_BlitSurface(up, NULL, screen, &rectUp);
80
t = black_outline(_("Sound Effects Volume"), f1, &white);
83
SDL_BlitSurface(t, NULL, screen, &s);
86
t = black_outline(_("Music Volume"), f1, &white);
89
SDL_BlitSurface(t, NULL, screen, &s);
94
t = black_outline(_("Sound & Music Disabled"), f1, &white);
97
SDL_BlitSurface(t, NULL, screen, &s);
101
t = black_outline(_("Paused!"), f2, &white);
104
SDL_BlitSurface(t, NULL, screen, &s);
107
t = black_outline(_("Press escape again to return to menu"), f1, &white);
110
SDL_BlitSurface(t, NULL, screen, &s);
113
t = black_outline(_("Press space bar to return to game"), f1, &white);
116
SDL_BlitSurface(t, NULL, screen, &s);
120
void draw_vols(int sfx, int mus) {
127
s.x = rectLeft.x + rectLeft.w + 5;
128
m.x = rectDown.x + rectDown.w + 5;
131
for (i = 1; i<=32; i++){
133
SDL_FillRect(screen, &s, SDL_MapRGB(screen->format, 0, 0, 127+sfx));
135
SDL_FillRect(screen, &s, SDL_MapRGB(screen->format, 0, 0, 0));
138
SDL_FillRect(screen, &m, SDL_MapRGB(screen->format, 0, 0, 127+mus));
140
SDL_FillRect(screen, &m, SDL_MapRGB(screen->format, 0, 0, 0));
146
/* ==== fillscreen ====
147
* RESULT: it will darken the screen by a factor of 4
148
* WARNING: only works on 16bit screens right now!
150
void darkenscreen( void ){
151
Uint16 rm = screen->format->Rmask;
152
Uint16 gm = screen->format->Gmask;
153
Uint16 bm = screen->format->Bmask;
159
for (y = 0; y<480; y++)
160
for (x = 0; x<640; x++) {
161
*p = (((*p&rm)>>2)&rm) | (((*p&gm)>>2)&gm) | (((*p&bm)>>2)&bm); p++;
165
int inRect( SDL_Rect r, int x, int y) {
166
if ((x < r.x) || (y < r.y) || (x > r.x + r.w) || (y > r.y + r.h))
171
// QUESTION: For usability sake, should escape return to the game
172
// and the user have to choose to quit the game, or ???
173
/**********************
174
Pause : Pause the game
175
***********************/
182
int mousePressed = 0;
184
int tocks=0; // used for keeping track of when a tock has happened
187
LOG( "---GAME PAUSED---\n" );
189
/* --- stop all sounds, play pause noise --- */
193
Mix_PlayChannel(-1, pause_sfx, 0);
194
sfx_volume = Mix_Volume(-1, -1); // get sfx volume w/o changing it
195
mus_volume = Mix_VolumeMusic(-1); // get mus volume w/o changing it
198
/* --- show the pause screen --- */
202
// Darken the screen...
207
draw_vols(sfx_volume, mus_volume);
212
SDL_EnableKeyRepeat( 1, 20 );
214
/* --- wait for space, click, or exit --- */
217
old_sfx_volume = sfx_volume;
218
old_mus_volume = mus_volume;
219
while (SDL_PollEvent(&event))
220
switch (event.type) {
226
((event.key.keysym.sym == SDLK_RIGHT) ||
227
(event.key.keysym.sym == SDLK_LEFT)))
231
if (event.key.keysym.sym == SDLK_SPACE)
233
if (event.key.keysym.sym == SDLK_ESCAPE) {
238
if (event.key.keysym.sym == SDLK_RIGHT)
240
if (event.key.keysym.sym == SDLK_LEFT)
242
if (event.key.keysym.sym == SDLK_UP)
244
if (event.key.keysym.sym == SDLK_DOWN)
248
case SDL_MOUSEBUTTONDOWN:
252
case SDL_MOUSEBUTTONUP:
258
if (sys_sound && mousePressed) {
261
SDL_GetMouseState(&x, &y);
262
/* check to see if they clicked on a button */
264
if (inRect(rectUp, x, y)) {
266
} else if (inRect(rectDown, x, y)) {
268
} else if (inRect(rectRight, x, y)) {
270
} else if (inRect(rectLeft, x, y)) {
274
/* check to see if they clicked a bar */
276
if ((x > rectLeft.x + rectLeft.w) && (x < rectRight.x)) {
277
if ((y >= rectLeft.y) && (y <= rectLeft.y + rectLeft.h)) {
278
sfx_volume = 4+(int)(128.0 * ((x - rectLeft.x - rectLeft.w - 1.0) / (rectRight.x - rectLeft.x - rectLeft.w - 2.0)));
280
if ((y >= rectDown.y) && (y <= rectDown.y + rectDown.h)) {
281
mus_volume = 4+(int)(128.0 * ((x - rectLeft.x - rectLeft.w - 1.0) / (rectRight.x - rectLeft.x - rectLeft.w - 2.0)));
290
if (sfx_volume > MIX_MAX_VOLUME)
291
sfx_volume = MIX_MAX_VOLUME;
294
if (mus_volume > MIX_MAX_VOLUME)
295
mus_volume = MIX_MAX_VOLUME;
299
if ((mus_volume != old_mus_volume) ||
300
(sfx_volume != old_sfx_volume)) {
302
if (mus_volume != old_mus_volume)
303
Mix_VolumeMusic(mus_volume);
305
if (sfx_volume != old_sfx_volume) {
306
Mix_Volume(-1,sfx_volume);
308
Mix_PlayChannel(-1, pause_sfx, 0);
312
draw_vols(sfx_volume, mus_volume);
313
localsettings.mus_volume=mus_volume;
314
localsettings.sfx_volume=sfx_volume;
322
/* --- Return to previous state --- */
324
SDL_EnableKeyRepeat( 0, SDL_DEFAULT_REPEAT_INTERVAL );
329
Mix_PlayChannel(-1, pause_sfx, 0);
333
LOG( "---GAME RESUMED---\n" );