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.
27
#define APP_NAME "Dodgin' Diamond ]["
37
static const char COPYRIGHT[]="Dodgin' Diamond 2 - Copyright (c) 2003,2004 Juan J. Martinez <jjm@usebox.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License Version 2 as published by the Free Software Foundation (www.fsf.org).";
40
SDL_Surface *screen, *gfx;
41
extern pDesc player[2];
42
SDL_Joystick *joy[2]={ NULL, NULL };
45
float scroll=0,scroll2=0;
55
Mix_Chunk *efx[8]={ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
56
Mix_Music *bgm=NULL, *bgm_boss=NULL;
60
/* load all the sound stuff */
67
sprintf(buffer,"%s/bgm1.xm",DD2_DATA);
68
bgm=Mix_LoadMUS(buffer);
70
fprintf(stderr,"Unable load bgm: %s\n", SDL_GetError());
72
sprintf(buffer,"%s/bgm2.xm",DD2_DATA);
73
bgm_boss=Mix_LoadMUS(buffer);
75
fprintf(stderr,"Unable load bgm_boss: %s\n", SDL_GetError());
77
for(i=0;i<NUM_EFX;i++) {
78
sprintf(buffer,"%s/efx%i.wav",DD2_DATA,i+1);
79
efx[i]=Mix_LoadWAV(buffer);
81
fprintf(stderr,"Unable load efx: %s\n", SDL_GetError());
83
Mix_VolumeChunk(efx[i],MIX_MAX_VOLUME/2);
93
for(done=false,tick=SDL_GetTicks();!done && afterdeath<400;) {
95
while(SDL_PollEvent(&event)) {
96
if (event.type==SDL_QUIT)
99
/* joystick control for the menu */
100
if(player[0].joy && joy[0])
102
SDL_JoystickUpdate();
104
if(SDL_JoystickGetButton(joy[0], 1))
106
event.type=SDL_KEYDOWN;
107
event.key.keysym.sym=SDLK_p;
111
if(player[1].joy && joy[1])
113
SDL_JoystickUpdate();
115
if(SDL_JoystickGetButton(joy[1], 1))
117
event.type=SDL_KEYDOWN;
118
event.key.keysym.sym=SDLK_p;
122
if(event.type==SDL_KEYDOWN) {
123
if(event.key.keysym.sym==SDLK_ESCAPE) {
129
if(event.key.keysym.sym==SDLK_p && pause_tick<SDL_GetTicks())
131
writeCString(gfx, screen, 98, 20, "game paused", 0);
133
pause=pause ? false : true;
134
pause_tick=SDL_GetTicks()+200;
138
if(event.key.keysym.sym==SDLK_F12)
139
SDL_SaveBMP(screen,"scnshot.bmp");
145
if(player[0].shield) {
146
if(joy[0] && player[0].joy)
147
control_player_joy(joy[0],&player[0]);
149
control_player(&player[0]);
152
if(player[1].shield) {
153
if(joy[1] && player[1].joy)
154
control_player_joy(joy[1],&player[1]);
156
control_player(&player[1]);
162
/* frame rate calculation */
163
ntick=SDL_GetTicks();
164
if(ntick-tick>=1000/FPS) {
184
SDL_BlitSurface(gfx, &b, screen, &a);
188
b.h=SCREENH-(int)scroll;
189
SDL_BlitSurface(gfx, &b, screen, &a);
190
a.y=SCREENH-(int)scroll;
193
SDL_BlitSurface(gfx, &b, screen, &a);
196
/* scroll parallax here */
211
SDL_BlitSurface(gfx, &b, screen, &a);
215
SDL_BlitSurface(gfx, &b, screen, &a);
218
b.y=204+(int)scroll2;
219
b.h=SCREENH-(int)scroll2;
220
SDL_BlitSurface(gfx, &b, screen, &a);
221
a.y=SCREENH-(int)scroll2;
224
SDL_BlitSurface(gfx, &b, screen, &a);
229
b.y=204+(int)scroll2;
230
b.h=SCREENH-(int)scroll2;
231
SDL_BlitSurface(gfx, &b, screen, &a);
232
a.y=SCREENH-(int)scroll2;
235
SDL_BlitSurface(gfx, &b, screen, &a);
246
engine_player(&player[0]);
249
engine_player(&player[1]);
251
if(!(player[0].shield | player[1].shield))
259
drawPanel(gfx,screen,player);
267
main (int argc, char *argv[])
276
if(argv[1][0]=='-' && argv[1][1]=='v') {
277
printf("%s v%s\nCopyright (c) 2003,2004 Juan J. Martinez <jjm@usebox.net>\n", PACKAGE, VERSION);
278
printf("This is free software, and you are welcome\nto redistribute it"
279
" under certain conditions; read COPYING for details.\n");
283
/* try local configuration */
284
sprintf(buffer,"%.500s/.dd2rc",getenv("HOME"));
285
if(!loadCFG(buffer,&conf)) {
286
/* if there's no local, use global */
287
sprintf(buffer,"%s/dd2.cfg",DD2_DATA);
288
if(!loadCFG(buffer,&conf))
289
fprintf(stderr,"unable to read configuration, using defaults\n");
292
sprintf(buffer,"%s/dd2.cfg",DD2_DATA);
293
if(!loadCFG(buffer,&conf))
294
fprintf(stderr,"unable to read configuration, using defaults\n");
298
sprintf(buffer,"%s/dd2-hiscore",DD2_DATA);
299
if(!loadScore(buffer,hiscore))
300
fprintf(stderr,"unable to read hi-scores, using defaults\n");
302
/* don't init sound if it's not needed */
303
if(conf.sound!=NO_SOUND)
304
i=SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_JOYSTICK);
306
i=SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK);
308
fprintf(stderr,"Unable to init SDL: %s\n", SDL_GetError());
313
sound=SDL_WasInit(SDL_INIT_AUDIO) & SDL_INIT_AUDIO;
315
/* no sound, 16000, 22050, 44100 */
316
if(sound && conf.sound!=NO_SOUND) {
329
if(Mix_OpenAudio(i, MIX_DEFAULT_FORMAT, 2, 2048)<0) {
330
fprintf(stderr, "Unable to set audio: %s\n", SDL_GetError());
336
vi=(SDL_VideoInfo *)SDL_GetVideoInfo();
338
bpp=vi->vfmt->BitsPerPixel;
341
screen=SDL_SetVideoMode(SCREENW, SCREENH, bpp, SDL_HWSURFACE|SDL_HWPALETTE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
343
screen=SDL_SetVideoMode(SCREENW, SCREENH, bpp, SDL_HWSURFACE|SDL_HWPALETTE|SDL_DOUBLEBUF);
346
fprintf(stderr, "Unable to set video mode: %s\n", SDL_GetError());
350
/* init the joystick */
351
if(SDL_WasInit(SDL_INIT_JOYSTICK) & SDL_INIT_JOYSTICK)
352
if(SDL_NumJoysticks()>=1)
354
joy[0]=SDL_JoystickOpen(0);
355
if(SDL_NumJoysticks()>1)
356
joy[1]=SDL_JoystickOpen(1);
360
SDL_ShowCursor(SDL_DISABLE);
362
/* set the caption */
363
SDL_WM_SetCaption(APP_NAME,NULL);
365
/* load console gfx */
366
sprintf(buffer,"%s/gfx.bmp",DD2_DATA);
369
fprintf(stderr,"Unable load gfx: %s\n", SDL_GetError());
372
/* set transparent color */
373
if(SDL_SetColorKey(gfx, SDL_SRCCOLORKEY, SDL_MapRGB(gfx->format, 255, 0, 255))<0) {
374
fprintf(stderr,"Unable to setup gfx: %s\n", SDL_GetError());
381
/* init the engine */
384
SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0));
388
Mix_VolumeMusic(MIX_MAX_VOLUME);
389
Mix_FadeInMusic(bgm,-1,2000);
393
player[0].joy=(int)conf.control[0]==JOYSTICK;
394
player[1].joy=(int)conf.control[1]==JOYSTICK;
402
Mix_FadeOutMusic(2000);
407
/* check if there's a place for this score */
408
for(j=9;j>=0 && hiscore[j].score<player[i].score;j--);
410
/* the player will be in the hall of fame? */
413
hiscore[k+1]=hiscore[k];
415
/* put the new score */
416
hiscore[j+1].score=player[i].score;
417
hiscore[j+1].stage=player[i].stage;
419
hiscore[j+1].name[0]=0;
420
if(!getName(hiscore[j+1].name, j+2,i+1))
421
break; /* probably a problem if the user closes the window */
423
/* show the hall of fame */
433
Mix_FreeMusic(bgm_boss);
435
for(i=0;i<NUM_EFX;i++)
437
Mix_FreeChunk(efx[i]);
442
/* release the joystick */
443
if(SDL_JoystickOpened(0))
444
SDL_JoystickClose(joy[0]);
445
if(SDL_JoystickOpened(1))
446
SDL_JoystickClose(joy[1]);
449
SDL_FreeSurface(gfx);
451
/* free engine memory */
454
/* now update conf changes */
456
/* update cnf file */
457
sprintf(buffer,"%s/dd2.cfg",DD2_DATA);
459
/* save conf into local */
460
sprintf(buffer,"%.500s/.dd2rc",getenv("HOME"));
462
saveCFG(buffer,&conf);
465
sprintf(buffer,"%s/dd2-hiscore",DD2_DATA);
466
if(!saveScore(buffer,hiscore))
467
fprintf(stderr,"unable to save hi-scores\ndo you have permissions to write into %s?\n"