JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
removed debug stuff because it ws useless.
authorJoshua Grams <josh@qualdan.com>
Sat, 9 Jul 2005 11:29:53 +0000 (11:29 +0000)
committerJoshua Grams <josh@qualdan.com>
Sat, 9 Jul 2005 11:29:53 +0000 (11:29 +0000)
removed some unnecessary globals.
went back to using ticks for everything (gives nice sized numbers for things).

Makefile
common.h
debug.c [deleted file]
debug.h [deleted file]
globals.h
main.c
rocks.c
sound.c

index 994cd8b..01499e2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -21,16 +21,15 @@ PROGRAM_PREFIX := /usr/games/bin
 CFLAGS := -Wall
 LDFLAGS := 
 
 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)
 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 := 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)
 
 libs := SFont.o
 objects := $(libs) $(my_objects)
 
index be0910e..069f677 100644 (file)
--- a/common.h
+++ b/common.h
 #define CONDERROR(a) if((a)) {initerror = strdup(SDL_GetError());return 1;}
 #define NULLERROR(a) CONDERROR((a) == NULL)
 
 #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
 #endif // VOR_COMMON_H
diff --git a/debug.c b/debug.c
deleted file mode 100644 (file)
index c59dcbb..0000000
--- a/debug.c
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "debug.h"
-#include "shape.h"
-
-#include <stdio.h>
-#include <stdint.h>
-
-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; i<bits; i++) {
-               if(n & 0x80000000) putchar('1'); else putchar('0');
-               n = n << 1;
-       }
-}
-
-void
-print_mask(struct shape *s)
-{
-       int i, j;
-
-       for(i=0; i<s->h; i++) {
-               for(j=0; j<s->mw-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 (file)
index 01d90a8..0000000
--- a/debug.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef VOR_DEBUG_H
-#define VOR_DEBUG_H
-
-#include <SDL.h>
-
-void printf_surface(SDL_Surface *s, char *name);
-
-#endif // VOR_DEBUG_H
index 8d0d962..bf5e1da 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -51,22 +51,18 @@ extern char topline[1024];
 extern char *initerror;
 
 extern struct shape shipshape;
 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;
 
 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 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 nships,score;
-extern int gameover;
-extern int maneuver;
 extern float fadetimer, faderate;
 
 extern int pausedown, paused;
 extern float fadetimer, faderate;
 
 extern int pausedown, paused;
diff --git a/main.c b/main.c
index c32feb3..09d7cc5 100644 (file)
--- a/main.c
+++ b/main.c
 
 #include "SFont.h"
 
 
 #include "SFont.h"
 
-#ifdef DEBUG
-#include "debug.h"
-#endif
-
 #include "args.h"
 #include "common.h"
 #include "config.h"
 #include "args.h"
 #include "common.h"
 #include "config.h"
@@ -71,8 +67,6 @@ struct bangdots bdot[MAXBANGDOTS], *bdotptr = bdot;
 char topline[1024];
 char *initerror = "";
 
 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.
 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)
 
 // 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 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;
 int jets = 0;
 
 float fadetimer = 0, faderate;
@@ -423,7 +415,7 @@ draw() {
        drawdots(surf_screen);
 
        // Draw ship
        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);
                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.
        draw_rocks();
 
        // Draw the life indicators.
-       if(state == GAMEPLAY || state == DEAD_PAUSE || state == GAME_OVER)
-       for(i = 0; i<nships-1; i++) {
-               dest.x = (i + 1)*(surf_life->w + 10);
-               dest.y = 20;
-               SDL_BlitSurface(surf_life, NULL, surf_screen, &dest);
+       if(state == GAMEPLAY || state == DEAD_PAUSE || state == GAME_OVER) {
+               for(i = 0; i<nships-1; i++) {
+                       dest.x = (i + 1)*(surf_life->w + 10);
+                       dest.y = 20;
+                       SDL_BlitSurface(surf_life, NULL, surf_screen, &dest);
+               }
        }
 
        // Draw the score
        }
 
        // Draw the score
@@ -521,7 +514,7 @@ draw() {
                        ; // no action necessary
        }
 
                        ; // no action necessary
        }
 
-       if(!gameover && state == GAMEPLAY) {
+       if(state == GAMEPLAY) {
                bang = hit_rocks(shipx, shipy, &shipshape);
        }
 
                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.
        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 {
                ms_frame = 0;
        } else {
-               s_frame = opt_gamespeed * ms_frame / 1000;
+               t_frame = opt_gamespeed * ms_frame / 50;
                if(state == GAMEPLAY) score += ms_frame;
        }
                if(state == GAMEPLAY) score += ms_frame;
        }
-       t_frame = s_frame * 20;
 
        // Update the surface
        SDL_Flip(surf_screen);
 
        // 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;
                        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));
                        }
 
                        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);
 
                        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;
 
                        shipx -= xscroll;
                        shipy -= yscroll;
 
@@ -662,8 +655,7 @@ gameloop() {
                                if(shipdx < SCREENDXMIN) shipdx = SCREENDXMIN;
                                if(--nships <= 0) {
                                        state = GAME_OVER;
                                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;
                                        state_timeout = 200.0;
                                        fadetimer = 0.0;
                                        faderate = t_frame;
@@ -688,7 +680,6 @@ gameloop() {
                                state = GAMEPLAY;
                                play_tune(TUNE_GAMEPLAY);
 
                                state = GAMEPLAY;
                                play_tune(TUNE_GAMEPLAY);
 
-                               gameover = 0;
                                shipx = XSIZE/2.2; shipy = YSIZE/2;
                                shipdx = screendx; shipdy = screendy;
                        }
                                shipx = XSIZE/2.2; shipy = YSIZE/2;
                                shipdx = screendx; shipdy = screendy;
                        }
@@ -700,28 +691,20 @@ gameloop() {
                }
 
                if(state == GAMEPLAY) {
                }
 
                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) {
                                pausedown = 0;
                        }
                } else if(state == GAME_OVER) {
diff --git a/rocks.c b/rocks.c
index 0b54b04..ceddd4b 100644 (file)
--- a/rocks.c
+++ b/rocks.c
@@ -28,12 +28,12 @@ struct shape rock_shapes[NROCKS];
 float rtimers[4];
 
 uint32_t 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.
 
 // 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 (+/-)
 
 #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) {
        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++;
                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
        // 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;
                while(rtimers[i] >= 1) {
                        rtimers[i] -= 1;
                        j=0;
diff --git a/sound.c b/sound.c
index 7f369ae..1a69535 100644 (file)
--- 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;
        // 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) {
 
        // 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;
        }
 
        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<NUM_TUNES; i++) {
                if (!(music[i] = Mix_LoadMUS(add_path(tune_file[i])))) {
        // Preload all the tunes into memory
        for (i=0; i<NUM_TUNES; i++) {
                if (!(music[i] = Mix_LoadMUS(add_path(tune_file[i])))) {
@@ -72,7 +62,6 @@ init_sound() {
 void
 play_sound(int i)  {
        if(!opt_sound) return;
 void
 play_sound(int i)  {
        if(!opt_sound) return;
-       debug(printf ("play sound %d on first free channel\n",i));
        Mix_PlayChannel(-1, wav[i], 0);
 }/*}}}*/
 
        Mix_PlayChannel(-1, wav[i], 0);
 }/*}}}*/
 
@@ -86,12 +75,7 @@ play_tune(int i) {/*{{{*/
        return;
        if (playing) {
                Mix_FadeOutMusic(1500);
        return;
        if (playing) {
                Mix_FadeOutMusic(1500);
-               debug(printf("Stop playing %d\n",playing));
        }
        }
-       debug(
-                       printf ("Play music %d\n",i);
-                       printf ("volume %d\n",music_volume[i]);
-                       )
        Mix_FadeInMusic(music[i],-1,2000);
        Mix_VolumeMusic(music_volume[i]);
 
        Mix_FadeInMusic(music[i],-1,2000);
        Mix_VolumeMusic(music_volume[i]);