From: Joshua Grams Date: Sat, 9 Jul 2005 11:29:53 +0000 (+0000) Subject: removed debug stuff because it ws useless. X-Git-Tag: 0.4~46 X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=commitdiff_plain;h=1aa8a0df26ef582dee4ffe3aa2f17f1f1a42b3c9 removed debug stuff because it ws useless. removed some unnecessary globals. went back to using ticks for everything (gives nice sized numbers for things). --- diff --git a/Makefile b/Makefile index 994cd8b..01499e2 100644 --- a/Makefile +++ b/Makefile @@ -21,16 +21,15 @@ PROGRAM_PREFIX := /usr/games/bin CFLAGS := -Wall LDFLAGS := -debug := $(if $(DEBUG),-DDEBUG=1) paths := -DDATA_PREFIX=\"$(DATA_PREFIX)\" sdl-cflags := $(shell sdl-config --cflags) sdl-ldflags := $(shell sdl-config --libs) ldflags := $(sdl-ldflags) -lSDL_image -lSDL_mixer $(LDFLAGS) -cflags := $(sdl-cflags) $(debug) $(paths) $(CFLAGS) +cflags := $(sdl-cflags) $(paths) $(CFLAGS) my_objects := args.o dust.o file.o mt.o rocks.o score.o shape.o sound.o -my_objects += $(if $(DEBUG),debug.o) main.o +my_objects += main.o libs := SFont.o objects := $(libs) $(my_objects) diff --git a/common.h b/common.h index be0910e..069f677 100644 --- a/common.h +++ b/common.h @@ -28,10 +28,4 @@ #define CONDERROR(a) if((a)) {initerror = strdup(SDL_GetError());return 1;} #define NULLERROR(a) CONDERROR((a) == NULL) -#ifndef DEBUG -#define DEBUG 0 -#endif - -#define debug(x) if(DEBUG) { x; } - #endif // VOR_COMMON_H diff --git a/debug.c b/debug.c deleted file mode 100644 index c59dcbb..0000000 --- a/debug.c +++ /dev/null @@ -1,51 +0,0 @@ -#include "debug.h" -#include "shape.h" - -#include -#include - -void -printf_surface(SDL_Surface *s, char *name) -{ - printf("SDL_Surface *%s = {\n", name); - printf("\tflags = 0x%x;\n", s->flags); - printf("\tformat = {\n"); - printf("\t\tBitsPerPixel = %d;\n", s->format->BitsPerPixel); - printf("\t\tBytesPerPixel = %d;\n", s->format->BytesPerPixel); - printf("\t\tmasks = 0x%x, 0x%x, 0x%x, 0x%x;\n", s->format->Rmask, s->format->Gmask, - s->format->Bmask, s->format->Amask); - printf("\t\tshifts = %d, %d, %d, %d;\n", s->format->Rshift, s->format->Gshift, - s->format->Bshift, s->format->Ashift); - printf("\t\tlosses = %d, %d, %d, %d;\n", s->format->Rloss, s->format->Gloss, - s->format->Bloss, s->format->Aloss); - printf("\t\tcolorkey = %d;\n", s->format->colorkey); - printf("\t\talpha = %d;\n", s->format->alpha); - printf("\t};\n"); - printf("\tw, h = %d, %d;\n", s->w, s->h); - printf("\tpitch = %d;\n", s->pitch); - printf("};\n"); -} - -void -printb(uint32_t n, int bits) -{ - int i; - - for(i=0; ih; i++) { - for(j=0; jmw-1; j++) printb(s->mask[s->mw*i+j], 32); - printb(s->mask[s->mw*i+j], s->w % 32); - putchar('\n'); - } - putchar('\n'); -} diff --git a/debug.h b/debug.h deleted file mode 100644 index 01d90a8..0000000 --- a/debug.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef VOR_DEBUG_H -#define VOR_DEBUG_H - -#include - -void printf_surface(SDL_Surface *s, char *name); - -#endif // VOR_DEBUG_H diff --git a/globals.h b/globals.h index 8d0d962..bf5e1da 100644 --- a/globals.h +++ b/globals.h @@ -51,22 +51,18 @@ extern char topline[1024]; extern char *initerror; extern struct shape shipshape; -extern float shipx,shipy; // X position, 0..XSIZE -extern float shipdx,shipdy; // Change in X position per tick. +extern float shipx,shipy; // ship position on screen +extern float shipdx,shipdy; // ship speed (pixels/tick) extern float screendx, screendy; extern float xscroll, yscroll; extern float yscroll; extern float scrollvel; -// all movement is based on s_frame. +// All movement is based on t_frame. +// All speeds are pixels/tick, with 20 ticks per second. extern float t_frame; // length of this frame (in ticks = 1/20th second) -extern float s_frame; // length of this frame (seconds) -extern int ms_frame; // length of this frame (milliseconds) -extern int ms_end; // end of this frame (milliseconds) extern int nships,score; -extern int gameover; -extern int maneuver; extern float fadetimer, faderate; extern int pausedown, paused; diff --git a/main.c b/main.c index c32feb3..09d7cc5 100644 --- a/main.c +++ b/main.c @@ -30,10 +30,6 @@ #include "SFont.h" -#ifdef DEBUG -#include "debug.h" -#endif - #include "args.h" #include "common.h" #include "config.h" @@ -71,8 +67,6 @@ struct bangdots bdot[MAXBANGDOTS], *bdotptr = bdot; char topline[1024]; char *initerror = ""; - - struct shape shipshape; float shipx = XSIZE/2, shipy = YSIZE/2; // X position, 0..XSIZE float shipdx = SCREENDXMIN, shipdy = 0.0; // Change in X position per tick. @@ -82,14 +76,12 @@ float back_dist; // all movement is based on t_frame. float t_frame; // length of this frame (in ticks = 1/20th second) -float s_frame; // length of this frame (seconds) int ms_frame; // length of this frame (milliseconds) int ms_end; // end of this frame (milliseconds) float bangx, bangy, bangdx, bangdy; int nships,score; -int gameover; int jets = 0; float fadetimer = 0, faderate; @@ -423,7 +415,7 @@ draw() { drawdots(surf_screen); // Draw ship - if(!gameover && state == GAMEPLAY ) { + if(state == GAMEPLAY ) { dest.x = shipx; dest.y = shipy; SDL_BlitSurface(surf_ship,NULL,surf_screen,&dest); @@ -432,11 +424,12 @@ draw() { draw_rocks(); // Draw the life indicators. - if(state == GAMEPLAY || state == DEAD_PAUSE || state == GAME_OVER) - for(i = 0; iw + 10); - dest.y = 20; - SDL_BlitSurface(surf_life, NULL, surf_screen, &dest); + if(state == GAMEPLAY || state == DEAD_PAUSE || state == GAME_OVER) { + for(i = 0; iw + 10); + dest.y = 20; + SDL_BlitSurface(surf_life, NULL, surf_screen, &dest); + } } // Draw the score @@ -521,7 +514,7 @@ draw() { ; // no action necessary } - if(!gameover && state == GAMEPLAY) { + if(state == GAMEPLAY) { bang = hit_rocks(shipx, shipy, &shipshape); } @@ -530,13 +523,12 @@ draw() { if(ms_frame>200 || ms_frame<0) { // We won't run at all below 5 frames per second. // This also happens if we were paused, grr. - s_frame = 0; + t_frame = 0; ms_frame = 0; } else { - s_frame = opt_gamespeed * ms_frame / 1000; + t_frame = opt_gamespeed * ms_frame / 50; if(state == GAMEPLAY) score += ms_frame; } - t_frame = s_frame * 20; // Update the surface SDL_Flip(surf_screen); @@ -617,17 +609,18 @@ gameloop() { screendy += tmp * t_frame/12; tmp = (shipx-XSCROLLTO)/25 + (shipdx-screendx); screendx += tmp * t_frame/12; - - // taper off if we would hit the barrier in under 2 seconds. + // 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)); } - xscroll = screendx * t_frame; - yscroll = screendy * t_frame; back_dist += (screendx - SCREENDXMIN)*t_frame; if(opt_max_lead >= 0) back_dist = min(back_dist, opt_max_lead); + xscroll = screendx * t_frame; + yscroll = screendy * t_frame; + shipx -= xscroll; shipy -= yscroll; @@ -662,8 +655,7 @@ gameloop() { if(shipdx < SCREENDXMIN) shipdx = SCREENDXMIN; if(--nships <= 0) { state = GAME_OVER; - gameover = 1; - shipdx = 8; shipdy = 0; + shipdx = SCREENDXMIN; shipdy = 0; state_timeout = 200.0; fadetimer = 0.0; faderate = t_frame; @@ -688,7 +680,6 @@ gameloop() { state = GAMEPLAY; play_tune(TUNE_GAMEPLAY); - gameover = 0; shipx = XSIZE/2.2; shipy = YSIZE/2; shipdx = screendx; shipdy = screendy; } @@ -700,28 +691,20 @@ gameloop() { } if(state == GAMEPLAY) { - if(!gameover) { - - if(!paused) { - if(keystate[SDLK_LEFT] | keystate[SDLK_h]) { shipdx -= 1.5*t_frame; jets |= 1<<0;} - if(keystate[SDLK_DOWN] | keystate[SDLK_t]) { shipdy += 1.5*t_frame; jets |= 1<<1;} - if(keystate[SDLK_RIGHT] | keystate[SDLK_n]) { shipdx += 1.5*t_frame; jets |= 1<<2;} - if(keystate[SDLK_UP] | keystate[SDLK_c]) { shipdy -= 1.5*t_frame; jets |= 1<<3;} - if(keystate[SDLK_3]) { SDL_SaveBMP(surf_screen, "snapshot.bmp"); } - } + if(!paused) { + if(keystate[SDLK_LEFT] | keystate[SDLK_h]) { shipdx -= 1.5*t_frame; jets |= 1<<0;} + if(keystate[SDLK_DOWN] | keystate[SDLK_t]) { shipdy += 1.5*t_frame; jets |= 1<<1;} + if(keystate[SDLK_RIGHT] | keystate[SDLK_n]) { shipdx += 1.5*t_frame; jets |= 1<<2;} + if(keystate[SDLK_UP] | keystate[SDLK_c]) { shipdy -= 1.5*t_frame; jets |= 1<<3;} + if(keystate[SDLK_3]) { SDL_SaveBMP(surf_screen, "snapshot.bmp"); } + } - if(keystate[SDLK_p] | keystate[SDLK_s]) { - if(!pausedown) { - paused = !paused; - pausedown = 1; - } - } else { - pausedown = 0; + if(keystate[SDLK_p] | keystate[SDLK_s]) { + if(!pausedown) { + paused = !paused; + pausedown = 1; } - - } - else { - paused = 0; + } else { pausedown = 0; } } else if(state == GAME_OVER) { diff --git a/rocks.c b/rocks.c index 0b54b04..ceddd4b 100644 --- a/rocks.c +++ b/rocks.c @@ -28,12 +28,12 @@ struct shape rock_shapes[NROCKS]; float rtimers[4]; uint32_t nrocks; -uint32_t nrocks_timer; -uint32_t nrocks_inc_ticks = 2*60*1000/(F_ROCKS-I_ROCKS); +float nrocks_timer; +float nrocks_inc_ticks = 2*60*20/(F_ROCKS-I_ROCKS); // constants for rock generation. -#define KH 32.0 // 32 s for a speed=1 rock to cross the screen horizontally. -#define KV 24.0 // 24 s for a speed=1 rock to cross the screen vertically. +#define KH (32.0*20) // 32 s for a speed=1 rock to cross the screen horizontally. +#define KV (24.0*20) // 24 s for a speed=1 rock to cross the screen vertically. #define RDX 2.5 // range for rock dx values (+/-) #define RDY 2.5 // range for rock dy values (+/-) @@ -142,10 +142,11 @@ new_rocks(void) float rmax[4]; if(nrocks < F_ROCKS) { - nrocks_timer += ms_frame; + nrocks_timer += t_frame; if(nrocks_timer >= nrocks_inc_ticks) { nrocks_timer -= nrocks_inc_ticks; nrocks++; + printf("nrocks = %d.\n", nrocks); } } @@ -154,7 +155,7 @@ new_rocks(void) // loop through the four sides of the screen for(i=0; i<4; i++) { // see if we generate a rock for this side this frame - rtimers[i] += ti[i]*s_frame; + rtimers[i] += ti[i]*t_frame; while(rtimers[i] >= 1) { rtimers[i] -= 1; j=0; diff --git a/sound.c b/sound.c index 7f369ae..1a69535 100644 --- a/sound.c +++ b/sound.c @@ -37,7 +37,6 @@ init_sound() { // Return 1 if the sound is ready to roll, and 0 if not. int i; - debug(printf ("Initialise sound\n")); // Initialise output with SDL_mixer if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, AUDIO_S16, MIX_DEFAULT_CHANNELS, 4096) < 0) { @@ -45,15 +44,6 @@ init_sound() { return 0; } - debug( - // What kind of sound did we get? Ah who cares. As long as it can play - // some basic bangs and simple music. - Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels); - printf("Opened audio at %d Hz %d bit %s\n", audio_rate, - (audio_format&0xFF), - (audio_channels > 1) ? "stereo" : "mono"); - ) - // Preload all the tunes into memory for (i=0; i