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
33 #include <SDL/SDL_image.h>
42 #define CONDERROR(a) if((a)) {initerror = strdup(SDL_GetError());return 1;}
43 #define NULLERROR(a) CONDERROR((a) == NULL)
45 // ************************************* STRUCTS
47 // Array of black pixel coordinates. This is scanned
48 // every frame to see if it's still black, and as
49 // soon as it isn't we BLOW UP
52 int dead; // has been blown out of the way
53 // to make room for a new ship appearing.
57 struct black_point_struct {
61 // Bang dots have the same colour as shield dots.
62 // Bang dots get darker as they age.
63 // Some are coloured the same as the ex-ship.
65 Uint16 c; // when zero, use heatcolor[bangdotlife]
66 float life; // When reduced to 0, set active = 0
68 float decay;// Amount by which to reduce life each time dot is drawn
71 // Engine dots stream out the back of the ship, getting darker as they go.
74 // The life of an engine dot
75 // is a number starting at between 0 and 50 and counting backward.
76 float life; // When reduced to 0, set active = 0
79 // Space dots are harmless background items
80 // All are active. When one falls off the edge, another is created at the start.
85 // ************************************* VARS
86 // SDL_Surface global variables
88 *surf_screen, // Screen
89 *surf_b_variations, // "variations" banner
90 *surf_b_on, // "on" banner
91 *surf_b_rockdodger, // "rockdodger" banner
92 *surf_b_game, // Title element "game"
93 *surf_b_over, // Title element "over"
94 *surf_ship, // Spaceship element
95 *surf_life, // Indicator of number of ships remaining
96 *surf_rock[NROCKS], // THE ROCKS
97 *surf_font_big; // The big font
101 // Structure global variables
102 struct enginedots edot[MAXENGINEDOTS], *dotptr = edot;
103 struct rock_struct rock[MAXROCKS], *rockptr = rock;
104 struct black_point_struct black_point[MAXBLACKPOINTS], *blackptr = black_point;
105 struct bangdots bdot[MAXBANGDOTS], *bdotptr = bdot;
106 struct spacedot sdot[MAXSPACEDOTS];
108 // Other global variables
110 char *initerror = "";
112 float shipx,shipy = 240.0; // X position, 0..XSIZE
113 float shipdx,shipdy; // Change in X position per tick.
114 float rockrate,rockspeed;
115 float movementrate; // this controls the speed of everything that moves.
119 int nships,score,initticks,ticks_since_last, last_ticks;
123 int sound_flag = 1, music_flag = 0;
124 int tail_plume = 0; // display big engine at the back?
125 int friction = 0; // should there be friction?
126 float fadetimer = 0, faderate;
128 int pausedown = 0, paused = 0;
130 // bangdot start (bd1) and end (bd2) position:
131 int bd1 = 0, bd2 = 0;
141 enum states state = TITLE_PAGE;
142 float state_timeout = 600.0;
146 "Press SPACE to start",
147 "http://qualdan.com/vor/"
150 int bangdotlife, nbangdots;
151 Uint16 heatcolor[W*3];
155 extern int optind, opterr, optopt;
157 float dist_sq(float x1, float y1, float x2, float y2)
159 return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
162 // ************************************* FUNCS
166 return (float)random()/(float)RAND_MAX;
172 for(i = 0; i<MAXENGINEDOTS; i++) {
180 for(i = 0; i<MAXSPACEDOTS; i++) {
183 sdot[i].x = rnd()*(XSIZE-5);
184 sdot[i].y = rnd()*(YSIZE-5);
190 intensity = (int)(r*180 + 70);
191 sdot[i].color = SDL_MapRGB(surf_screen->format,intensity,intensity,intensity);
197 makebangdots(int xbang, int ybang, int dx, int dy, SDL_Surface *s, int power) {
199 // TODO - stop generating dots after a certain amount of time has passed, to cope with slower CPUs.
200 // TODO - generate and display dots in a circular buffer
207 begin_generate = SDL_GetTicks();
210 rawpixel = (Uint16 *) s->pixels;
212 //for(n = 0; n <= power/2; n++) {
216 for(x = 0; x<s->w; x++) {
217 for(y = 0; y<s->h; y++) {
218 c = rawpixel[s->pitch/2*y + x];
219 if(c && c != SDL_MapRGB(s->format,0,255,0)) {
221 theta = rnd()*M_PI*2;
225 bdot[bd2].dx = (power/50.0)*45.0*cos(theta)*r + dx;
226 bdot[bd2].dy = (power/50.0)*45.0*sin(theta)*r + dy;
227 bdot[bd2].x = x + xbang;
228 bdot[bd2].y = y + ybang;
230 // Replace the last few bang dots with the pixels from the exploding object
231 bdot[bd2].c = (endcount>0)?c:0;
232 bdot[bd2].life = 100;
233 bdot[bd2].decay = rnd()*3 + 1;
234 bdot[bd2].active = 1;
239 // If the circular buffer is filled, who cares? They've had their chance.
240 //if(bd2 == bd1-1) goto exitloop;
246 if(SDL_GetTicks() - begin_generate > 7) endcount++;
249 SDL_UnlockSurface(s);
254 draw_bang_dots(SDL_Surface *s) {
258 rawpixel = (Uint16 *) s->pixels;
262 for(i = bd1; (bd1 <= bd2)?(i<bd2):(i >= bd1 && i < bd2); last_i = ++i) {
266 if(bdot[i].x <= 0 || bdot[i].x >= XSIZE || bdot[i].y <= 0 || bdot[i].y >= YSIZE) {
267 // If the dot has drifted outside the perimeter, kill it
275 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)];
276 bdot[i].life -= bdot[i].decay;
277 bdot[i].x += bdot[i].dx*movementrate;
278 bdot[i].y += bdot[i].dy*movementrate + yscroll;
298 draw_space_dots(SDL_Surface *s) {
301 rawpixel = (Uint16 *) s->pixels;
303 for(i = 0; i<MAXSPACEDOTS; i++) {
307 rawpixel[(int)(s->pitch/2*(int)sdot[i].y) + (int)(sdot[i].x)] = sdot[i].color;
308 sdot[i].x += sdot[i].dx*movementrate;
309 sdot[i].y += yscroll;
310 if(sdot[i].y > YSIZE) {
312 } else if(sdot[i].y < 0) {
322 draw_engine_dots(SDL_Surface *s) {
325 rawpixel = (Uint16 *) s->pixels;
327 for(i = 0; i<MAXENGINEDOTS; i++) {
329 edot[i].x += edot[i].dx*movementrate;
330 edot[i].y += edot[i].dy*movementrate + yscroll;
331 if((edot[i].life -= movementrate*3)<0 || edot[i].y<0 || edot[i].y>YSIZE) {
333 } else if(edot[i].x<0 || edot[i].x>XSIZE) {
337 heatindex = edot[i].life * 6;
338 //rawpixel[(int)(s->pitch/2*(int)(edot[i].y)) + (int)(edot[i].x)] = lifecolor[(int)(edot[i].life)];
339 rawpixel[(int)(s->pitch/2*(int)(edot[i].y)) + (int)(edot[i].x)] = heatindex>3*W ? heatcolor[3*W-1] : heatcolor[heatindex];
346 create_engine_dots(int newdots) {
348 double theta,r,dx,dy;
350 if(!tail_plume) return;
352 if(state == GAMEPLAY) {
353 for(i = 0; i<newdots*movementrate; i++) {
354 if(dotptr->active == 0) {
355 theta = rnd()*M_PI*2;
361 dotptr->x = shipx + surf_ship->w/2-14;
362 dotptr->y = shipy + surf_ship->h/2 + (rnd()-0.5)*5-1;
363 dotptr->dx = 10*(dx-1.5) + shipdx;
364 dotptr->dy = 1*dy + shipdy;
365 dotptr->life = 45 + rnd(1)*5;
368 if(dotptr-edot >= MAXENGINEDOTS) {
377 create_engine_dots2(int newdots, int m) {
379 double theta, theta2, dx, dy, adx, ady;
381 // Don't create fresh engine dots when
382 // the game is not being played and a demo is not beng shown
383 if(state != GAMEPLAY) return;
385 for(i = 0; i<newdots; i++) {
386 if(dotptr->active == 0) {
387 theta = rnd()*M_PI*2;
388 theta2 = rnd()*M_PI*2;
390 dx = cos(theta) * fabs(cos(theta2));
391 dy = sin(theta) * fabs(cos(theta2));
397 dotptr->x = shipx + surf_ship->w/2 + (rnd()-0.5)*3;
398 dotptr->y = shipy + surf_ship->h/2 + (rnd()-0.5)*3;
403 dotptr->dx = -20*adx + shipdx;
404 dotptr->dy = 2*dy + shipdy;
405 dotptr->life = 60 * adx;
408 dotptr->dx = 2*dx + shipdx;
409 dotptr->dy = -20*ady + shipdy;
410 dotptr->life = 60 * ady;
414 dotptr->dx = 20*adx + shipdx;
415 dotptr->dy = 2*dy + shipdy;
416 dotptr->life = 60 * adx;
419 dotptr->dx = 2*dx + shipdx;
420 dotptr->dy = 20*ady + shipdy;
421 dotptr->life = 60 * ady;
425 if(dotptr-edot >= MAXENGINEDOTS) {
433 drawdots(SDL_Surface *s) {
437 // Draw the background stars aka space dots
440 // Draw the score when playing the game or whn the game is freshly over
441 if(1 || state == GAMEPLAY || state == DEAD_PAUSE || state == GAME_OVER ) {
442 SDL_UnlockSurface(s);
444 snprintscore_line(topline, 50, score);
445 SFont_Write(s,g_font,XSIZE-250,0,topline);
450 // Draw all the engine dots
453 // Create more engine dots comin out da back
454 if(!gameover) create_engine_dots(200);
456 // Create engine dots out the side we're moving from
457 for(m = 0; m<4; m++) {
458 if(maneuver & 1<<m) { // 'maneuver' is a bit field
459 create_engine_dots2(80,m);
463 // Draw all outstanding bang dots
464 //if(bangdotlife-- > 0)
467 SDL_UnlockSurface(s);
471 init(int fullscreen) {
478 // Where are our data files?
479 if(!find_files()) exit(1);
480 read_high_score_table();
483 // Initialize SDL with audio and video
484 if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0) {
486 printf ("Can't open sound, starting without it\n");
490 atexit(SDL_CloseAudio);
491 sound_flag = init_sound();
494 // Initialize with video only
495 CONDERROR(SDL_Init(SDL_INIT_VIDEO) != 0);
501 // Attempt to get the required video size
502 flag = SDL_DOUBLEBUF | SDL_HWSURFACE;
503 if(fullscreen) flag |= SDL_FULLSCREEN;
504 surf_screen = SDL_SetVideoMode(XSIZE,YSIZE,16,flag);
506 // Set the title bar text
507 SDL_WM_SetCaption("Variations on Rockdodger", "VoR");
509 NULLERROR(surf_screen);
511 // Set the heat color from the range 0 (cold) to 300 (blue-white)
512 for(i = 0; i<W*3; i++) {
513 heatcolor[i] = SDL_MapRGB(
515 (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?
520 NULLERROR(temp = IMG_Load(add_path("banners/variations.png")));
521 NULLERROR(surf_b_variations = SDL_DisplayFormat(temp));
523 NULLERROR(temp = IMG_Load(add_path("banners/on.png")));
524 NULLERROR(surf_b_on = SDL_DisplayFormat(temp));
526 NULLERROR(temp = IMG_Load(add_path("banners/rockdodger.png")));
527 NULLERROR(surf_b_rockdodger = SDL_DisplayFormat(temp));
529 NULLERROR(temp = IMG_Load(add_path("banners/game.png")));
530 NULLERROR(surf_b_game = SDL_DisplayFormat(temp));
532 NULLERROR(temp = IMG_Load(add_path("banners/over.png")));
533 NULLERROR(surf_b_over = SDL_DisplayFormat(temp));
535 surf_font_big = IMG_Load(add_path(BIG_FONT_FILE));
536 g_font = SFont_InitFont(surf_font_big);
538 // Load the spaceship graphic.
539 NULLERROR(temp = IMG_Load(add_path("sprites/ship.png")));
540 NULLERROR(surf_ship = SDL_DisplayFormat(temp));
542 // Load the life indicator (small ship) graphic.
543 NULLERROR(temp = IMG_Load(add_path("indicators/life.png")));
544 NULLERROR(surf_life = SDL_DisplayFormat(temp));
546 // Create the array of black points;
547 SDL_LockSurface(surf_ship);
548 raw_pixels = (Uint16 *) surf_ship->pixels;
549 for(i = 0; i<surf_ship->w; i++) {
550 for(j = 0; j<surf_ship->h; j++) {
551 if(raw_pixels[j*(surf_ship->pitch)/2 + i] == 0) {
559 SDL_UnlockSurface(surf_ship);
564 // Load all our lovely rocks
565 for(i = 0; i<NROCKS; i++) {
566 char a[MAX_PATH_LEN];
568 snprintf(a,MAX_PATH_LEN,add_path("sprites/rock%d.png"),i);
569 NULLERROR(temp = IMG_Load(a));
570 NULLERROR(surf_rock[i] = SDL_DisplayFormat(temp));
573 // Remove the mouse cursor
575 SDL_ShowCursor(SDL_DISABLE);
585 struct black_point_struct *p;
589 float fadegame,fadeover;
598 // Draw a fully black background
599 SDL_FillRect(surf_screen,NULL,0);
601 // Draw the background dots
602 drawdots(surf_screen);
605 if(!gameover && state == GAMEPLAY ) {
606 src.w = surf_ship->w;
607 src.h = surf_ship->h;
612 SDL_BlitSurface(surf_ship,&src,surf_screen,&dest);
615 // Draw all the rocks, in all states
616 for(i = 0; i<MAXROCKS; i++) {
619 src.w = rock[i].image->w;
620 src.h = rock[i].image->h;
623 dest.x = (int) rock[i].x;
624 dest.y = (int) rock[i].y;
627 SDL_BlitSurface(rock[i].image,&src,surf_screen,&dest);
632 // If it's game over, show the game over graphic in the dead centre
635 if(fadetimer<3.0/faderate) {
636 fadegame = fadetimer/(3.0/faderate);
641 if(fadetimer<3.0/faderate) {
643 } else if(fadetimer<6.0/faderate) {
644 fadeover = ((3.0/faderate)-fadetimer)/(6.0/faderate);
649 src.w = surf_b_game->w;
650 src.h = surf_b_game->h;
653 dest.x = (XSIZE-src.w)/2;
654 dest.y = (YSIZE-src.h)/2-40;
655 SDL_SetAlpha(surf_b_game, SDL_SRCALPHA, (int)(fadegame*(200 + 55*cos(fadetimer += movementrate/1.0))));
656 SDL_BlitSurface(surf_b_game,&src,surf_screen,&dest);
658 src.w = surf_b_over->w;
659 src.h = surf_b_over->h;
662 dest.x = (XSIZE-src.w)/2;
663 dest.y = (YSIZE-src.h)/2 + 40;
664 SDL_SetAlpha(surf_b_over, SDL_SRCALPHA, (int)(fadeover*(200 + 55*sin(fadetimer))));
665 SDL_BlitSurface(surf_b_over,&src,surf_screen,&dest);
670 src.w = surf_b_variations->w;
671 src.h = surf_b_variations->h;
674 dest.x = (XSIZE-src.w)/2 + cos(fadetimer/6.5)*10;
675 dest.y = (YSIZE/2-src.h)/2 + sin(fadetimer/5.0)*10;
676 SDL_SetAlpha(surf_b_variations, SDL_SRCALPHA, (int)(200 + 55*sin(fadetimer += movementrate/2.0)));
677 SDL_BlitSurface(surf_b_variations,&src,surf_screen,&dest);
679 src.w = surf_b_on->w;
680 src.h = surf_b_on->h;
683 dest.x = (XSIZE-src.w)/2 + cos((fadetimer + 1.0)/6.5)*10;
684 dest.y = (YSIZE/2-src.h)/2 + surf_b_variations->h + 20 + sin((fadetimer + 1.0)/5.0)*10;
685 SDL_SetAlpha(surf_b_on, SDL_SRCALPHA, (int)(200 + 55*sin(fadetimer-1.0)));
686 SDL_BlitSurface(surf_b_on,&src,surf_screen,&dest);
688 src.w = surf_b_rockdodger->w;
689 src.h = surf_b_rockdodger->h;
692 dest.x = (XSIZE-src.w)/2 + cos((fadetimer + 2.0)/6.5)*10;
693 dest.y = (YSIZE/2-src.h)/2 + surf_b_variations->h + surf_b_on->h + 40 + sin((fadetimer + 2.0)/5)*10;
694 SDL_SetAlpha(surf_b_rockdodger, SDL_SRCALPHA, (int)(200 + 55*sin(fadetimer-2.0)));
695 SDL_BlitSurface(surf_b_rockdodger,&src,surf_screen,&dest);
697 text = "Version " VERSION;
698 x = (XSIZE-SFont_TextWidth(g_font,text))/2 + sin(fadetimer/4.5)*10;
699 SFont_Write(surf_screen,g_font,x,YSIZE-50 + sin(fadetimer/2)*5,text);
701 text = sequence[(int)(fadetimer/40)%NSEQUENCE];
702 //text = "Press SPACE to start!";
703 x = (XSIZE-SFont_TextWidth(g_font,text))/2 + cos(fadetimer/4.5)*10;
704 SFont_Write(surf_screen,g_font,x,YSIZE-100 + cos(fadetimer/3)*5,text);
707 case HIGH_SCORE_ENTRY:
709 if(!process_score_input()) { // done inputting name
711 // Change state to briefly show high scores page
712 state = HIGH_SCORE_DISPLAY;
715 // Write the high score table to the file
716 write_high_score_table();
718 // Play the title page tune
722 case HIGH_SCORE_DISPLAY:
723 // Display de list o high scores mon.
724 display_scores(surf_screen, 150,50);
728 ; // no action necessary
731 if(!gameover && state == GAMEPLAY) {
732 SDL_LockSurface(surf_screen);
733 raw_pixels = (Uint16 *) surf_screen->pixels;
734 // Check that the black points on the ship are
735 // still black, and not covered up by rocks.
736 for(p = black_point; p<blackptr; p++) {
737 offset = surf_screen->pitch/2 * (p->y + (int)shipy) + p->x + (int)shipx;
738 if(raw_pixels[offset]) {
743 SDL_UnlockSurface(surf_screen);
746 // Draw all the little ships
747 if(state == GAMEPLAY || state == DEAD_PAUSE || state == GAME_OVER)
748 for(i = 0; i<nships-1; i++) {
749 src.w = surf_life->w;
750 src.h = surf_life->h;
753 dest.x = (i + 1)*(src.w + 10);
755 SDL_BlitSurface(surf_life,&src,surf_screen,&dest);
761 n = SDL_GetTicks()-initticks;
763 ticks_since_last = n-score;
767 ticks_since_last = SDL_GetTicks()-last_ticks;
768 last_ticks = SDL_GetTicks();
769 if(ticks_since_last>200 || ticks_since_last<0) {
773 movementrate = ticks_since_last/50.0;
774 if(state == GAMEPLAY) {
775 score += ticks_since_last;
779 // Update the surface
780 SDL_Flip(surf_screen);
794 // Count down the game loop timer, and change state when it gets to zero or less;
796 if((state_timeout -= movementrate*3) < 0) {
799 // Create a new ship and start all over again
805 state = HIGH_SCORE_ENTRY;
806 state_timeout = 5.0e6;
807 if(new_high_score(score)) {
809 SDL_EnableUNICODE(1);
810 while(SDL_PollEvent(&e))
813 state = HIGH_SCORE_DISPLAY;
817 case HIGH_SCORE_DISPLAY:
819 state_timeout = 500.0;
821 case HIGH_SCORE_ENTRY:
822 // state = TITLE_PAGE;
824 // state_timeout = 100.0;
827 state = HIGH_SCORE_DISPLAY;
828 state_timeout = 200.0;
831 ; // no action necessary
834 if(state == DEAD_PAUSE) {
838 if(state_timeout < DEAD_PAUSE_LENGTH - 20.0) {
839 blast_radius = BLAST_RADIUS * 1.3;
842 blast_radius = BLAST_RADIUS * (DEAD_PAUSE_LENGTH - state_timeout) / 20.0;
846 if(shipx < 60) shipx = 60;
847 for(i = 0; i<MAXROCKS; i++ ) {
849 if(rock[i].x <= 0) continue;
851 // This makes it so your explosion from dying magically doesn't leave
852 // any rocks that aren't moving much on the x axis. After the first
853 // 20 tics, only rocks that are barely moving will be pushed.
854 if(fixonly && (!rock[i].dead || rock[i].dx < -4 || rock[i].dx > 3)) {
858 dx = rock[i].x - shipx;
859 dy = rock[i].y - shipy;
861 n = sqrt(dx*dx + dy*dy);
862 if(n < blast_radius) {
864 rock[i].dx += rockrate*(dx+30)/n;
865 rock[i].dy += rockrate*dy/n;
872 if(--countdown <= 0 && (rnd()*100.0<(rockrate += 0.025))) {
875 if(rockptr-rock >= MAXROCKS) {
878 if(!rockptr->active) {
879 rockptr->x = (float)XSIZE;
880 rockptr->dx = -(rockspeed)*(1 + rnd());
881 rockptr->dy = rnd()-0.5;
882 rockptr->type_number = random() % NROCKS;
883 rockptr->image = surf_rock[rockptr->type_number];// [random()%NROCKS];
885 rockptr->y = rnd()*(YSIZE + rockptr->image->h);
887 if(movementrate>0.1) {
888 countdown = (int)(ROCKRATE/movementrate);
896 shipdx *= pow((double)0.9,(double)movementrate);
897 shipdy *= pow((double)0.9,(double)movementrate);
898 // if(abs(shipdx)<0.00001) shipdx = 0;
899 // if(abs(shipdy)<0.00001) shipdy = 0;
903 shipx += shipdx*movementrate;
904 shipy += shipdy*movementrate;
907 yscroll = shipy - (YSIZE / 2);
908 yscroll += shipdy * 25;
910 yscroll = ((scrollvel * (12 - movementrate)) + (yscroll * movementrate)) / 12;
912 yscroll = yscroll*movementrate;
915 // Move all the rocks
916 for(i = 0; i < MAXROCKS; i++) {
918 rock[i].x += rock[i].dx*movementrate;
919 rock[i].y += rock[i].dy*movementrate + yscroll;
920 if(rock[i].y > YSIZE || rock[i].y < -rock[i].image->h) {
926 rock[i].y = (YSIZE - rock[i].image->h) - rock[i].y;
927 rock[i].y += (rock[i].dy*movementrate + yscroll) * 1.01;
930 if(rock[i].x < -rock[i].image->w || rock[i].x > XSIZE) {
939 if(shipx<0 || shipx>XSIZE-surf_ship->w) {
940 // BOUNCE from left and right wall
941 shipx -= shipdx*movementrate;
946 if(shipy<0 || shipy>YSIZE-surf_ship->h) {
947 // BOUNCE from top and bottom wall
953 if(draw() && state == GAMEPLAY) {
954 // Play the explosion sound
956 makebangdots(shipx,shipy,shipdx,shipdy,surf_ship,30);
960 state_timeout = 200.0;
962 faderate = movementrate;
966 state_timeout = DEAD_PAUSE_LENGTH;
973 keystate = SDL_GetKeyState(NULL);
975 if(state != HIGH_SCORE_ENTRY && (keystate[SDLK_q] || keystate[SDLK_ESCAPE])) {
979 if(keystate[SDLK_SPACE] && (state == HIGH_SCORE_DISPLAY || state == TITLE_PAGE)) {
981 for(i = 0; i<MAXROCKS; i++ ) {
1005 keystate = SDL_GetKeyState(NULL);
1008 if(state == GAMEPLAY) {
1012 if(keystate[SDLK_UP] | keystate[SDLK_c]) { shipdy -= 1.5*movementrate; maneuver |= 1<<3;}
1013 if(keystate[SDLK_DOWN] | keystate[SDLK_t]) { shipdy += 1.5*movementrate; maneuver |= 1<<1;}
1014 if(keystate[SDLK_LEFT] | keystate[SDLK_h]) { shipdx -= 1.5*movementrate; maneuver |= 1<<2;}
1015 if(keystate[SDLK_RIGHT] | keystate[SDLK_n]) { shipdx += 1.5*movementrate; maneuver |= 1;}
1016 if(keystate[SDLK_3]) { SDL_SaveBMP(surf_screen, "snapshot.bmp"); }
1019 if(keystate[SDLK_p] | keystate[SDLK_s]) {
1033 } else if(state == GAME_OVER) {
1034 if(keystate[SDLK_SPACE]) {
1042 main(int argc, char **argv) {
1043 int i, x, fullscreen;
1051 while ((x = getopt(argc,argv,"efhmps")) >= 0) {
1056 case 'f': // fullscreen
1060 printf("Variations on RockDodger\n"
1061 " -e big tail [E]ngine\n"
1062 " -f [F]ull screen\n"
1063 " -h this [H]elp message\n"
1064 " -m enable [M]usic\n"
1065 " -p original [P]hysics (friction)\n"
1066 " -s [S]ilent (no sound)\n");
1071 case 'p': // physics
1081 if(init(fullscreen)) {
1082 printf ("ta: '%s'\n",initerror);
1086 for(i = 0; i<MAXROCKS; i++) {
1092 initticks = SDL_GetTicks();