1 /* Variations on RockDodger
2 * Space Rocks copyright (C) 2001 Paul Holt <pad@pcholt.com>
4 * Project fork 2004, Jason Woofenden and Joshua Grams.
5 * (a whole bunch of modifications and project rename)
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include <SDL/SDL_image.h>
43 #define CONDERROR(a) if((a)) {initerror = strdup(SDL_GetError());return 1;}
44 #define NULLERROR(a) CONDERROR((a) == NULL)
46 // ************************************* STRUCTS
48 // Array of black pixel coordinates. This is scanned
49 // every frame to see if it's still black, and as
50 // soon as it isn't we BLOW UP
53 int dead; // has been blown out of the way
54 // to make room for a new ship appearing.
59 struct black_point_struct {
63 // Bang dots have the same colour as shield dots.
64 // Bang dots get darker as they age.
65 // Some are coloured the same as the ex-ship.
67 Uint16 c; // when zero, use heatcolor[bangdotlife]
68 float life; // When reduced to 0, set active = 0
70 float decay;// Amount by which to reduce life each time dot is drawn
73 // Engine dots stream out the back of the ship, getting darker as they go.
76 // The life of an engine dot
77 // is a number starting at between 0 and 50 and counting backward.
78 float life; // When reduced to 0, set active = 0
81 // Space dots are harmless background items
82 // All are active. When one falls off the edge, another is created at the start.
87 // ************************************* VARS
88 // SDL_Surface global variables
90 *surf_screen, // Screen
91 *surf_b_variations, // "variations" banner
92 *surf_b_on, // "on" banner
93 *surf_b_rockdodger, // "rockdodger" banner
94 *surf_b_game, // Title element "game"
95 *surf_b_over, // Title element "over"
96 *surf_ship, // Spaceship element
97 *surf_life, // Indicator of number of ships remaining
98 *surf_rock[NROCKS], // THE ROCKS
99 *surf_font_big; // The big font
101 struct shape rock_shapes[NROCKS];
105 // Structure global variables
106 struct enginedots edot[MAXENGINEDOTS], *dotptr = edot;
107 struct rock_struct rock[MAXROCKS], *rockptr = rock;
108 struct black_point_struct black_point[MAXBLACKPOINTS], *blackptr = black_point;
109 struct bangdots bdot[MAXBANGDOTS], *bdotptr = bdot;
110 struct spacedot sdot[MAXSPACEDOTS];
112 // Other global variables
114 char *initerror = "";
116 struct shape shipshape;
117 float shipx,shipy = 240.0; // X position, 0..XSIZE
118 float shipdx,shipdy; // Change in X position per tick.
119 float rockrate,rockspeed;
120 float movementrate; // this controls the speed of everything that moves.
124 int nships,score,initticks,ticks_since_last, last_ticks;
128 int sound_flag = 1, music_flag = 0;
129 int tail_plume = 0; // display big engine at the back?
130 int friction = 0; // should there be friction?
131 float fadetimer = 0, faderate;
133 int pausedown = 0, paused = 0;
135 // bangdot start (bd1) and end (bd2) position:
136 int bd1 = 0, bd2 = 0;
146 enum states state = TITLE_PAGE;
147 float state_timeout = 600.0;
151 "Press SPACE to start",
152 "http://qualdan.com/vor/"
155 int bangdotlife, nbangdots;
156 Uint16 heatcolor[W*3];
160 extern int optind, opterr, optopt;
162 float dist_sq(float x1, float y1, float x2, float y2)
164 return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
167 // ************************************* FUNCS
171 return (float)random()/(float)RAND_MAX;
177 for(i = 0; i<MAXENGINEDOTS; i++) {
185 for(i = 0; i<MAXSPACEDOTS; i++) {
188 sdot[i].x = rnd()*(XSIZE-5);
189 sdot[i].y = rnd()*(YSIZE-5);
195 intensity = (int)(r*180 + 70);
196 sdot[i].color = SDL_MapRGB(surf_screen->format,intensity,intensity,intensity);
202 makebangdots(int xbang, int ybang, int dx, int dy, SDL_Surface *s, int power) {
204 // TODO - stop generating dots after a certain amount of time has passed, to cope with slower CPUs.
205 // TODO - generate and display dots in a circular buffer
212 begin_generate = SDL_GetTicks();
215 rawpixel = (Uint16 *) s->pixels;
217 //for(n = 0; n <= power/2; n++) {
221 for(x = 0; x<s->w; x++) {
222 for(y = 0; y<s->h; y++) {
223 c = rawpixel[s->pitch/2*y + x];
224 if(c && c != s->format->colorkey) {
226 theta = rnd()*M_PI*2;
230 bdot[bd2].dx = (power/50.0)*45.0*cos(theta)*r + dx;
231 bdot[bd2].dy = (power/50.0)*45.0*sin(theta)*r + dy;
232 bdot[bd2].x = x + xbang;
233 bdot[bd2].y = y + ybang;
235 // Replace the last few bang dots with the pixels from the exploding object
236 bdot[bd2].c = (endcount>0)?c:0;
237 bdot[bd2].life = 100;
238 bdot[bd2].decay = rnd()*3 + 1;
239 bdot[bd2].active = 1;
244 // If the circular buffer is filled, who cares? They've had their chance.
245 //if(bd2 == bd1-1) goto exitloop;
251 if(SDL_GetTicks() - begin_generate > 7) endcount++;
254 SDL_UnlockSurface(s);
259 draw_bang_dots(SDL_Surface *s) {
263 rawpixel = (Uint16 *) s->pixels;
267 for(i = bd1; (bd1 <= bd2)?(i<bd2):(i >= bd1 && i < bd2); last_i = ++i) {
271 if(bdot[i].x <= 0 || bdot[i].x >= XSIZE || bdot[i].y <= 0 || bdot[i].y >= YSIZE) {
272 // If the dot has drifted outside the perimeter, kill it
280 rawpixel[(int)(s->pitch/2*(int)(bdot[i].y)) + (int)(bdot[i].x)] = bdot[i].c ? bdot[i].c : heatcolor[(int)(bdot[i].life*3)];
281 bdot[i].life -= bdot[i].decay;
282 bdot[i].x += bdot[i].dx*movementrate;
283 bdot[i].y += bdot[i].dy*movementrate + yscroll;
303 draw_space_dots(SDL_Surface *s) {
306 rawpixel = (Uint16 *) s->pixels;
308 for(i = 0; i<MAXSPACEDOTS; i++) {
312 rawpixel[(int)(s->pitch/2*(int)sdot[i].y) + (int)(sdot[i].x)] = sdot[i].color;
313 sdot[i].x += sdot[i].dx*movementrate;
314 sdot[i].y += yscroll;
315 if(sdot[i].y > YSIZE) {
317 } else if(sdot[i].y < 0) {
327 draw_engine_dots(SDL_Surface *s) {
330 rawpixel = (Uint16 *) s->pixels;
332 for(i = 0; i<MAXENGINEDOTS; i++) {
334 edot[i].x += edot[i].dx*movementrate;
335 edot[i].y += edot[i].dy*movementrate + yscroll;
336 if((edot[i].life -= movementrate*3)<0 || edot[i].y<0 || edot[i].y>YSIZE) {
338 } else if(edot[i].x<0 || edot[i].x>XSIZE) {
342 heatindex = edot[i].life * 6;
343 //rawpixel[(int)(s->pitch/2*(int)(edot[i].y)) + (int)(edot[i].x)] = lifecolor[(int)(edot[i].life)];
344 rawpixel[(int)(s->pitch/2*(int)(edot[i].y)) + (int)(edot[i].x)] = heatindex>3*W ? heatcolor[3*W-1] : heatcolor[heatindex];
351 create_engine_dots(int newdots) {
353 double theta,r,dx,dy;
355 if(!tail_plume) return;
357 if(state == GAMEPLAY) {
358 for(i = 0; i<newdots*movementrate; i++) {
359 if(dotptr->active == 0) {
360 theta = rnd()*M_PI*2;
366 dotptr->x = shipx + surf_ship->w/2-14;
367 dotptr->y = shipy + surf_ship->h/2 + (rnd()-0.5)*5-1;
368 dotptr->dx = 10*(dx-1.5) + shipdx;
369 dotptr->dy = 1*dy + shipdy;
370 dotptr->life = 45 + rnd(1)*5;
373 if(dotptr-edot >= MAXENGINEDOTS) {
382 create_engine_dots2(int newdots, int m) {
384 double theta, theta2, dx, dy, adx, ady;
386 // Don't create fresh engine dots when
387 // the game is not being played and a demo is not beng shown
388 if(state != GAMEPLAY) return;
390 for(i = 0; i<newdots; i++) {
391 if(dotptr->active == 0) {
392 theta = rnd()*M_PI*2;
393 theta2 = rnd()*M_PI*2;
395 dx = cos(theta) * fabs(cos(theta2));
396 dy = sin(theta) * fabs(cos(theta2));
402 dotptr->x = shipx + surf_ship->w/2 + (rnd()-0.5)*3;
403 dotptr->y = shipy + surf_ship->h/2 + (rnd()-0.5)*3;
408 dotptr->dx = -20*adx + shipdx;
409 dotptr->dy = 2*dy + shipdy;
410 dotptr->life = 60 * adx;
413 dotptr->dx = 2*dx + shipdx;
414 dotptr->dy = -20*ady + shipdy;
415 dotptr->life = 60 * ady;
419 dotptr->dx = 20*adx + shipdx;
420 dotptr->dy = 2*dy + shipdy;
421 dotptr->life = 60 * adx;
424 dotptr->dx = 2*dx + shipdx;
425 dotptr->dy = 20*ady + shipdy;
426 dotptr->life = 60 * ady;
430 if(dotptr-edot >= MAXENGINEDOTS) {
438 drawdots(SDL_Surface *s) {
442 // Draw the background stars aka space dots
445 // Draw the score when playing the game or whn the game is freshly over
446 if(1 || state == GAMEPLAY || state == DEAD_PAUSE || state == GAME_OVER ) {
447 SDL_UnlockSurface(s);
449 snprintscore_line(topline, 50, score);
450 SFont_Write(s,g_font,XSIZE-250,0,topline);
455 // Draw all the engine dots
458 // Create more engine dots comin out da back
459 if(!gameover) create_engine_dots(200);
461 // Create engine dots out the side we're moving from
462 for(m = 0; m<4; m++) {
463 if(maneuver & 1<<m) { // 'maneuver' is a bit field
464 create_engine_dots2(80,m);
468 // Draw all outstanding bang dots
469 //if(bangdotlife-- > 0)
472 SDL_UnlockSurface(s);
475 char a[MAX_PATH_LEN];
477 init(int fullscreen) {
484 // Where are our data files?
485 if(!find_files()) exit(1);
486 read_high_score_table();
489 // Initialize SDL with audio and video
490 if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0) {
492 printf ("Can't open sound, starting without it\n");
496 atexit(SDL_CloseAudio);
497 sound_flag = init_sound();
500 // Initialize with video only
501 CONDERROR(SDL_Init(SDL_INIT_VIDEO) != 0);
507 // Attempt to get the required video size
508 flag = SDL_DOUBLEBUF | SDL_HWSURFACE;
509 if(fullscreen) flag |= SDL_FULLSCREEN;
510 surf_screen = SDL_SetVideoMode(XSIZE,YSIZE,16,flag);
512 // Set the title bar text
513 SDL_WM_SetCaption("Variations on Rockdodger", "VoR");
515 NULLERROR(surf_screen);
517 // Set the heat color from the range 0 (cold) to 300 (blue-white)
518 for(i = 0; i<W*3; i++) {
519 heatcolor[i] = SDL_MapRGB(
521 (i<W)?(i*M/W):(M),(i<W)?0:(i<2*W)?((i-W)*M/W):M,(i<2*W)?0:((i-W)*M/W) // Got that?
526 NULLERROR(temp = IMG_Load(add_path("banners/variations.png")));
527 NULLERROR(surf_b_variations = SDL_DisplayFormat(temp));
529 NULLERROR(temp = IMG_Load(add_path("banners/on.png")));
530 NULLERROR(surf_b_on = SDL_DisplayFormat(temp));
532 NULLERROR(temp = IMG_Load(add_path("banners/rockdodger.png")));
533 NULLERROR(surf_b_rockdodger = SDL_DisplayFormat(temp));
535 NULLERROR(temp = IMG_Load(add_path("banners/game.png")));
536 NULLERROR(surf_b_game = SDL_DisplayFormat(temp));
538 NULLERROR(temp = IMG_Load(add_path("banners/over.png")));
539 NULLERROR(surf_b_over = SDL_DisplayFormat(temp));
541 surf_font_big = IMG_Load(add_path(BIG_FONT_FILE));
542 g_font = SFont_InitFont(surf_font_big);
544 // Load the spaceship graphic.
545 NULLERROR(temp = IMG_Load(add_path("sprites/ship.png")));
546 NULLERROR(surf_ship = SDL_DisplayFormat(temp));
547 get_shape(surf_ship, &shipshape);
549 // Load the life indicator (small ship) graphic.
550 NULLERROR(temp = IMG_Load(add_path("indicators/life.png")));
551 NULLERROR(surf_life = SDL_DisplayFormat(temp));
553 // Create the array of black points;
554 SDL_LockSurface(surf_ship);
555 raw_pixels = (Uint16 *) surf_ship->pixels;
556 for(i = 0; i<surf_ship->w; i++) {
557 for(j = 0; j<surf_ship->h; j++) {
558 if(raw_pixels[j*(surf_ship->pitch)/2 + i] == 0) {
566 SDL_UnlockSurface(surf_ship);
571 // Load all our lovely rocks
572 for(i = 0; i<NROCKS; i++) {
574 snprintf(a,MAX_PATH_LEN,add_path("sprites/rock%02d.png"),i);
575 NULLERROR(temp = IMG_Load(a));
576 NULLERROR(surf_rock[i] = SDL_DisplayFormat(temp));
577 get_shape(surf_rock[i], &rock_shapes[i]);
580 // Remove the mouse cursor
582 SDL_ShowCursor(SDL_DISABLE);
592 struct black_point_struct *p;
596 float fadegame,fadeover;
605 // Draw a fully black background
606 SDL_FillRect(surf_screen,NULL,0);
608 // Draw the background dots
609 drawdots(surf_screen);
612 if(!gameover && state == GAMEPLAY ) {
613 src.w = surf_ship->w;
614 src.h = surf_ship->h;
619 SDL_BlitSurface(surf_ship,&src,surf_screen,&dest);
622 // Draw all the rocks, in all states
623 for(i = 0; i<MAXROCKS; i++) {
626 src.w = rock[i].image->w;
627 src.h = rock[i].image->h;
630 dest.x = (int) rock[i].x;
631 dest.y = (int) rock[i].y;
634 SDL_BlitSurface(rock[i].image,&src,surf_screen,&dest);
639 // If it's game over, show the game over graphic in the dead centre
642 if(fadetimer<3.0/faderate) {
643 fadegame = fadetimer/(3.0/faderate);
648 if(fadetimer<3.0/faderate) {
650 } else if(fadetimer<6.0/faderate) {
651 fadeover = ((3.0/faderate)-fadetimer)/(6.0/faderate);
656 src.w = surf_b_game->w;
657 src.h = surf_b_game->h;
660 dest.x = (XSIZE-src.w)/2;
661 dest.y = (YSIZE-src.h)/2-40;
662 SDL_SetAlpha(surf_b_game, SDL_SRCALPHA, (int)(fadegame*(200 + 55*cos(fadetimer += movementrate/1.0))));
663 SDL_BlitSurface(surf_b_game,&src,surf_screen,&dest);
665 src.w = surf_b_over->w;
666 src.h = surf_b_over->h;
669 dest.x = (XSIZE-src.w)/2;
670 dest.y = (YSIZE-src.h)/2 + 40;
671 SDL_SetAlpha(surf_b_over, SDL_SRCALPHA, (int)(fadeover*(200 + 55*sin(fadetimer))));
672 SDL_BlitSurface(surf_b_over,&src,surf_screen,&dest);
677 src.w = surf_b_variations->w;
678 src.h = surf_b_variations->h;
681 dest.x = (XSIZE-src.w)/2 + cos(fadetimer/6.5)*10;
682 dest.y = (YSIZE/2-src.h)/2 + sin(fadetimer/5.0)*10;
683 SDL_SetAlpha(surf_b_variations, SDL_SRCALPHA, (int)(200 + 55*sin(fadetimer += movementrate/2.0)));
684 SDL_BlitSurface(surf_b_variations,&src,surf_screen,&dest);
686 src.w = surf_b_on->w;
687 src.h = surf_b_on->h;
690 dest.x = (XSIZE-src.w)/2 + cos((fadetimer + 1.0)/6.5)*10;
691 dest.y = (YSIZE/2-src.h)/2 + surf_b_variations->h + 20 + sin((fadetimer + 1.0)/5.0)*10;
692 SDL_SetAlpha(surf_b_on, SDL_SRCALPHA, (int)(200 + 55*sin(fadetimer-1.0)));
693 SDL_BlitSurface(surf_b_on,&src,surf_screen,&dest);
695 src.w = surf_b_rockdodger->w;
696 src.h = surf_b_rockdodger->h;
699 dest.x = (XSIZE-src.w)/2 + cos((fadetimer + 2.0)/6.5)*10;
700 dest.y = (YSIZE/2-src.h)/2 + surf_b_variations->h + surf_b_on->h + 40 + sin((fadetimer + 2.0)/5)*10;
701 SDL_SetAlpha(surf_b_rockdodger, SDL_SRCALPHA, (int)(200 + 55*sin(fadetimer-2.0)));
702 SDL_BlitSurface(surf_b_rockdodger,&src,surf_screen,&dest);
704 text = "Version " VERSION;
705 x = (XSIZE-SFont_TextWidth(g_font,text))/2 + sin(fadetimer/4.5)*10;
706 SFont_Write(surf_screen,g_font,x,YSIZE-50 + sin(fadetimer/2)*5,text);
708 text = sequence[(int)(fadetimer/40)%NSEQUENCE];
709 //text = "Press SPACE to start!";
710 x = (XSIZE-SFont_TextWidth(g_font,text))/2 + cos(fadetimer/4.5)*10;
711 SFont_Write(surf_screen,g_font,x,YSIZE-100 + cos(fadetimer/3)*5,text);
714 case HIGH_SCORE_ENTRY:
716 if(!process_score_input()) { // done inputting name
718 // Change state to briefly show high scores page
719 state = HIGH_SCORE_DISPLAY;
722 // Write the high score table to the file
723 write_high_score_table();
725 // Play the title page tune
729 case HIGH_SCORE_DISPLAY:
730 // Display de list o high scores mon.
731 display_scores(surf_screen, 150,50);
735 ; // no action necessary
738 if(!gameover && state == GAMEPLAY) {
739 for(i=0; i<MAXROCKS; i++) {
741 if(collide(shipx-rock[i].x, shipy-rock[i].y, rock[i].shape, &shipshape))
746 SDL_LockSurface(surf_screen);
747 raw_pixels = (Uint16 *) surf_screen->pixels;
748 // Check that the black points on the ship are
749 // still black, and not covered up by rocks.
750 for(p = black_point; p<blackptr; p++) {
751 offset = surf_screen->pitch/2 * (p->y + (int)shipy) + p->x + (int)shipx;
752 if(raw_pixels[offset]) {
757 SDL_UnlockSurface(surf_screen);
761 // Draw all the little ships
762 if(state == GAMEPLAY || state == DEAD_PAUSE || state == GAME_OVER)
763 for(i = 0; i<nships-1; i++) {
764 src.w = surf_life->w;
765 src.h = surf_life->h;
768 dest.x = (i + 1)*(src.w + 10);
770 SDL_BlitSurface(surf_life,&src,surf_screen,&dest);
776 n = SDL_GetTicks()-initticks;
778 ticks_since_last = n-score;
782 ticks_since_last = SDL_GetTicks()-last_ticks;
783 last_ticks = SDL_GetTicks();
784 if(ticks_since_last>200 || ticks_since_last<0) {
788 movementrate = ticks_since_last/50.0;
789 if(state == GAMEPLAY) {
790 score += ticks_since_last;
794 // Update the surface
795 SDL_Flip(surf_screen);
809 // Count down the game loop timer, and change state when it gets to zero or less;
811 if((state_timeout -= movementrate*3) < 0) {
814 // Create a new ship and start all over again
820 state = HIGH_SCORE_ENTRY;
821 state_timeout = 5.0e6;
822 if(new_high_score(score)) {
824 SDL_EnableUNICODE(1);
825 while(SDL_PollEvent(&e))
828 state = HIGH_SCORE_DISPLAY;
832 case HIGH_SCORE_DISPLAY:
834 state_timeout = 500.0;
836 case HIGH_SCORE_ENTRY:
837 // state = TITLE_PAGE;
839 // state_timeout = 100.0;
842 state = HIGH_SCORE_DISPLAY;
843 state_timeout = 200.0;
846 ; // no action necessary
849 if(state == DEAD_PAUSE) {
853 if(state_timeout < DEAD_PAUSE_LENGTH - 20.0) {
854 blast_radius = BLAST_RADIUS * 1.3;
857 blast_radius = BLAST_RADIUS * (DEAD_PAUSE_LENGTH - state_timeout) / 20.0;
861 if(shipx < 60) shipx = 60;
862 for(i = 0; i<MAXROCKS; i++ ) {
864 if(rock[i].x <= 0) continue;
866 // This makes it so your explosion from dying magically doesn't leave
867 // any rocks that aren't moving much on the x axis. After the first
868 // 20 tics, only rocks that are barely moving will be pushed.
869 if(fixonly && (!rock[i].dead || rock[i].dx < -4 || rock[i].dx > 3)) {
873 dx = rock[i].x - shipx;
874 dy = rock[i].y - shipy;
876 n = sqrt(dx*dx + dy*dy);
877 if(n < blast_radius) {
879 rock[i].dx += rockrate*(dx+30)/n;
880 rock[i].dy += rockrate*dy/n;
887 if(--countdown <= 0 && (rnd()*100.0<(rockrate += 0.025))) {
890 if(rockptr-rock >= MAXROCKS) {
893 if(!rockptr->active) {
894 rockptr->x = (float)XSIZE;
895 rockptr->dx = -(rockspeed)*(1 + rnd());
896 rockptr->dy = rnd()-0.5;
897 rockptr->type_number = random() % NROCKS;
898 rockptr->image = surf_rock[rockptr->type_number];// [random()%NROCKS];
899 rockptr->shape = &rock_shapes[rockptr->type_number];
901 rockptr->y = rnd()*(YSIZE + rockptr->image->h);
903 if(movementrate>0.1) {
904 countdown = (int)(ROCKRATE/movementrate);
912 shipdx *= pow((double)0.9,(double)movementrate);
913 shipdy *= pow((double)0.9,(double)movementrate);
914 // if(abs(shipdx)<0.00001) shipdx = 0;
915 // if(abs(shipdy)<0.00001) shipdy = 0;
919 shipx += shipdx*movementrate;
920 shipy += shipdy*movementrate;
923 yscroll = shipy - (YSIZE / 2);
924 yscroll += shipdy * 25;
926 yscroll = ((scrollvel * (12 - movementrate)) + (yscroll * movementrate)) / 12;
928 yscroll = yscroll*movementrate;
931 // Move all the rocks
932 for(i = 0; i < MAXROCKS; i++) {
934 rock[i].x += rock[i].dx*movementrate;
935 rock[i].y += rock[i].dy*movementrate + yscroll;
936 if(rock[i].y > YSIZE || rock[i].y < -rock[i].image->h) {
942 rock[i].y = (YSIZE - rock[i].image->h) - rock[i].y;
943 rock[i].y += (rock[i].dy*movementrate + yscroll) * 1.01;
946 if(rock[i].x < -rock[i].image->w || rock[i].x > XSIZE) {
955 if(shipx<0 || shipx>XSIZE-surf_ship->w) {
956 // BOUNCE from left and right wall
957 shipx -= shipdx*movementrate;
962 if(shipy<0 || shipy>YSIZE-surf_ship->h) {
963 // BOUNCE from top and bottom wall
969 if(draw() && state == GAMEPLAY) {
970 // Play the explosion sound
972 makebangdots(shipx,shipy,shipdx,shipdy,surf_ship,30);
976 state_timeout = 200.0;
978 faderate = movementrate;
982 state_timeout = DEAD_PAUSE_LENGTH;
989 keystate = SDL_GetKeyState(NULL);
991 if(state != HIGH_SCORE_ENTRY && (keystate[SDLK_q] || keystate[SDLK_ESCAPE])) {
995 if(keystate[SDLK_SPACE] && (state == HIGH_SCORE_DISPLAY || state == TITLE_PAGE)) {
997 for(i = 0; i<MAXROCKS; i++ ) {
1021 keystate = SDL_GetKeyState(NULL);
1024 if(state == GAMEPLAY) {
1028 if(keystate[SDLK_UP] | keystate[SDLK_c]) { shipdy -= 1.5*movementrate; maneuver |= 1<<3;}
1029 if(keystate[SDLK_DOWN] | keystate[SDLK_t]) { shipdy += 1.5*movementrate; maneuver |= 1<<1;}
1030 if(keystate[SDLK_LEFT] | keystate[SDLK_h]) { shipdx -= 1.5*movementrate; maneuver |= 1<<2;}
1031 if(keystate[SDLK_RIGHT] | keystate[SDLK_n]) { shipdx += 1.5*movementrate; maneuver |= 1;}
1032 if(keystate[SDLK_3]) { SDL_SaveBMP(surf_screen, "snapshot.bmp"); }
1035 if(keystate[SDLK_p] | keystate[SDLK_s]) {
1049 } else if(state == GAME_OVER) {
1050 if(keystate[SDLK_SPACE]) {
1058 main(int argc, char **argv) {
1059 int i, x, fullscreen;
1067 while ((x = getopt(argc,argv,"efhmps")) >= 0) {
1072 case 'f': // fullscreen
1076 printf("Variations on RockDodger\n"
1077 " -e big tail [E]ngine\n"
1078 " -f [F]ull screen\n"
1079 " -h this [H]elp message\n"
1080 " -m enable [M]usic\n"
1081 " -p original [P]hysics (friction)\n"
1082 " -s [S]ilent (no sound)\n");
1087 case 'p': // physics
1097 if(init(fullscreen)) {
1098 printf ("ta: '%s'\n",initerror);
1102 for(i = 0; i<MAXROCKS; i++) {
1108 initticks = SDL_GetTicks();