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.
-# 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)
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 $@ $<
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
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/
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/*
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
--- /dev/null
+#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;
+}
--- /dev/null
+#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
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;
#include "debug.h"
#endif
+#include "args.h"
#include "config.h"
#include "file.h"
#include "globals.h"
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;
// ************************************* 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;
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;
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;
}
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;
}
int
main(int argc, char **argv) {
init_opts();
-
argp_parse(&argp, argc, argv, 0, 0, 0);
if(init()) {
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
+#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