From: Joshua Grams Date: Thu, 7 Jul 2005 18:11:01 +0000 (+0000) Subject: renamed framelen and friends (again) X-Git-Tag: 0.4~50 X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=commitdiff_plain;h=286cb1818d7d2787c8a19f5cf34947e7300bc536 renamed framelen and friends (again) --- diff --git a/globals.h b/globals.h index 3fb2a05..4eb58f1 100644 --- a/globals.h +++ b/globals.h @@ -62,11 +62,15 @@ extern float shipx,shipy; // X position, 0..XSIZE extern float shipdx,shipdy; // Change in X position per tick. extern float screendx, screendy; extern float xscroll, yscroll; -extern float framelen; // this controls the speed of everything that moves. extern float yscroll; extern float scrollvel; -extern int nships,score,initticks,ticks_since_last, last_ticks; +// all movement is based on s_frame. +float t_frame; // length of this frame (in ticks = 1/20th second) +int ms_frame; // length of this frame (milliseconds) +int ms_end; // end of this frame (milliseconds) + +extern int nships,score; extern int gameover; extern int maneuver; extern float fadetimer, faderate; diff --git a/main.c b/main.c index a2bdcbc..9b04f07 100644 --- a/main.c +++ b/main.c @@ -78,11 +78,15 @@ float shipdx = SCREENDXMIN, shipdy = 0.0; // Change in X position per tick. float screendx = SCREENDXMIN, screendy = 0.0; float xscroll, yscroll; float back_dist; -float framelen; // this controls the speed of everything that moves. + +// all movement is based on t_frame. +float t_frame; // length of this frame (in ticks = 1/20th second) +int ms_frame; // length of this frame (milliseconds) +int ms_end; // end of this frame (milliseconds) float bangx, bangy, bangdx, bangdy; -int nships,score,ticks_since_last,last_ticks; +int nships,score; int gameover; int maneuver = 0; @@ -228,8 +232,8 @@ draw_bang_dots(SDL_Surface *s) { //last_i = i + 1; rawpixel[(int)(s->pitch/2*(int)(bdot[i].y)) + (int)(bdot[i].x)] = bdot[i].c ? bdot[i].c : heatcolor[(int)(bdot[i].life*3)]; bdot[i].life -= bdot[i].decay; - bdot[i].x += bdot[i].dx*framelen - xscroll; - bdot[i].y += bdot[i].dy*framelen - yscroll; + bdot[i].x += bdot[i].dx*t_frame - xscroll; + bdot[i].y += bdot[i].dy*t_frame - yscroll; if(bdot[i].life<0) bdot[i].active = 0; @@ -276,9 +280,9 @@ draw_engine_dots(SDL_Surface *s) { for(i = 0; iYSIZE) { + edot[i].x += edot[i].dx*t_frame - xscroll; + edot[i].y += edot[i].dy*t_frame - yscroll; + if((edot[i].life -= t_frame*3)<0 || edot[i].y<0 || edot[i].y>YSIZE) { edot[i].active = 0; } else if(edot[i].x<0 || edot[i].x>XSIZE) { edot[i].active = 0; @@ -300,7 +304,7 @@ create_engine_dots(int newdots) { if(!opt_tail_engine) return; if(state == GAMEPLAY) { - for(i = 0; iactive == 0) { theta = rnd()*M_PI*2; r = rnd(); @@ -545,7 +549,7 @@ draw() { dest.x = (XSIZE-surf_b_game->w)/2; dest.y = (YSIZE-surf_b_game->h)/2-40; - SDL_SetAlpha(surf_b_game, SDL_SRCALPHA, (int)(fadegame*(200 + 55*cos(fadetimer += framelen/1.0)))); + SDL_SetAlpha(surf_b_game, SDL_SRCALPHA, (int)(fadegame*(200 + 55*cos(fadetimer += t_frame/1.0)))); SDL_BlitSurface(surf_b_game,NULL,surf_screen,&dest); dest.x = (XSIZE-surf_b_over->w)/2; @@ -558,7 +562,7 @@ draw() { dest.x = (XSIZE-surf_b_variations->w)/2 + cos(fadetimer/6.5)*10; dest.y = (YSIZE/2-surf_b_variations->h)/2 + sin(fadetimer/5.0)*10; - SDL_SetAlpha(surf_b_variations, SDL_SRCALPHA, (int)(200 + 55*sin(fadetimer += framelen/2.0))); + SDL_SetAlpha(surf_b_variations, SDL_SRCALPHA, (int)(200 + 55*sin(fadetimer += t_frame/2.0))); SDL_BlitSurface(surf_b_variations,NULL,surf_screen,&dest); dest.x = (XSIZE-surf_b_on->w)/2 + cos((fadetimer + 1.0)/6.5)*10; @@ -609,15 +613,15 @@ draw() { bang = hit_rocks(shipx, shipy, &shipshape); } - ticks_since_last = SDL_GetTicks()-last_ticks; - last_ticks = SDL_GetTicks(); - if(ticks_since_last>200 || ticks_since_last<0) { + ms_frame = SDL_GetTicks() - ms_end; + ms_end += ms_frame; + if(ms_frame>200 || ms_frame<0) { // We won't run at all below 5 frames per second. - framelen = 0; + t_frame = 0; } else { - framelen = opt_gamespeed*ticks_since_last/50.0; + t_frame = opt_gamespeed*ms_frame/50.0; if(state == GAMEPLAY) { - score += ticks_since_last; + score += ms_frame; } } @@ -638,7 +642,7 @@ gameloop() { if(!paused) { // Count down the game loop timer, and change state when it gets to zero or less; - if((state_timeout -= framelen*3) < 0) { + if((state_timeout -= t_frame*3) < 0) { switch(state) { case DEAD_PAUSE: // Create a new ship and start all over again @@ -696,24 +700,24 @@ gameloop() { // FRICTION? if(opt_friction) { - shipdx *= pow((double)0.9,(double)framelen); - shipdy *= pow((double)0.9,(double)framelen); + shipdx *= pow((double)0.9,(double)t_frame); + shipdy *= pow((double)0.9,(double)t_frame); } // INERTIA - shipx += shipdx*framelen; - shipy += shipdy*framelen; + shipx += shipdx*t_frame; + shipy += shipdy*t_frame; // SCROLLING tmp = shipy - (YSIZE / 2); tmp += shipdy * 25; tmp /= -25; - tmp = ((screendy * (framelen - 12)) + (tmp * framelen)) / 12; + tmp = ((screendy * (t_frame - 12)) + (tmp * t_frame)) / 12; screendy = -tmp; tmp = shipx - (XSIZE / 3); tmp += shipdx * 25; tmp /= -25; - tmp = ((screendx * (framelen - 12)) + (tmp * framelen)) / 12; + tmp = ((screendx * (t_frame - 12)) + (tmp * t_frame)) / 12; screendx = -tmp; // taper off if we would hit the barrier in under 2 seconds. @@ -721,17 +725,17 @@ gameloop() { screendx = SCREENDXMIN - (back_dist/TO_TICKS(2)); } - xscroll = screendx * framelen; - yscroll = screendy * framelen; - back_dist += (screendx - SCREENDXMIN)*framelen; + 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); shipx -= xscroll; shipy -= yscroll; // move bang center - bangx += bangdx*framelen - xscroll; - bangy += bangdy*framelen - yscroll; + bangx += bangdx*t_frame - xscroll; + bangy += bangdy*t_frame - yscroll; move_rocks(); @@ -739,14 +743,14 @@ gameloop() { // BOUNCE X if(shipx<0 || shipx>XSIZE-surf_ship->w) { // BOUNCE from left and right wall - shipx -= (shipdx-screendx)*framelen; + shipx -= (shipdx-screendx)*t_frame; shipdx = screendx - (shipdx-screendx)*opt_bounciness; } // BOUNCE Y if(shipy<0 || shipy>YSIZE-surf_ship->h) { // BOUNCE from top and bottom wall - shipy -= (shipdy-screendy)*framelen; + shipy -= (shipdy-screendy)*t_frame; shipdy = screendy - (shipdy-screendy)*opt_bounciness; } @@ -764,7 +768,7 @@ gameloop() { shipdx = 8; shipdy = 0; state_timeout = 200.0; fadetimer = 0.0; - faderate = framelen; + faderate = t_frame; } else { state = DEAD_PAUSE; @@ -801,10 +805,10 @@ gameloop() { if(!gameover) { if(!paused) { - if(keystate[SDLK_UP] | keystate[SDLK_c]) { shipdy -= 1.5*framelen; maneuver |= 1<<3;} - if(keystate[SDLK_DOWN] | keystate[SDLK_t]) { shipdy += 1.5*framelen; maneuver |= 1<<1;} - if(keystate[SDLK_LEFT] | keystate[SDLK_h]) { shipdx -= 1.5*framelen; maneuver |= 1<<2;} - if(keystate[SDLK_RIGHT] | keystate[SDLK_n]) { shipdx += 1.5*framelen; maneuver |= 1;} + if(keystate[SDLK_UP] | keystate[SDLK_c]) { shipdy -= 1.5*t_frame; maneuver |= 1<<3;} + if(keystate[SDLK_DOWN] | keystate[SDLK_t]) { shipdy += 1.5*t_frame; maneuver |= 1<<1;} + if(keystate[SDLK_LEFT] | keystate[SDLK_h]) { shipdx -= 1.5*t_frame; maneuver |= 1<<2;} + if(keystate[SDLK_RIGHT] | keystate[SDLK_n]) { shipdx += 1.5*t_frame; maneuver |= 1;} if(keystate[SDLK_3]) { SDL_SaveBMP(surf_screen, "snapshot.bmp"); } } diff --git a/rocks.c b/rocks.c index 03f8671..5518c41 100644 --- a/rocks.c +++ b/rocks.c @@ -145,7 +145,7 @@ new_rocks(void) float rmax[4]; if(nrocks < F_ROCKS) { - nrocks_timer += ticks_since_last; + nrocks_timer += ms_frame; if(nrocks_timer >= nrocks_inc_ticks) { nrocks_timer -= nrocks_inc_ticks; nrocks++; @@ -157,7 +157,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]*framelen/20; + rtimers[i] += ti[i]*t_frame/20; while(rtimers[i] >= 1) { rtimers[i] -= 1; j=0; @@ -215,8 +215,8 @@ move_rocks(void) for(i = 0; i < MAXROCKS; i++) { if(rock[i].active) { // move - rock[i].x += (rock[i].dx-screendx)*framelen; - rock[i].y += (rock[i].dy-screendy)*framelen; + rock[i].x += (rock[i].dx-screendx)*t_frame; + rock[i].y += (rock[i].dy-screendy)*t_frame; // clip if(rock[i].x < -rock[i].image->w || rock[i].x >= XSIZE || rock[i].y < -rock[i].image->h || rock[i].y >= YSIZE) { diff --git a/rocks.h b/rocks.h index 9297012..e6a6274 100644 --- a/rocks.h +++ b/rocks.h @@ -1,4 +1,3 @@ -#include #include "shape.h" int init_rocks(void);