JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
new option --bounciness (default changed from 100% to 50%).
authorJoshua Grams <josh@qualdan.com>
Tue, 5 Jul 2005 21:21:41 +0000 (21:21 +0000)
committerJoshua Grams <josh@qualdan.com>
Tue, 5 Jul 2005 21:21:41 +0000 (21:21 +0000)
pressing space at the Game Over screen now goes only to score display.
  (press space again to start a new game)
refactored the Makefile again.
moved command-line parsing stuff out to args.c/args.h.
rearranged command-line help.

Makefile
args.c [new file with mode: 0644]
args.h [new file with mode: 0644]
globals.h
main.c
rocks.c
sound.c

index be17b46..d68150b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
-#   Rock Dodger! Avoid the rocks as long as you can!
-#   Copyright (C) 2001  Paul Holt <pad@pcholt.com>
+#   Variations on Rockdodger
+#   Copyright (C) 2004  Joshua Grams <josh@qualdan.com>
 
 #   This program is free software; you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
 #   along with this program; if not, write to the Free Software
 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-debug := $(if $(DEBUG),1,0)
 ldflags := $(shell sdl-config --libs) -lSDL_image -lSDL_mixer
-cflags := $(shell sdl-config --cflags) -Wall -DDEBUG=$(debug) $(CFLAGS)
+cflags := $(shell sdl-config --cflags) -Wall -DDEBUG=$(if $(DEBUG),1,0)
+cflags := $(strip $(cflags))
+cflags += $(CFLAGS)
 
-my_objects := file.o rocks.o score.o shape.o sound.o main.o $(if $(DEBUG),debug.o)
+my_objects := args.o file.o rocks.o score.o shape.o sound.o
+my_objects += $(if $(DEBUG),debug.o) main.o
 libs := SFont.o
 objects := $(libs) $(my_objects)
 
@@ -39,12 +41,16 @@ DATA_PREFIX = /usr/share/vor
 PROGRAM_PREFIX = /usr/games/bin
 
 
+.PHONY: all clean maintainer-clean install uninstall
+.PHONY: mkinstalldirs rminstalldirs
+.PHONY: program program-clean install-program uninstall-program
+.PHONY: data data-clean install-data uninstall-data
 
-.PHONY: all clean graphics maintainer-clean install uninstall
+all: program data
 
-all: graphics vor
+data: $(graphics)
 
-graphics: $(graphics)
+program: vor
 
 %.o: %.c
        $(CC) $(cflags) -c -o $@ $<
@@ -58,13 +64,17 @@ vor: $(objects)
 
 include gfx.mk
 
-clean:
+clean: program-clean
+
+maintainer-clean: program-clean data-clean
+
+program-clean:
        rm -f *.o vor
 
-maintainer-clean: clean
+data-clean:
        rm -f $(graphics)
 
-install:       all
+mkinstalldirs:
        if [ ! -d $(DATA_PREFIX) ]; then mkdir $(DATA_PREFIX); fi
        if [ ! -d $(DATA_PREFIX)/banners ]; then mkdir $(DATA_PREFIX)/banners; fi
        if [ ! -d $(DATA_PREFIX)/fonts ]; then mkdir $(DATA_PREFIX)/fonts; fi
@@ -74,7 +84,22 @@ install:     all
        if [ ! -d $(DATA_PREFIX)/sounds ]; then mkdir $(DATA_PREFIX)/sounds; fi
        if [ ! -d $(DATA_PREFIX)/sprites ]; then mkdir $(DATA_PREFIX)/sprites; fi
 
+rminstalldirs:
+       if [ -d $(DATA_PREFIX)/banners ]; then rmdir $(DATA_PREFIX)/banners; fi
+       if [ -d $(DATA_PREFIX)/fonts ]; then rmdir $(DATA_PREFIX)/fonts; fi
+       if [ -d $(DATA_PREFIX)/icons ]; then rmdir $(DATA_PREFIX)/icons; fi
+       if [ -d $(DATA_PREFIX)/indicators ]; then rmdir $(DATA_PREFIX)/indicators; fi
+       if [ -d $(DATA_PREFIX)/music ]; then rmdir $(DATA_PREFIX)/music; fi
+       if [ -d $(DATA_PREFIX)/sounds ]; then rmdir $(DATA_PREFIX)/sounds; fi
+       if [ -d $(DATA_PREFIX)/sprites ]; then rmdir $(DATA_PREFIX)/sprites; fi
+       if [ -d $(DATA_PREFIX) ]; then rmdir $(DATA_PREFIX); fi
+
+install: all mkinstalldirs install-program install-data
+
+install-program: program
        $(INSTALL_PROGRAM) ./vor $(PROGRAM_PREFIX)
+
+install-data: data
        $(INSTALL_DATA) ./data/banners/* $(DATA_PREFIX)/banners/
        $(INSTALL_DATA) ./data/fonts/* $(DATA_PREFIX)/fonts/
        $(INSTALL_DATA) ./data/icons/* $(DATA_PREFIX)/icons/
@@ -85,8 +110,12 @@ install:    all
        touch $(DATA_PREFIX)/scores
        chmod a+rw $(DATA_PREFIX)/scores
 
-uninstall:
+uninstall: uninstall-program uninstall-data rminstalldirs
+
+uninstall-program:
        rm -f $(PROGRAM_PREFIX)/vor
+
+uninstall-data:
        rm -f $(DATA_PREFIX)/banners/*
        rm -f $(DATA_PREFIX)/fonts/*
        rm -f $(DATA_PREFIX)/icons/*
@@ -95,12 +124,3 @@ uninstall:
        rm -f $(DATA_PREFIX)/sounds/*
        rm -f $(DATA_PREFIX)/sprites/*
        rm -f $(DATA_PREFIX)/scores $(DATA_PREFIX)/.highscore
-
-       if [ -d $(DATA_PREFIX)/banners ]; then rmdir $(DATA_PREFIX)/banners; fi
-       if [ -d $(DATA_PREFIX)/fonts ]; then rmdir $(DATA_PREFIX)/fonts; fi
-       if [ -d $(DATA_PREFIX)/icons ]; then rmdir $(DATA_PREFIX)/icons; fi
-       if [ -d $(DATA_PREFIX)/indicators ]; then rmdir $(DATA_PREFIX)/indicators; fi
-       if [ -d $(DATA_PREFIX)/music ]; then rmdir $(DATA_PREFIX)/music; fi
-       if [ -d $(DATA_PREFIX)/sounds ]; then rmdir $(DATA_PREFIX)/sounds; fi
-       if [ -d $(DATA_PREFIX)/sprites ]; then rmdir $(DATA_PREFIX)/sprites; fi
-       if [ -d $(DATA_PREFIX) ]; then rmdir $(DATA_PREFIX); fi
diff --git a/args.c b/args.c
new file mode 100644 (file)
index 0000000..5ee9c35
--- /dev/null
+++ b/args.c
@@ -0,0 +1,68 @@
+#include "args.h"
+#include "config.h"
+
+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 *);
+
+const char *argp_program_version = "Variations on Rockdodger " VERSION;
+const char *argp_program_bug_address = "<josh@qualdan.com>";
+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%)"},
+       {"game-speed", 'g', "N%", 0, "50-100% (default 100%)"},
+       {"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"},
+       {0, 0, 0, 0, "Informational:", -1},
+       {0}
+};
+
+struct argp argp = { opts, &parse_opt, 0, doc };
+
+void
+init_opts(void)
+{
+       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
+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);
+                                 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);
+                                 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 'p': opt_friction = 1; break;
+               default: break;
+       }
+       return 0;
+}
diff --git a/args.h b/args.h
new file mode 100644 (file)
index 0000000..4f04d27
--- /dev/null
+++ b/args.h
@@ -0,0 +1,18 @@
+#ifndef VOR_ARGS_H
+#define VOR_ARGS_H
+
+#include <argp.h>
+
+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;
+
+void init_opts(void);
+
+#endif // VOR_ARGS_H
index a682d47..e6b1905 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -53,14 +53,6 @@ extern struct enginedots edot[MAXENGINEDOTS], *dotptr;
 extern struct bangdots bdot[MAXBANGDOTS], *bdotptr;
 extern struct spacedot sdot[MAXSPACEDOTS];
 
-// command-line arguments
-extern int opt_fullscreen;
-extern int opt_sound;
-extern int opt_music;
-extern float opt_gamespeed;
-extern int opt_tail_engine;
-extern int opt_friction;
-
 // Other global variables
 extern char topline[1024];
 extern char *initerror;
diff --git a/main.c b/main.c
index a161720..79b8689 100644 (file)
--- a/main.c
+++ b/main.c
@@ -23,6 +23,7 @@
 #include "debug.h"
 #endif
 
+#include "args.h"
 #include "config.h"
 #include "file.h"
 #include "globals.h"
@@ -68,30 +69,6 @@ struct spacedot sdot[MAXSPACEDOTS];
 char topline[1024];
 char *initerror = "";
 
-// Command-line argument parsing
-int opt_fullscreen;
-int opt_sound;
-int opt_music;
-float opt_gamespeed;
-int opt_tail_engine;
-int opt_friction;
-
-const char *argp_program_version = "Variations on Rockdodger " VERSION;
-const char *argp_program_bug_address = "<josh@qualdan.com>";
-static char doc[] = "VoR: Dodge the rocks until you die.";
-static struct argp_option opts[] = {
-       {0, 0, 0, 0, "Basic Options:"},
-       {"full-screen", 'f', 0, 0, ""},
-       {"music", 'm', 0, 0, "Enable music"},
-       {"silent", 's', 0, 0, "Turn off explosion sounds"},
-       {0, 0, 0, 0, "Gameplay Options:"},
-       {"game-speed", 'g', "N%", 0, "Game speed [50-100%]"},
-       {"engine", 'e', 0, 0, "Display large tail plume"},
-       {"old-physics", 'p', 0, 0, "Original physics (i.e. friction)."},
-       {0}
-};
-error_t parse_opt(int, char*, struct argp_state *);
-static struct argp argp = { opts, &parse_opt, 0, doc };
 
 
 struct shape shipshape;
@@ -140,38 +117,6 @@ extern int optind, opterr, optopt;
 
 // ************************************* FUNCS
 
-void
-init_opts(void)
-{
-       opt_fullscreen = 0;
-       opt_sound = 1;
-       opt_music = 0;
-       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
-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 'g': sscanf(arg, "%d%%", &i);
-                                 if(i < 50) i = 50; else if(i > 100) i = 100;
-                                 opt_gamespeed = (float)i / 100;
-                                 break;
-               case 'e': opt_tail_engine = 1; break;
-               case 'p': opt_friction = 1; break;
-               default: break;
-       }
-       return 0;
-}
-
 float
 rnd() {
        return (float)random()/(float)RAND_MAX;
@@ -663,9 +608,9 @@ draw() {
        ticks_since_last = SDL_GetTicks()-last_ticks;
        last_ticks = SDL_GetTicks();
        if(ticks_since_last>200 || ticks_since_last<0) {
+               // We won't run at all below 5 frames per second.
                gamerate = 0;
-       }
-       else {
+       } else {
                gamerate = opt_gamespeed*ticks_since_last/50.0;
                if(state == GAMEPLAY) {
                        score += ticks_since_last;
@@ -697,14 +642,14 @@ gameloop() {
                                                play_tune(1);
                                                break;
                                        case GAME_OVER:
-                                               state = HIGH_SCORE_ENTRY;
-                                               state_timeout = 5.0e6;
                                                if(new_high_score(score)) {
                                                        SDL_Event e;
+                                                       state = HIGH_SCORE_ENTRY;
+                                                       state_timeout = 5.0e6;
                                                        SDL_EnableUNICODE(1);
                                                        while(SDL_PollEvent(&e))
                                                                ;
-                                               } else {
+                                               } else if(!keystate[SDLK_SPACE]) {
                                                        state = HIGH_SCORE_DISPLAY;
                                                        state_timeout = 400;
                                                }
@@ -784,14 +729,14 @@ gameloop() {
                        if(shipx<0 || shipx>XSIZE-surf_ship->w) {
                                // BOUNCE from left and right wall
                                shipx -= (shipdx-screendx)*gamerate;
-                               shipdx = 2*screendx-shipdx;
+                               shipdx = screendx - (shipdx-screendx)*opt_bounciness;
                        }
 
                        // BOUNCE Y
                        if(shipy<0 || shipy>YSIZE-surf_ship->h) {
                                // BOUNCE from top and bottom wall
                                shipy -= (shipdy-screendy)*gamerate;
-                               shipdy = 2*screendy-shipdy;
+                               shipdy = screendy - (shipdy-screendy)*opt_bounciness;
                        }
 
 
@@ -882,7 +827,6 @@ gameloop() {
 int
 main(int argc, char **argv) {
        init_opts();
-
        argp_parse(&argp, argc, argv, 0, 0, 0);
 
        if(init()) {
diff --git a/rocks.c b/rocks.c
index 89fe3a2..e47bc44 100644 (file)
--- a/rocks.c
+++ b/rocks.c
@@ -69,7 +69,7 @@ reset_rocks(void)
 enum { LEFT, RIGHT, TOP, BOTTOM };
 
 
-// compute the number of rocks/seccond that should be coming from each side
+// compute the number of rocks/second that should be coming from each side
 
 // compute the speed ranges of rocks coming from each side
 void
diff --git a/sound.c b/sound.c
index 7a2ad22..88d8d4c 100644 (file)
--- a/sound.c
+++ b/sound.c
@@ -1,8 +1,7 @@
+#include "args.h"
 #include "sound.h"
 #include "config.h"
 
-extern int opt_sound, opt_music;
-
 #define TUNE_TITLE_PAGE                0
 #define TUNE_GAMEPLAY          1
 #define TUNE_HIGH_SCORE_ENTRY  2