X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=rocks.c;h=03f8671804bdb6ebe44f4804b06fe9e75ea158a2;hp=1e69ce2342a2bad00e5f5023b4ee364314f1467b;hb=e0fab1bd78914a12ee88f2a9fcfca9f28a1df0f2;hpb=36430b3c87da1304d1de5bf9d294545f46d6f3a0 diff --git a/rocks.c b/rocks.c index 1e69ce2..03f8671 100644 --- a/rocks.c +++ b/rocks.c @@ -3,6 +3,7 @@ #include #include +#include "common.h" #include "config.h" #include "file.h" #include "globals.h" @@ -19,23 +20,25 @@ struct rock_struct { struct rock_struct rock[MAXROCKS], *rockptr = rock; -float rockrate; - SDL_Surface *surf_rock[NROCKS]; struct shape rock_shapes[NROCKS]; -float rockhtimer = 0; -int nrocks = 41; +// timers for rock generation. +float rtimers[4]; + +uint32_t nrocks; +uint32_t nrocks_timer; +uint32_t nrocks_inc_ticks = 2*60*1000/(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 RDX 2.5 // range for rock dx values (+/-) +#define RDY 2.5 // range for rock dy values (+/-) float rnd(void); -// used for rock generation. -#define KH (1.0/32.0) -#define KV (1.0/24.0) -#define RXMIN 5.0 -#define RXMAX 10.0 -#define RYMIN (-0.5) -#define RYMAX 0.5 +#define crnd() (2*(rnd()-0.5)) int @@ -59,33 +62,146 @@ reset_rocks(void) { int i; - for(i = 0; i= 1) { - while(rockptr->active && i= MAXROCKS) rockptr = rock; - i++; + int i,j; + float ti[4]; + float rmin[4]; + float rmax[4]; + + if(nrocks < F_ROCKS) { + nrocks_timer += ticks_since_last; + if(nrocks_timer >= nrocks_inc_ticks) { + nrocks_timer -= nrocks_inc_ticks; + nrocks++; } - if(!rockptr->active) { - rockhtimer -= 1; - rockptr->dx = -5.0*(1.0 + rnd()); - rockptr->dy = rnd()-0.5; - rockptr->type_number = random() % NROCKS; - rockptr->image = surf_rock[rockptr->type_number]; - rockptr->shape = &rock_shapes[rockptr->type_number]; - rockptr->x = (float)XSIZE; - rockptr->y = rnd()*(YSIZE + rockptr->image->h); - rockptr->active = 1; + } + + rock_sides(ti, rmin, rmax); + + // 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; + while(rtimers[i] >= 1) { + rtimers[i] -= 1; + j=0; + while(rockptr->active && j= MAXROCKS) rockptr = rock; + j++; + } + if(!rockptr->active) { + rockptr->type_number = random() % NROCKS; + rockptr->image = surf_rock[rockptr->type_number]; + rockptr->shape = &rock_shapes[rockptr->type_number]; + switch(i) { + case RIGHT: + rockptr->x = XSIZE; + rockptr->y = rnd()*(YSIZE + rockptr->image->h); + + rockptr->dx = -weighted_rnd_range(rmin[i], rmax[i]) + screendx; + rockptr->dy = RDY*crnd(); + break; + case LEFT: + rockptr->x = -rockptr->image->w; + rockptr->y = rnd()*(YSIZE + rockptr->image->h); + + rockptr->dx = weighted_rnd_range(rmin[i], rmax[i]) + screendx; + rockptr->dy = RDY*crnd(); + break; + case BOTTOM: + rockptr->x = rnd()*(XSIZE + rockptr->image->w); + rockptr->y = YSIZE; + + rockptr->dx = RDX*crnd(); + rockptr->dy = -weighted_rnd_range(rmin[i], rmax[i]) + screendy; + break; + case TOP: + rockptr->x = rnd()*(XSIZE + rockptr->image->w); + rockptr->y = -rockptr->image->h; + + rockptr->dx = RDX*crnd(); + rockptr->dy = weighted_rnd_range(rmin[i], rmax[i]) + screendy; + break; + } + + rockptr->active = 1; + } } } } @@ -99,15 +215,13 @@ move_rocks(void) for(i = 0; i < MAXROCKS; i++) { if(rock[i].active) { // move - rock[i].x += rock[i].dx*gamerate; - rock[i].y += rock[i].dy*gamerate + yscroll; + rock[i].x += (rock[i].dx-screendx)*framelen; + rock[i].y += (rock[i].dy-screendy)*framelen; // clip - if(rock[i].y < -rock[i].image->h || rock[i].y > YSIZE) { - // rock[i].active = 0; - rock[i].y = (YSIZE - rock[i].image->h) - rock[i].y; - rock[i].y += (rock[i].dy*gamerate + yscroll) * 1.01; + if(rock[i].x < -rock[i].image->w || rock[i].x >= XSIZE + || rock[i].y < -rock[i].image->h || rock[i].y >= YSIZE) { + rock[i].active = 0; } - if(rock[i].x < -rock[i].image->w || rock[i].x > XSIZE) rock[i].active = 0; } } } @@ -156,22 +270,24 @@ blast_rocks(float x, float y, float radius, int onlyslow) int i; float dx, dy, n; + if(onlyslow) return; + for(i = 0; i 3)) continue; + if(onlyslow && (rock[i].dx-screendx < -4 || rock[i].dx-screendx > 3)) continue; dx = rock[i].x - x; dy = rock[i].y - y; n = sqrt(dx*dx + dy*dy); if(n < radius) { - n *= 20; - rock[i].dx += rockrate*(dx+30)/n; - rock[i].dy += rockrate*dy/n; + n *= 15; + rock[i].dx += 54.0*dx/n; + rock[i].dy += 54.0*dy/n; } } }