19 puts("Dodge the rocks until you die.");
21 puts(" Gameplay Variations:");
22 puts(" -b, --bounciness=N% Keep N% of speed when hitting edges (default 50%)");
23 puts(" -g, --game-speed=N% 50-200% (default 100%)");
25 puts(" Look and Feel:");
26 puts(" -f, --full-screen");
27 puts(" -m, --music Enable music");
28 puts(" -s, --silent No explosion sounds or music");
30 puts(" Informational:");
31 puts(" -?, --help Give this help list");
32 puts(" -V, --version Print program version");
34 puts("Mandatory or optional arguments to long options are also mandatory or optional");
35 puts("for any corresponding short options.");
37 puts("Report bugs to <josh@qualdan.com>.");
41 short_opt(char c, char *arg)
46 case 'b': if(!arg || sscanf(arg, "%d%%", &i) != 1 || i < 0 || i > 100) {
47 fprintf(stderr, "bad --bounciness (-b) value (should be 0-100%%)\n\n");
50 opt_bounciness = (float)i / 100;
53 case 'f': opt_fullscreen = 1; break;
54 case 'g': if(!arg || sscanf(arg, "%d%%", &i) != 1 || i < 50 || i > 200) {
55 fprintf(stderr, "bad --game-speed (-g) value (should be 50-200%%)\n\n");
58 opt_gamespeed = (float)i / 100;
61 case 'l': if(sscanf(arg, "%f", &opt_max_lead) != 1) {
62 fprintf(stderr, "bad --max-lead (-l) value (must be a number)\n\n");
65 opt_max_lead *= XSIZE;
68 case 'm': opt_music = 1; break;
69 case 's': opt_sound = 0; opt_music = 0; break;
71 printf("Variations on Rockdodger %s\n", VERSION);
76 fprintf(stderr, "unknown option -%c\n\n", c);
83 parse_short_opts(const char *s, char *arg)
85 while(s[1]) if(!short_opt(*s++, NULL)) return 0;
86 return short_opt(*s, arg);
89 static char *long_opts[] = {
90 "bounciness", "game-speed",
91 "full-screen", "music", "silent",
95 static char short_opts[] = {
102 parse_long_opt(const char *s, char *arg)
105 for(i=0; i<sizeof(short_opts); i++) {
106 if(strcmp(s, long_opts[i]) == 0)
107 return short_opt(short_opts[i], arg);
109 fprintf(stderr, "unknown long option --%s\n\n", s);
116 // Gameplay Variations
117 opt_bounciness = 0.50; // lose 50% when you hit the screen edge.
118 opt_gamespeed = 1.00; // Run game at full speed.
119 opt_max_lead = 1.00*XSIZE; // you can get 1 screen ahead.
128 parse_opts(int argc, char *argv[])
134 for(i=1; i<argc; i++) {
136 s = argv[i]; if(!*s) continue;
138 fputs("not an option\n\n", stderr);
144 for(r=s; *r; r++) if(*r == '=') { *r = 0; arg = r+1; break; }
145 if(!arg && (i+1 < argc)) arg = argv[i+1];
148 if(!parse_long_opt(s+1, arg)) { show_help(); return 0; }
150 if(!parse_short_opts(s, arg)) { show_help(); return 0; }