JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
new option --bounciness (default changed from 100% to 50%).
[vor.git] / args.c
1 #include "args.h"
2 #include "config.h"
3
4 int opt_fullscreen;
5 int opt_music;
6 int opt_sound;
7 float opt_bounciness;
8 float opt_gamespeed;
9 int opt_tail_engine;
10 int opt_friction;
11
12 error_t parse_opt(int, char*, struct argp_state *);
13
14 const char *argp_program_version = "Variations on Rockdodger " VERSION;
15 const char *argp_program_bug_address = "<josh@qualdan.com>";
16 static char doc[] = "Dodge the rocks until you die.";
17 static struct argp_option opts[] = {
18         {0, 0, 0, 0, "Gameplay Variations:"},
19         {"bounciness", 'b', "N%", 0, "keep N% of speed when hitting edges (default 50%)"},
20         {"game-speed", 'g', "N%", 0, "50-100% (default 100%)"},
21         {"bad-physics", 'p', 0, 0, "bad physics (i.e. friction)"},
22         {0, 0, 0, 0, "Look and Feel:"},
23         {"engine", 'e', 0, 0, "Display large tail plume"},
24         {"full-screen", 'f', 0, 0, ""},
25         {"music", 'm', 0, 0, "Enable music"},
26         {"silent", 's', 0, 0, "Turn off explosion sounds"},
27         {0, 0, 0, 0, "Informational:", -1},
28         {0}
29 };
30
31 struct argp argp = { opts, &parse_opt, 0, doc };
32
33 void
34 init_opts(void)
35 {
36         opt_fullscreen = 0;
37         opt_sound = 1;
38         opt_music = 0;
39         opt_bounciness = 0.50; // lose 50% when you hit the screen edge.
40         opt_gamespeed = 1.00; // Run game at full speed.
41         // These switch back to the old gameplay and are off by default.
42         opt_tail_engine = 0;
43         opt_friction = 0;
44 }
45
46 error_t
47 parse_opt(int key, char *arg, struct argp_state *state)
48 {
49         int i;
50
51         switch(key) {
52                 case 'f': opt_fullscreen = 1; break;
53                 case 'm': opt_music = 1; break;
54                 case 's': opt_sound = 0; opt_music = 0; break;
55                 case 'b': i = 0; sscanf(arg, "%d%%", &i);
56                                   if(i < 50) i = 50; else if(i > 100) i = 100;
57                                   opt_bounciness = (float)i / 100;
58                                   break;
59                 case 'g': i = 0; sscanf(arg, "%d%%", &i);
60                                   if(i < 0) i = 0; else if(i > 100) i = 100;
61                                   opt_gamespeed = (float)i / 100;
62                                   break;
63                 case 'e': opt_tail_engine = 1; break;
64                 case 'p': opt_friction = 1; break;
65                 default: break;
66         }
67         return 0;
68 }