From a726e74233c877dab3aca50e5b31e7652035ae30 Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Tue, 30 May 2006 16:00:45 +0000 Subject: [PATCH] made it so engine dots are created throughout the time of the frame so it looks right even with a big lag. factored out move_engine_dots added now config var THRUSTER_STRENGTH added new config var ENGINE_DOTS_PER_TIC adjusted settings so there are fewer engine dots and they don't push the rocks so hard --- config.h | 13 ++++++---- main.c | 81 +++++++++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 68 insertions(+), 26 deletions(-) diff --git a/config.h b/config.h index 4313697..144b429 100644 --- a/config.h +++ b/config.h @@ -21,23 +21,28 @@ // initial/final counts for rocks-on-screen #define NORMAL_I_ROCKS 20 -#define NORMAL_F_ROCKS 35 +#define NORMAL_F_ROCKS 35 // after 2 minutes #define NORMAL_GAMESPEED 1.0 #define EASY_I_ROCKS 10 -#define EASY_F_ROCKS 25 +#define EASY_F_ROCKS 25 // after 2 minutes #define EASY_GAMESPEED 0.85 // number of rock structs to allocate #define MAXROCKS 120 -#define MAXENGINEDOTS 5000 +#define THRUSTER_STRENGTH 1.5 + +// how many engine dots come out of each thruster per tic (1/20th of a seccond) +#define ENGINE_DOTS_PER_TIC 150 + +#define MAXENGINEDOTS 10000 #define MAXBANGDOTS 50000 #define W 100 #define M 255 // determines how hard they push the rocks. Set to 0 to disable pushing rocks -#define ENGINE_DOT_WEIGHT 0.1 +#define ENGINE_DOT_WEIGHT 0.07 // radius^2 (pixels) which will be cleared of rocks when you die #define BLAST_RADIUS 300 diff --git a/main.c b/main.c index ea1f536..e3a0f83 100644 --- a/main.c +++ b/main.c @@ -75,7 +75,7 @@ float screendx = SCREENDXMIN, screendy = 0.0; float back_dist; // all movement is based on t_frame. -float t_frame; // length of this frame (in ticks = 1/20th second) +float t_frame; // length of this frame (in ticks = 1/20th second) adjusted for gamespeed int ms_frame; // length of this frame (milliseconds) int ms_end; // end of this frame (milliseconds) @@ -225,12 +225,15 @@ draw_bang_dots(SDL_Surface *s) void -new_engine_dots(int n, int dir) { +new_engine_dots(float time_span, int dir) { int i; + int n = time_span * ENGINE_DOTS_PER_TIC; float a, r; // angle, random length float dx, dy; float hx, hy; // half ship width/height. static const int s[4] = { 2, 1, 0, 1 }; + float time; + float accelh, accelv, past_ship_dx, past_ship_dy; hx = ship.image->w / 2; hy = ship.image->h / 2; @@ -243,18 +246,40 @@ new_engine_dots(int n, int dir) { dy = r * -sin(a); // screen y is "backwards". dotptr->active = 1; - dotptr->x = ship.x + s[dir]*hx + (frnd()-0.5)*3; - dotptr->y = ship.y + s[(dir+1)&3]*hy + (frnd()-0.5)*3; + + // dot was created at a random time during the time span + time = frnd() * time_span; // this is how long ago + + // calculate how fast the ship was going when this engine dot was + // created (as if it had a smoothe accelleration). This is used in + // determining the velocity of the dots, but not their starting + // location. + accelh = ((ship.jets >> 2) & 1) - (ship.jets & 1); + accelh *= THRUSTER_STRENGTH * time; + past_ship_dx = ship.dx - accelh; + accelv = ((ship.jets >> 1) & 1) - ((ship.jets >> 3) & 1); + accelv *= THRUSTER_STRENGTH * time; + past_ship_dy = ship.dy - accelv; + + // the starting position (not speed) of the dot is calculated as + // though the ship were traveling at a constant speed for this + // time_span. + dotptr->x = (ship.x - (ship.dx - screendx) * time) + s[dir]*hx; + dotptr->y = (ship.y - (ship.dy - screendy) * time) + s[(dir+1)&3]*hy; if(dir&1) { - dotptr->dx = ship.dx + 2*dx; - dotptr->dy = ship.dy + 20*dy; + dotptr->dx = past_ship_dx + 2*dx; + dotptr->dy = past_ship_dy + 20*dy; dotptr->life = 60 * fabs(dy); } else { - dotptr->dx = ship.dx + 20*dx; - dotptr->dy = ship.dy + 2*dy; + dotptr->dx = past_ship_dx + 20*dx; + dotptr->dy = past_ship_dy + 2*dy; dotptr->life = 60 * fabs(dx); } + // move the dot as though it were created in the past + dotptr->x += (dotptr->dx - screendx) * time; + dotptr->y += (dotptr->dy - screendy) * time; + if(dotptr - edot < MAXENGINEDOTS-1) dotptr++; else dotptr = edot; } @@ -262,6 +287,22 @@ new_engine_dots(int n, int dir) { } void +move_engine_dots() { + int i; + for(i = 0; i= XSIZE || edot[i].y < 0 || edot[i].y >= YSIZE) { + edot[i].active = 0; + } + } +} + +void draw_engine_dots(SDL_Surface *s) { int i; uint16_t c; @@ -271,14 +312,7 @@ draw_engine_dots(SDL_Surface *s) { Sprite *hit; for(i = 0; i= XSIZE - || edot[i].y<0 || edot[i].y >= YSIZE) { - edot[i].active = 0; + if(!edot[i].active) { continue; } // check collisions @@ -300,10 +334,12 @@ void drawdots(SDL_Surface *s) { int m; - // Create engine dots out the side we're moving from + move_engine_dots(); + + // Create engine dots for(m = 0; m<4; m++) { if(ship.jets & 1<