JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Friction doesn't make sense any more, dropped that.
authorJoshua Grams <josh@qualdan.com>
Thu, 7 Jul 2005 21:13:33 +0000 (21:13 +0000)
committerJoshua Grams <josh@qualdan.com>
Thu, 7 Jul 2005 21:13:33 +0000 (21:13 +0000)
Tail engine is just dumb, dropped that.
Undocumented -l option.
Rewrote particle generation for jets (same results, shorter code).

args.c
args.h
globals.h
main.c
rocks.c

diff --git a/args.c b/args.c
index 3a40acd..0131215 100644 (file)
--- a/args.c
+++ b/args.c
@@ -6,13 +6,11 @@
 float opt_bounciness;
 float opt_gamespeed;
 float opt_max_lead;
 float opt_bounciness;
 float opt_gamespeed;
 float opt_max_lead;
-int opt_friction;
 
 // Look and Feel
 int opt_fullscreen;
 int opt_music;
 int opt_sound;
 
 // Look and Feel
 int opt_fullscreen;
 int opt_music;
 int opt_sound;
-int opt_tail_engine;
 
 error_t parse_opt(int, char*, struct argp_state *);
 
 
 error_t parse_opt(int, char*, struct argp_state *);
 
@@ -23,10 +21,9 @@ static struct argp_option opts[] = {
        {0, 0, 0, 0, "Gameplay Variations:"},
        {"bounciness", 'b', "N%", 0, "Keep N% of speed when hitting edges (default 50%)"},
        {"game-speed", 'g', "N%", 0, "50-100% (default 100%)"},
        {0, 0, 0, 0, "Gameplay Variations:"},
        {"bounciness", 'b', "N%", 0, "Keep N% of speed when hitting edges (default 50%)"},
        {"game-speed", 'g', "N%", 0, "50-100% (default 100%)"},
-       {"max-lead", 'l', "#SCREENS", 0, "Max dist. ahead you can get (default 1 screen)\n(negative value means no limit)"},
-       {"bad-physics", 'p', 0, 0, "Bad physics (i.e. friction)"},
+       {"max-lead", 'l', "#SCREENS", OPTION_HIDDEN,
+               "Max distance ahead you can get\n (default 1 screen; < 0 means no limit)"},
        {0, 0, 0, 0, "Look and Feel:"},
        {0, 0, 0, 0, "Look and Feel:"},
-       {"engine", 'e', 0, 0, "Display large tail plume"},
        {"full-screen", 'f', 0, 0, ""},
        {"music", 'm', 0, 0, "Enable music"},
        {"silent", 's', 0, 0, "No explosion sounds or music"},
        {"full-screen", 'f', 0, 0, ""},
        {"music", 'm', 0, 0, "Enable music"},
        {"silent", 's', 0, 0, "No explosion sounds or music"},
@@ -43,13 +40,11 @@ init_opts(void)
        opt_bounciness = 0.50; // lose 50% when you hit the screen edge.
        opt_gamespeed = 1.00; // Run game at full speed.
        opt_max_lead = 1.00*XSIZE;  // you can get 1 screen ahead.
        opt_bounciness = 0.50; // lose 50% when you hit the screen edge.
        opt_gamespeed = 1.00; // Run game at full speed.
        opt_max_lead = 1.00*XSIZE;  // you can get 1 screen ahead.
-       opt_friction = 0;
 
        // Look and Feel
        opt_fullscreen = 0;
        opt_sound = 1;
        opt_music = 0;
 
        // Look and Feel
        opt_fullscreen = 0;
        opt_sound = 1;
        opt_music = 0;
-       opt_tail_engine = 0;
 }
 
 error_t
 }
 
 error_t
@@ -59,31 +54,35 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
        switch(key) {
                case 'b': if(!sscanf(arg, "%d%%", &i)) {
 
        switch(key) {
                case 'b': if(!sscanf(arg, "%d%%", &i)) {
-                                         argp_error(state, "bad --bounciness (-b) value (should be 0-100%%)");
+                                         fprintf(stderr, "bad --bounciness (-b) value (should be 0-100%%)\n");
+                                         argp_state_help(state, stderr, ARGP_HELP_STD_HELP);
                                          return EINVAL;
                                  }
                                  if(i < 50) i = 50; else if(i > 100) i = 100;
                                  opt_bounciness = (float)i / 100;
                                  break;
                                          return EINVAL;
                                  }
                                  if(i < 50) i = 50; else if(i > 100) i = 100;
                                  opt_bounciness = (float)i / 100;
                                  break;
-               case 'e': opt_tail_engine = 1; break;
                case 'f': opt_fullscreen = 1; break;
                case 'g': if(!sscanf(arg, "%d%%", &i)) {
                case 'f': opt_fullscreen = 1; break;
                case 'g': if(!sscanf(arg, "%d%%", &i)) {
-                                         argp_error(state, "bad --gamespeed (-g) value (should be 50-100%%)");
+                                         fprintf(stderr, "bad --gamespeed (-g) value (should be 50-100%%)\n");
+                                         argp_state_help(state, stderr, ARGP_HELP_STD_HELP);
                                          return EINVAL;
                                  }
                                  if(i < 0) i = 0; else if(i > 100) i = 100;
                                  opt_gamespeed = (float)i / 100;
                                  break;
                case 'l': if(!sscanf(arg, "%f", &opt_max_lead)) {
                                          return EINVAL;
                                  }
                                  if(i < 0) i = 0; else if(i > 100) i = 100;
                                  opt_gamespeed = (float)i / 100;
                                  break;
                case 'l': if(!sscanf(arg, "%f", &opt_max_lead)) {
-                                         argp_error(state, "bad --max-limit (-l) value (must be a number)");
+                                         fprintf(stderr, "bad --max-lead (-l) value (must be a number)\n");
+                                         argp_state_help(state, stderr, ARGP_HELP_STD_HELP);
                                          return EINVAL;
                                  }
                                  opt_max_lead *= XSIZE;
                                  break;
                case 'm': opt_music = 1; break;
                                          return EINVAL;
                                  }
                                  opt_max_lead *= XSIZE;
                                  break;
                case 'm': opt_music = 1; break;
-               case 'p': opt_friction = 1; break;
                case 's': opt_sound = 0; opt_music = 0; break;
                case 's': opt_sound = 0; opt_music = 0; break;
-               default: break;
+               case ARGP_KEY_END:
+                                 break;
+               default:
+                                 return ARGP_ERR_UNKNOWN;
        }
        return 0;
 }
        }
        return 0;
 }
diff --git a/args.h b/args.h
index c2d05c6..a122b8d 100644 (file)
--- a/args.h
+++ b/args.h
@@ -7,13 +7,11 @@
 extern float opt_bounciness;
 extern float opt_gamespeed;
 extern float opt_max_lead;
 extern float opt_bounciness;
 extern float opt_gamespeed;
 extern float opt_max_lead;
-extern int opt_friction;
 
 // Look and Feel
 extern int opt_fullscreen;
 extern int opt_music;
 extern int opt_sound;
 
 // Look and Feel
 extern int opt_fullscreen;
 extern int opt_music;
 extern int opt_sound;
-extern int opt_tail_engine;
 
 struct argp argp;
 
 
 struct argp argp;
 
index 4eb58f1..fb68ef6 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -66,9 +66,10 @@ extern float yscroll;
 extern float scrollvel;
 
 // all movement is based on s_frame.
 extern float scrollvel;
 
 // all movement is based on s_frame.
-float t_frame;  // length of this frame (in ticks = 1/20th second)
-int ms_frame;   // length of this frame (milliseconds)
-int ms_end;     // end of this frame (milliseconds)
+extern float t_frame;  // length of this frame (in ticks = 1/20th second)
+extern float s_frame;  // length of this frame (seconds)
+extern int ms_frame;   // length of this frame (milliseconds)
+extern int ms_end;     // end of this frame (milliseconds)
 
 extern int nships,score;
 extern int gameover;
 
 extern int nships,score;
 extern int gameover;
diff --git a/main.c b/main.c
index 9b04f07..92927b5 100644 (file)
--- a/main.c
+++ b/main.c
@@ -81,6 +81,7 @@ float back_dist;
 
 // all movement is based on t_frame.
 float t_frame;  // length of this frame (in ticks = 1/20th second)
 
 // all movement is based on t_frame.
 float t_frame;  // length of this frame (in ticks = 1/20th second)
+float s_frame;  // length of this frame (seconds)
 int ms_frame;   // length of this frame (milliseconds)
 int ms_end;     // end of this frame (milliseconds)
 
 int ms_frame;   // length of this frame (milliseconds)
 int ms_end;     // end of this frame (milliseconds)
 
@@ -88,7 +89,7 @@ float bangx, bangy, bangdx, bangdy;
 
 int nships,score;
 int gameover;
 
 int nships,score;
 int gameover;
-int maneuver = 0;
+int jets = 0;
 
 float fadetimer = 0, faderate;
 
 
 float fadetimer = 0, faderate;
 
@@ -297,84 +298,36 @@ draw_engine_dots(SDL_Surface *s) {
 }
 
 void
 }
 
 void
-create_engine_dots(int newdots) {
+new_engine_dots(int n, int dir) {
        int i;
        int i;
-       double theta,r,dx,dy;
-
-       if(!opt_tail_engine) return;
-
-       if(state == GAMEPLAY) {
-               for(i = 0; i<newdots*t_frame; i++) {
-                       if(dotptr->active == 0) {
-                               theta = rnd()*M_PI*2;
-                               r = rnd();
-                               dx = cos(theta)*r;
-                               dy = sin(theta)*r;
-
-                               dotptr->active = 1;
-                               dotptr->x = shipx + surf_ship->w/2-14;
-                               dotptr->y = shipy + surf_ship->h/2 + (rnd()-0.5)*5-1;
-                               dotptr->dx = 10*(dx-1.5) + shipdx;
-                               dotptr->dy = 1*dy + shipdy;
-                               dotptr->life = 45 + rnd(1)*5;
-
-                               dotptr++;
-                               if(dotptr-edot >= MAXENGINEDOTS) {
-                                       dotptr = edot;
-                               }
-                       }
-               }
-       }
-}
+       float a, r;  // angle, random length
+       float dx, dy;
+       float hx, hy; // half ship width/height.
+       static const int s[4] = { 2, 1, 0, 1 };
 
 
-void
-create_engine_dots2(int newdots, int m) {
-       int i;
-       double theta, theta2, dx, dy, adx, ady;
+       hx = surf_ship->w / 2;
+       hy = surf_ship->h / 2;
 
 
-       // Don't create fresh engine dots when
-       // the game is not being played and a demo is not beng shown
-       if(state != GAMEPLAY) return;
-
-       for(i = 0; i<newdots; i++) {
+       for(i = 0; i<n; i++) {
                if(dotptr->active == 0) {
                if(dotptr->active == 0) {
-                       theta = rnd()*M_PI*2;
-                       theta2 = rnd()*M_PI*2;
-
-                       dx = cos(theta) * fabs(cos(theta2));
-                       dy = sin(theta) * fabs(cos(theta2));
-                       adx = fabs(dx);
-                       ady = fabs(dy);
-
+                       a = rnd()*M_PI + (dir-1)*M_PI_2;
+                       r = sin(rnd()*M_PI);
+                       dx = r * cos(a);
+                       dy = r * -sin(a);  // screen y is "backwards".
 
                        dotptr->active = 1;
 
                        dotptr->active = 1;
-                       dotptr->x = shipx + surf_ship->w/2 + (rnd()-0.5)*3;
-                       dotptr->y = shipy + surf_ship->h/2 + (rnd()-0.5)*3;
-
-                       switch(m) {
-                               case 0:
-                                       dotptr->x -= 14;
-                                       dotptr->dx = -20*adx + shipdx;
-                                       dotptr->dy = 2*dy + shipdy;
-                                       dotptr->life = 60 * adx;
-                               break;
-                               case 1:
-                                       dotptr->dx = 2*dx + shipdx;
-                                       dotptr->dy = -20*ady + shipdy;
-                                       dotptr->life = 60 * ady;
-                               break;
-                               case 2:
-                                       dotptr->x += 14;
-                                       dotptr->dx = 20*adx + shipdx;
-                                       dotptr->dy = 2*dy + shipdy;
-                                       dotptr->life = 60 * adx;
-                               break;
-                               case 3:
-                                       dotptr->dx = 2*dx + shipdx;
-                                       dotptr->dy = 20*ady + shipdy;
-                                       dotptr->life = 60 * ady;
-                               break;
+                       dotptr->x = shipx + s[dir]*hx + (rnd()-0.5)*3;
+                       dotptr->y = shipy + s[(dir+1)&3]*hy + (rnd()-0.5)*3;
+                       if(dir&1) {
+                               dotptr->dx = shipdx + 2*dx;
+                               dotptr->dy = shipdy + 20*dy;
+                               dotptr->life = 60 * fabs(dy);
+                       } else {
+                               dotptr->dx = shipdx + 20*dx;
+                               dotptr->dy = shipdy + 2*dy;
+                               dotptr->life = 60 * fabs(dx);
                        }
                        }
+
                        dotptr++;
                        if(dotptr-edot >= MAXENGINEDOTS) {
                                dotptr = edot;
                        dotptr++;
                        if(dotptr-edot >= MAXENGINEDOTS) {
                                dotptr = edot;
@@ -387,13 +340,10 @@ void
 drawdots(SDL_Surface *s) {
        int m;
 
 drawdots(SDL_Surface *s) {
        int m;
 
-       // Create more engine dots comin' out da back
-       if(!gameover) create_engine_dots(200);
-
        // Create engine dots out the side we're moving from
        for(m = 0; m<4; m++) {
        // Create engine dots out the side we're moving from
        for(m = 0; m<4; m++) {
-               if(maneuver & 1<<m) { // 'maneuver' is a bit field
-                       create_engine_dots2(80,m);
+               if(jets & 1<<m) { // 'jets' is a bit field
+                       new_engine_dots(80,m);
                }
        }
 
                }
        }
 
@@ -617,13 +567,14 @@ draw() {
        ms_end += ms_frame;
        if(ms_frame>200 || ms_frame<0) {
                // We won't run at all below 5 frames per second.
        ms_end += ms_frame;
        if(ms_frame>200 || ms_frame<0) {
                // We won't run at all below 5 frames per second.
-               t_frame = 0;
+               // This also happens if we were paused, grr.
+               s_frame = 0;
+               ms_frame = 0;
        } else {
        } else {
-               t_frame = opt_gamespeed*ms_frame/50.0;
-               if(state == GAMEPLAY) {
-                       score += ms_frame;
-               }
+               s_frame = opt_gamespeed * ms_frame / 1000;
+               if(state == GAMEPLAY) score += ms_frame;
        }
        }
+       t_frame = s_frame * 20;
 
        // Update the surface
        SDL_Flip(surf_screen);
 
        // Update the surface
        SDL_Flip(surf_screen);
@@ -698,12 +649,6 @@ gameloop() {
 
                        new_rocks();
 
 
                        new_rocks();
 
-                       // FRICTION?
-                       if(opt_friction) {
-                               shipdx *= pow((double)0.9,(double)t_frame);
-                               shipdy *= pow((double)0.9,(double)t_frame);
-                       }
-
                        // INERTIA
                        shipx += shipdx*t_frame;
                        shipy += shipdy*t_frame;
                        // INERTIA
                        shipx += shipdx*t_frame;
                        shipy += shipdy*t_frame;
@@ -795,7 +740,7 @@ gameloop() {
                                shipdx = screendx; shipdy = screendy;
                        }
 
                                shipdx = screendx; shipdy = screendy;
                        }
 
-                       maneuver = 0;
+                       jets = 0;
                } else {
                        SDL_PumpEvents();
                        keystate = SDL_GetKeyState(NULL);
                } else {
                        SDL_PumpEvents();
                        keystate = SDL_GetKeyState(NULL);
@@ -805,10 +750,10 @@ gameloop() {
                        if(!gameover) {
 
                                if(!paused) {
                        if(!gameover) {
 
                                if(!paused) {
-                                       if(keystate[SDLK_UP]    | keystate[SDLK_c]) { shipdy -= 1.5*t_frame; maneuver |= 1<<3;}
-                                       if(keystate[SDLK_DOWN]  | keystate[SDLK_t]) { shipdy += 1.5*t_frame; maneuver |= 1<<1;}
-                                       if(keystate[SDLK_LEFT]  | keystate[SDLK_h]) { shipdx -= 1.5*t_frame; maneuver |= 1<<2;}
-                                       if(keystate[SDLK_RIGHT] | keystate[SDLK_n]) { shipdx += 1.5*t_frame; maneuver |= 1;}
+                                       if(keystate[SDLK_LEFT]  | keystate[SDLK_h]) { shipdx -= 1.5*t_frame; jets |= 1<<0;}
+                                       if(keystate[SDLK_DOWN]  | keystate[SDLK_t]) { shipdy += 1.5*t_frame; jets |= 1<<1;}
+                                       if(keystate[SDLK_RIGHT] | keystate[SDLK_n]) { shipdx += 1.5*t_frame; jets |= 1<<2;}
+                                       if(keystate[SDLK_UP]    | keystate[SDLK_c]) { shipdy -= 1.5*t_frame; jets |= 1<<3;}
                                        if(keystate[SDLK_3])            { SDL_SaveBMP(surf_screen, "snapshot.bmp"); }
                                }
 
                                        if(keystate[SDLK_3])            { SDL_SaveBMP(surf_screen, "snapshot.bmp"); }
                                }
 
diff --git a/rocks.c b/rocks.c
index 5518c41..fc18bf3 100644 (file)
--- a/rocks.c
+++ b/rocks.c
@@ -157,7 +157,7 @@ new_rocks(void)
        // loop through the four sides of the screen
        for(i=0; i<4; i++) {
                // see if we generate a rock for this side this frame
        // loop through the four sides of the screen
        for(i=0; i<4; i++) {
                // see if we generate a rock for this side this frame
-               rtimers[i] += ti[i]*t_frame/20;
+               rtimers[i] += ti[i]*s_frame;
                while(rtimers[i] >= 1) {
                        rtimers[i] -= 1;
                        j=0;
                while(rtimers[i] >= 1) {
                        rtimers[i] -= 1;
                        j=0;