From eb0732dc23646473853da1e37311f93052b8251b Mon Sep 17 00:00:00 2001 From: Joshua Grams Date: Sat, 17 Feb 2007 16:55:00 +0000 Subject: [PATCH] removed and renamed more variables. --- args.c | 11 ----------- args.h | 5 ----- config.h | 5 ++++- main.c | 40 +++++++++++++++++++++------------------- 4 files changed, 25 insertions(+), 36 deletions(-) diff --git a/args.c b/args.c index 9c4c62b..f194690 100644 --- a/args.c +++ b/args.c @@ -4,11 +4,6 @@ #include "args.h" #include "config.h" -// Gameplay Variations -float opt_bounciness; -float opt_gamespeed; -float opt_max_lead; - // Look and Feel int opt_fullscreen; int opt_sound; @@ -73,12 +68,6 @@ parse_long_opt(const char *s, char *arg) 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. - - // Look and Feel opt_fullscreen = 0; opt_sound = 1; } diff --git a/args.h b/args.h index 92cf5b7..4b1569e 100644 --- a/args.h +++ b/args.h @@ -1,11 +1,6 @@ #ifndef VOR_ARGS_H #define VOR_ARGS_H -// Gameplay Variations -extern float opt_bounciness; -extern float opt_gamespeed; -extern float opt_max_lead; - // Look and Feel extern int opt_fullscreen; extern int opt_sound; diff --git a/config.h b/config.h index 13be252..77b453c 100644 --- a/config.h +++ b/config.h @@ -10,7 +10,10 @@ #define XSCROLLTO (XSIZE/3) #define YSCROLLTO (YSIZE/2) -#define SCREENDXMIN 7.5 +#define BARRIER_SPEED 7.5 + +#define MAX_DIST_AHEAD XSIZE +#define BOUNCINESS 0.50 // ----------------------------------------------------------------------- diff --git a/main.c b/main.c index 36cebc6..72f3cfd 100644 --- a/main.c +++ b/main.c @@ -65,10 +65,10 @@ struct bangdots bdot[MAXBANGDOTS], *bdotptr = bdot; char topline[1024]; char *initerror = ""; -struct ship ship = { SHIP, 0, NULL, XSIZE/2, YSIZE/2, SCREENDXMIN, 0.0 }; +struct ship ship = { SHIP, 0, NULL, XSIZE/2, YSIZE/2, BARRIER_SPEED, 0.0 }; -float screendx = SCREENDXMIN, screendy = 0.0; -float back_dist; +float screendx = BARRIER_SPEED, screendy = 0.0; +float dist_ahead; // all movement is based on t_frame. unsigned long frames, start, end; @@ -76,6 +76,8 @@ float t_frame; // length of this frame (in ticks = 1/20th second) adjusted for int ms_frame; // length of this frame (milliseconds) int ms_end; // end of this frame (milliseconds) +float gamespeed = 1.00; + int score; float fadetimer = 0; @@ -117,7 +119,7 @@ char *data_dir; extern char *optarg; extern int optind, opterr, optopt; -#define TO_TICKS(seconds) ((seconds)*20*opt_gamespeed) +#define TO_TICKS(seconds) ((seconds)*20*gamespeed) // ************************************* FUNCS @@ -575,14 +577,14 @@ kill_ship(struct ship *ship) ship->flags = MOVE; ship->dx = (ship->dx < 0) ? -sqrt(-ship->dx) : sqrt(ship->dx); ship->dy = (ship->dy < 0) ? -sqrt(-ship->dy) : sqrt(ship->dy); - if(ship->dx < SCREENDXMIN) ship->dx = SCREENDXMIN; + if(ship->dx < BARRIER_SPEED) ship->dx = BARRIER_SPEED; } else { state = GAME_OVER; state_timeout = 200.0; fadetimer = 0.0; ship->flags = 0; // scrolling is based on the ship speed, so we need to reset it. - ship->dx = SCREENDXMIN; ship->dy = 0; + ship->dx = BARRIER_SPEED; ship->dy = 0; } } @@ -654,7 +656,7 @@ gameloop() { if(ms_frame > 1000) { ms_frame = 1000; } - t_frame = opt_gamespeed * ms_frame / 50; + t_frame = gamespeed * ms_frame / 50; frames++; while(SDL_PollEvent(&e)) { @@ -708,16 +710,16 @@ gameloop() { update_state(t_frame); // SCROLLING - tmp = (ship.y+ship.h/2+ship.dy*t_frame-YSCROLLTO)/25 + (ship.dy-screendy); + tmp = (ship.y+ship.h/2 + ship.dy*t_frame - YSCROLLTO)/25 + (ship.dy-screendy); screendy += tmp * t_frame/12; - tmp = (ship.x+ship.w/2+ship.dx*t_frame-XSCROLLTO)/25 + (ship.dx-screendx); + tmp = (ship.x+ship.w/2 + ship.dx*t_frame - XSCROLLTO)/25 + (ship.dx-screendx); screendx += tmp * t_frame/12; // taper off so we don't hit the barrier abruptly. // (if we would hit in < 2 seconds, adjust to 2 seconds). - if(back_dist + (screendx - SCREENDXMIN)*TO_TICKS(2) < 0) - screendx = SCREENDXMIN - (back_dist/TO_TICKS(2)); - back_dist += (screendx - SCREENDXMIN)*t_frame; - if(opt_max_lead >= 0) back_dist = min(back_dist, opt_max_lead); + if(dist_ahead + (screendx - BARRIER_SPEED)*TO_TICKS(2) < 0) + screendx = BARRIER_SPEED - (dist_ahead/TO_TICKS(2)); + dist_ahead += (screendx - BARRIER_SPEED)*t_frame; + if(MAX_DIST_AHEAD >= 0) dist_ahead = min(dist_ahead, MAX_DIST_AHEAD); move_sprites(t_frame); new_rocks(t_frame); move_engine_dots(t_frame); new_engine_dots(t_frame); @@ -729,13 +731,13 @@ gameloop() { // BOUNCE off left or right edge of screen if(ship.x < 0 || ship.x+ship.w > XSIZE) { ship.x -= (ship.dx-screendx)*t_frame; - ship.dx = screendx - (ship.dx-screendx)*opt_bounciness; + ship.dx = screendx - (ship.dx-screendx)*BOUNCINESS; } // BOUNCE off top or bottom of screen if(ship.y < 0 || ship.y+ship.h > YSIZE) { ship.y -= (ship.dy-screendy)*t_frame; - ship.dy = screendy - (ship.dy-screendy)*opt_bounciness; + ship.dy = screendy - (ship.dy-screendy)*BOUNCINESS; } draw(); @@ -752,17 +754,17 @@ gameloop() { g_easy = 0; initial_rocks = NORMAL_I_ROCKS; final_rocks = NORMAL_F_ROCKS; - if(opt_gamespeed == EASY_GAMESPEED) - opt_gamespeed = NORMAL_GAMESPEED; + if(gamespeed == EASY_GAMESPEED) + gamespeed = NORMAL_GAMESPEED; } else if(keystate[SDLK_1]) { g_easy = 1; initial_rocks = EASY_I_ROCKS; final_rocks = EASY_F_ROCKS; - opt_gamespeed = EASY_GAMESPEED; + gamespeed = EASY_GAMESPEED; } reset_sprites(); reset_rocks(); - screendx = SCREENDXMIN; screendy = 0; + screendx = BARRIER_SPEED; screendy = 0; ship.x = XSIZE/2.2; ship.y = YSIZE/2 - ship.w/2; ship.dx = screendx; ship.dy = screendy; -- 1.7.10.4