X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=rocks.c;h=e47bc44c044f71984277808ff4a412e8c153d76a;hp=ca921cf22522e6435c827acd811b23c8d06ebb7d;hb=4461dfec6f8f09b43ec9719523d14978d82bd124;hpb=d96cae8368715101e2bf3f9ff8900dc171c70b2f diff --git a/rocks.c b/rocks.c index ca921cf..e47bc44 100644 --- a/rocks.c +++ b/rocks.c @@ -24,7 +24,10 @@ struct shape rock_shapes[NROCKS]; // timers for rock generation. float rtimers[4]; -int nrocks; + +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. @@ -50,7 +53,6 @@ init_rocks(void) NULLERROR(surf_rock[i] = SDL_DisplayFormat(temp)); get_shape(surf_rock[i], &rock_shapes[i]); } - nrocks = 41; return 0; } @@ -60,66 +62,109 @@ reset_rocks(void) int i; for(i = 0; i= nrocks_inc_ticks) { + nrocks_timer -= nrocks_inc_ticks; + nrocks++; + } + } - rock_timer_increments(ti); + 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]*gamerate/20; - if(rtimers[i] >= 1) { + while(rtimers[i] >= 1) { + rtimers[i] -= 1; j=0; while(rockptr->active && j= MAXROCKS) rockptr = rock; j++; } if(!rockptr->active) { - rtimers[i] -= 1; rockptr->type_number = random() % NROCKS; rockptr->image = surf_rock[rockptr->type_number]; rockptr->shape = &rock_shapes[rockptr->type_number]; @@ -127,24 +172,33 @@ new_rocks(void) 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->dx = RDX*crnd(); - rockptr->dy = RDY*crnd(); - rockptr->active = 1; } }