removed some unnecessary globals.
went back to using ticks for everything (gives nice sized numbers for things).
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)
#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
+++ /dev/null
-#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');
-}
+++ /dev/null
-#ifndef VOR_DEBUG_H
-#define VOR_DEBUG_H
-
-#include <SDL.h>
-
-void printf_surface(SDL_Surface *s, char *name);
-
-#endif // VOR_DEBUG_H
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;
#include "SFont.h"
-#ifdef DEBUG
-#include "debug.h"
-#endif
-
#include "args.h"
#include "common.h"
#include "config.h"
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.
// 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;
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);
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
; // no action necessary
}
- if(!gameover && state == GAMEPLAY) {
+ if(state == GAMEPLAY) {
bang = hit_rocks(shipx, shipy, &shipshape);
}
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);
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;
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 = GAMEPLAY;
play_tune(TUNE_GAMEPLAY);
- gameover = 0;
shipx = XSIZE/2.2; shipy = YSIZE/2;
shipdx = screendx; shipdy = screendy;
}
}
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) {
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 (+/-)
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);
}
}
// 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;
// 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) {
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])))) {
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);
}/*}}}*/
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]);