3
Dodgin' Diamond 2, a shot'em up arcade
4
Copyright (C) 2003,2004 Juan J. Martinez <jjm@usebox.net>
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License Version 2 as
8
published by the Free Software Foundation.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28
extern SDL_Surface *screen, *gfx;
29
extern SDL_Joystick *joy[2];
30
extern Mix_Chunk *efx[8];
31
extern Mix_Music *bgm;
34
extern pDesc player[2];
36
extern score hiscore[10];
39
extern float scroll,scroll2;
44
drawGetName(char *name, int place, int playern)
48
/* erase the screen */
49
SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0));
51
writeCString(gfx, screen, 90, 40, "congratulations", 0);
53
sprintf(buffer,"player %i with score %.6li",playern,player[playern-1].score);
54
writeCString(gfx, screen, 10, 80, buffer, 1);
58
sprintf(buffer,"you got %ith place",place);
61
sprintf(buffer,"you got %ist place",place);
64
sprintf(buffer,"you got %ind place",place);
67
sprintf(buffer,"you got %ird place",place);
70
writeCString(gfx, screen, 10, 97, buffer, 1);
72
writeCString(gfx, screen, 10, 131, "enter your name", 0);
75
sprintf(buffer,"%s+",name);
79
writeCString(gfx, screen, 175, 131, buffer, 1);
85
getName(char *name, int place, int playern)
92
if(joy[playern-1] && player[playern-1].joy)
98
drawGetName(name,place,playern);
102
while(SDL_PollEvent(&mevent)) {
103
if (mevent.type==SDL_QUIT)
106
/* joystick control */
107
if(joy[playern-1] && player[playern-1].joy)
109
SDL_JoystickUpdate();
111
i=SDL_JoystickGetAxis(joy[playern-1],1);
114
mevent.type=SDL_KEYDOWN;
115
mevent.key.keysym.sym=SDLK_DOWN;
119
mevent.type=SDL_KEYDOWN;
120
mevent.key.keysym.sym=SDLK_UP;
122
i=SDL_JoystickGetAxis(joy[playern-1],0);
125
mevent.type=SDL_KEYDOWN;
126
mevent.key.keysym.sym=SDLK_RIGHT;
129
if(SDL_JoystickGetButton(joy[playern-1], 0))
131
mevent.type=SDL_KEYDOWN;
132
mevent.key.keysym.sym=SDLK_RETURN;
135
if(SDL_JoystickGetButton(joy[playern-1], 1))
138
mevent.type=SDL_KEYDOWN;
139
mevent.key.keysym.sym=SDLK_BACKSPACE;
144
if(mevent.type==SDL_KEYDOWN) {
145
if(mevent.key.keysym.sym==SDLK_ESCAPE) {
147
strcpy(name,"nobody");
151
if(mevent.key.keysym.sym==SDLK_DOWN)
162
drawGetName(name,place,playern);
167
if(mevent.key.keysym.sym==SDLK_UP)
178
drawGetName(name,place,playern);
183
if(mevent.key.keysym.sym==SDLK_RIGHT)
189
drawGetName(name,place,playern);
196
if(mevent.key.keysym.sym==SDLK_RETURN)
200
Mix_PlayChannel(-1,efx[7],0);
204
if(mevent.key.keysym.sym==SDLK_BACKSPACE) {
208
drawGetName(name,place,playern);
213
/* I don't know if this will work ever, in my system does */
214
if((mevent.key.keysym.sym>=SDLK_a &&
215
mevent.key.keysym.sym<=SDLK_z) ||
216
(mevent.key.keysym.sym>=SDLK_0 &&
217
mevent.key.keysym.sym<=SDLK_9)) {
219
name[pos]=SDLK2ascii(mevent.key.keysym.sym);
222
drawGetName(name,place,playern);
235
drawHiscores(int max)
240
/* erase the screen */
241
SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0));
250
SDL_BlitSurface(gfx, &b, screen, &a);
253
writeCString(gfx, screen, 80, 2, "the hall of fame", 1);
256
writeNumber(gfx, screen, 10, 23+i*17, i+1, 2);
257
writeCString(gfx, screen, 30, 20+i*17, hiscore[i].name, 0);
258
writeCString(gfx, screen, 180, 20+i*17, "st",0);
259
writeNumber(gfx, screen, 200, 23+i*17, hiscore[i].stage,2);
260
writeCString(gfx, screen, 236, 20+i*17, "sc",0);
261
writeNumber(gfx, screen, 260, 23+i*17, hiscore[i].score,6);
281
while(SDL_PollEvent(&mevent)) {
282
if (mevent.type==SDL_QUIT)
284
if(mevent.type==SDL_KEYDOWN) {
288
/* wait some time and return */
289
if(SDL_GetTicks()-tick>10000) {
292
Mix_PlayChannel(-1,efx[7],0);
301
drawConfigure(int option)
303
/* erase the screen */
304
SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0));
307
writeCString(gfx, screen, 20, 20, "player 1", 0);
308
if(conf.control[0]==KEYBOARD)
309
writeCString(gfx, screen, 20, 37, " keyboard", (option==1));
311
writeCString(gfx, screen, 20, 37, " joystick 1", (option==1));
312
writeCString(gfx, screen, 20, 54, "player 2", 0);
313
if(conf.control[1]==KEYBOARD)
314
writeCString(gfx, screen, 20, 71, " keyboard", (option==2));
316
writeCString(gfx, screen, 20, 71, " joystick 2", (option==2));
317
writeCString(gfx, screen, 20, 105, "sound", 0);
321
writeCString(gfx, screen, 20, 122, " high quality", (option==3));
324
writeCString(gfx, screen, 20, 122, " medium quality", (option==3));
327
writeCString(gfx, screen, 20, 122, " low quality", (option==3));
330
writeCString(gfx, screen, 20, 122, " no sound", (option==3));
333
writeCString(gfx, screen, 20, 139, "graphic mode", 0);
335
writeCString(gfx, screen, 20, 156, " fullscreen", (option==4));
337
writeCString(gfx, screen, 20, 156, " windowed", (option==4));
348
drawConfigure(option);
351
while(SDL_PollEvent(&mevent)) {
352
if (mevent.type==SDL_QUIT)
355
/* joystick control for the menu */
358
SDL_JoystickUpdate();
360
i=SDL_JoystickGetAxis(joy[0],1);
363
mevent.type=SDL_KEYDOWN;
364
mevent.key.keysym.sym=SDLK_DOWN;
368
mevent.type=SDL_KEYDOWN;
369
mevent.key.keysym.sym=SDLK_UP;
372
if(SDL_JoystickGetButton(joy[0], 0))
374
mevent.type=SDL_KEYDOWN;
375
mevent.key.keysym.sym=SDLK_RETURN;
378
if(SDL_JoystickGetButton(joy[0], 1))
380
mevent.type=SDL_KEYDOWN;
381
mevent.key.keysym.sym=SDLK_ESCAPE;
385
if(mevent.type==SDL_KEYDOWN) {
386
if(mevent.key.keysym.sym==SDLK_ESCAPE)
388
if(mevent.key.keysym.sym==SDLK_DOWN ||
389
mevent.key.keysym.sym==SDLK_s) {
393
drawConfigure(option);
395
if(mevent.key.keysym.sym==SDLK_UP ||
396
mevent.key.keysym.sym==SDLK_w) {
400
drawConfigure(option);
402
if(mevent.key.keysym.sym==SDLK_RETURN) {
408
conf.control[0]=conf.control[0] ? 0 : 1;
409
drawConfigure(option);
414
conf.control[1]=conf.control[1] ? 0 : 1;
415
drawConfigure(option);
429
for(i=0;i<NUM_EFX;i++)
431
Mix_FreeChunk(efx[i]);
437
if(conf.sound!=NO_SOUND) {
450
if(Mix_OpenAudio(i, MIX_DEFAULT_FORMAT, 2, 2048)<0) {
451
fprintf(stderr, "Unable to set audio: %s\n", SDL_GetError());
456
Mix_PlayChannel(-1,efx[7],0);
460
drawConfigure(option);
463
conf.fullscreen=conf.fullscreen ? 0 : 1;
464
drawConfigure(option);
480
/* erase the screen */
481
SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0));
490
SDL_BlitSurface(gfx, &b, screen, &a);
493
writeCString(gfx, screen, 105, 50, "one player", (option==1));
494
writeCString(gfx, screen, 105, 67, "two players", (option==2));
495
writeCString(gfx, screen, 105, 94, "hall of fame", (option==3));
496
writeCString(gfx, screen, 105, 111, "configure", (option==4));
497
writeCString(gfx, screen, 105, 138, "about", (option==5));
498
writeCString(gfx, screen, 105, 155, "exit game", (option==6));
507
SDL_BlitSurface(gfx, &b, screen, &a);
520
Mix_PlayChannel(-1,efx[7],0);
524
/* some dirty init */
528
while(SDL_PollEvent(&mevent)) {
529
if (mevent.type==SDL_QUIT)
532
/* joystick control for the menu */
535
SDL_JoystickUpdate();
537
i=SDL_JoystickGetAxis(joy[0],1);
540
mevent.type=SDL_KEYDOWN;
541
mevent.key.keysym.sym=SDLK_DOWN;
545
mevent.type=SDL_KEYDOWN;
546
mevent.key.keysym.sym=SDLK_UP;
549
if(SDL_JoystickGetButton(joy[0], 0))
551
mevent.type=SDL_KEYDOWN;
552
mevent.key.keysym.sym=SDLK_RETURN;
555
if(SDL_JoystickGetButton(joy[0], 1))
557
mevent.type=SDL_KEYDOWN;
558
mevent.key.keysym.sym=SDLK_ESCAPE;
562
if(mevent.type==SDL_KEYDOWN) {
563
if(mevent.key.keysym.sym==SDLK_ESCAPE)
565
if(mevent.key.keysym.sym==SDLK_DOWN ||
566
mevent.key.keysym.sym==SDLK_s) {
572
if(mevent.key.keysym.sym==SDLK_UP ||
573
mevent.key.keysym.sym==SDLK_w) {
579
if(mevent.key.keysym.sym==SDLK_RETURN) {
586
player[0].score=player[1].score=0;
587
player[0].stage=player[1].stage=0;
592
player[0].score=player[1].score=0;
593
player[0].stage=player[1].stage=0;
627
/* erase the screen */
628
SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0));
637
SDL_BlitSurface(gfx, &b, screen, &a);
639
writeCString(gfx, screen, 20, 50, "this is dd2 version " VERSION ".", 0);
640
writeCString(gfx, screen, 20, 80, "main author", 1);
641
writeCString(gfx, screen, 40, 105, "juan j. martinez", 0);
642
writeCString(gfx, screen, 40, 140, "thanks you for playing...", 0);
657
while(SDL_PollEvent(&mevent)) {
658
if (mevent.type==SDL_QUIT)
660
if(mevent.type==SDL_KEYDOWN) {
664
/* wait some time and return */
665
if(SDL_GetTicks()-tick>10000) {
668
Mix_PlayChannel(-1,efx[7],0);