From 30498ebe775df3854f28946b1373da948bd190a3 Mon Sep 17 00:00:00 2001 From: Joshua Grams Date: Wed, 6 Jul 2005 23:05:39 +0000 Subject: [PATCH] We now limit how far ahead you can get. This is measured in screen widths, and has a command-line option --max-lead. Also added error checking to command-line parsing. --- args.c | 53 +++++++++++++++++++++++++++++++++++++---------------- args.h | 10 +++++++--- common.h | 28 ++++++++++++++++++++++++++++ main.c | 30 +++++++++++++++++------------- shape.c | 13 +------------ 5 files changed, 90 insertions(+), 44 deletions(-) create mode 100644 common.h diff --git a/args.c b/args.c index 5ee9c35..3a40acd 100644 --- a/args.c +++ b/args.c @@ -1,13 +1,18 @@ +#include #include "args.h" #include "config.h" +// Gameplay Variations +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; -float opt_bounciness; -float opt_gamespeed; int opt_tail_engine; -int opt_friction; error_t parse_opt(int, char*, struct argp_state *); @@ -16,14 +21,15 @@ const char *argp_program_bug_address = ""; static char doc[] = "Dodge the rocks until you die."; static struct argp_option opts[] = { {0, 0, 0, 0, "Gameplay Variations:"}, - {"bounciness", 'b', "N%", 0, "keep N% of speed when hitting edges (default 50%)"}, + {"bounciness", 'b', "N%", 0, "Keep N% of speed when hitting edges (default 50%)"}, {"game-speed", 'g', "N%", 0, "50-100% (default 100%)"}, - {"bad-physics", 'p', 0, 0, "bad physics (i.e. friction)"}, + {"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)"}, {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, "Turn off explosion sounds"}, + {"silent", 's', 0, 0, "No explosion sounds or music"}, {0, 0, 0, 0, "Informational:", -1}, {0} }; @@ -33,14 +39,17 @@ struct argp argp = { opts, &parse_opt, 0, doc }; void init_opts(void) { + // Gameplay Variations + 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; - opt_bounciness = 0.50; // lose 50% when you hit the screen edge. - opt_gamespeed = 1.00; // Run game at full speed. - // These switch back to the old gameplay and are off by default. opt_tail_engine = 0; - opt_friction = 0; } error_t @@ -49,19 +58,31 @@ parse_opt(int key, char *arg, struct argp_state *state) int i; switch(key) { - case 'f': opt_fullscreen = 1; break; - case 'm': opt_music = 1; break; - case 's': opt_sound = 0; opt_music = 0; break; - case 'b': i = 0; sscanf(arg, "%d%%", &i); + case 'b': if(!sscanf(arg, "%d%%", &i)) { + argp_error(state, "bad --bounciness (-b) value (should be 0-100%%)"); + return EINVAL; + } if(i < 50) i = 50; else if(i > 100) i = 100; opt_bounciness = (float)i / 100; break; - case 'g': i = 0; sscanf(arg, "%d%%", &i); + case 'e': opt_tail_engine = 1; break; + case 'f': opt_fullscreen = 1; break; + case 'g': if(!sscanf(arg, "%d%%", &i)) { + argp_error(state, "bad --gamespeed (-g) value (should be 50-100%%)"); + return EINVAL; + } if(i < 0) i = 0; else if(i > 100) i = 100; opt_gamespeed = (float)i / 100; break; - case 'e': opt_tail_engine = 1; break; + case 'l': if(!sscanf(arg, "%f", &opt_max_lead)) { + argp_error(state, "bad --max-limit (-l) value (must be a number)"); + 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; default: break; } return 0; diff --git a/args.h b/args.h index 4f04d27..c2d05c6 100644 --- a/args.h +++ b/args.h @@ -3,13 +3,17 @@ #include +// Gameplay Variations +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; -extern float opt_bounciness; -extern float opt_gamespeed; extern int opt_tail_engine; -extern int opt_friction; struct argp argp; diff --git a/common.h b/common.h new file mode 100644 index 0000000..ac9d87e --- /dev/null +++ b/common.h @@ -0,0 +1,28 @@ +#ifndef VOR_COMMON_H +#define VOR_COMMON_H + +#ifndef NULL +#define NULL 0 +#endif + +#ifndef true +#define true 1 +#endif + +#ifndef false +#define false 0 +#endif + +#ifndef max +#define max(a, b) ((a) > (b) ? (a) : (b)) +#endif + +#ifndef min +#define min(a, b) ((a) < (b) ? (a) : (b)) +#endif + +#ifndef abs +#define abs(a) ((a)<=0 ? -(a) : (a)) +#endif + +#endif // VOR_COMMON_H diff --git a/main.c b/main.c index c2e6601..a2bdcbc 100644 --- a/main.c +++ b/main.c @@ -19,11 +19,23 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "SFont.h" + #ifdef DEBUG #include "debug.h" #endif #include "args.h" +#include "common.h" #include "config.h" #include "file.h" #include "globals.h" @@ -32,17 +44,6 @@ #include "shape.h" #include "sound.h" -#include -#include -#include -#include -#include -#include -#include -#include - -#include "SFont.h" - // ************************************* VARS // SDL_Surface global variables SDL_Surface @@ -116,6 +117,8 @@ char *data_dir; extern char *optarg; extern int optind, opterr, optopt; +#define TO_TICKS(seconds) ((seconds)*20*opt_gamespeed) + // ************************************* FUNCS float @@ -714,13 +717,14 @@ gameloop() { screendx = -tmp; // taper off if we would hit the barrier in under 2 seconds. - if(back_dist + (screendx - SCREENDXMIN)*2*20*opt_gamespeed < 0) { - screendx = SCREENDXMIN - (back_dist/(2*20*opt_gamespeed)); + if(back_dist + (screendx - SCREENDXMIN)*TO_TICKS(2) < 0) { + screendx = SCREENDXMIN - (back_dist/TO_TICKS(2)); } xscroll = screendx * framelen; yscroll = screendy * framelen; back_dist += (screendx - SCREENDXMIN)*framelen; + if(opt_max_lead >= 0) back_dist = min(back_dist, opt_max_lead); shipx -= xscroll; shipy -= yscroll; diff --git a/shape.c b/shape.c index 9e03f19..f457158 100644 --- a/shape.c +++ b/shape.c @@ -1,4 +1,5 @@ #include +#include "common.h" #include "shape.h" void @@ -39,18 +40,6 @@ get_shape(SDL_Surface *img, struct shape *s) SDL_UnlockSurface(img); } -#ifndef max -#define max(a, b) ((a) > (b) ? (a) : (b)) -#endif - -#ifndef min -#define min(a, b) ((a) < (b) ? (a) : (b)) -#endif - -#ifndef abs -#define abs(a) ((a)<=0 ? -(a) : (a)) -#endif - int line_collide(int xov, struct shape *r, uint32_t *rbits, struct shape *s, uint32_t *sbits) { -- 1.7.10.4