JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
number of rocks on screen now starts at 25, gradually increasing
[vor.git] / rocks.c
diff --git a/rocks.c b/rocks.c
index 7de0c2f..19918ed 100644 (file)
--- 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,6 +62,8 @@ reset_rocks(void)
        int i;
 
        for(i = 0; i<MAXROCKS; i++) rock[i].active = 0;
+       nrocks = I_ROCKS;
+       nrocks_timer = 0;
 }
 
 enum { LEFT, RIGHT, TOP, BOTTOM };
@@ -68,9 +72,11 @@ void
 rock_timer_increments(float *ti)
 {
        float dx0,dx1, dy0,dy1;
+       float hfactor, vfactor;
        int i;
 
        for(i=0; i<4; i++) ti[i] = 0;
+       hfactor = nrocks/KH; vfactor = nrocks/KV;
 
        dx0 = -RDX - screendx; dx1 = RDX - screendx;
        dy0 = -RDY - screendy; dy1 = RDY - screendy;
@@ -84,6 +90,8 @@ rock_timer_increments(float *ti)
                        }
                } else ti[LEFT] = (dx0+dx1)/2;
        }
+       ti[LEFT] *= hfactor;
+       ti[RIGHT] *= hfactor;
 
        if(dy0 != 0) {
                if(dy0 < 0) {
@@ -94,6 +102,8 @@ rock_timer_increments(float *ti)
                        }
                } else ti[TOP] = (dy0+dy1)/2;
        }
+       ti[TOP] *= vfactor;
+       ti[BOTTOM] *= vfactor;
 }
 
 void
@@ -101,7 +111,14 @@ new_rocks(void)
 {
        int i,j;
        float ti[4];
-       float x, y;
+
+       if(nrocks < F_ROCKS) {
+               nrocks_timer += ticks_since_last;
+               if(nrocks_timer >= nrocks_inc_ticks) {
+                       nrocks_timer -= nrocks_inc_ticks;
+                       nrocks++;
+               }
+       }
 
        rock_timer_increments(ti);
 
@@ -137,16 +154,8 @@ new_rocks(void)
                                                break;
                                }
 
-                               j=0;
-                               do {
-                                       rockptr->dx = RDX*crnd();
-                                       rockptr->dy = RDY*crnd();
-                                       x = (rockptr->dx-screendx)*gamerate;
-                                       y = (rockptr->dy-screendy)*gamerate;
-                                       j++;
-                               } while(x < -rockptr->image->w || x >= XSIZE
-                                               || y < -rockptr->image->h || y >= YSIZE);
-                               if(j > 1) printf("had to try %d times.\n", j);
+                               rockptr->dx = RDX*crnd();
+                               rockptr->dy = RDY*crnd();
 
                                rockptr->active = 1;
                        }
@@ -218,6 +227,8 @@ blast_rocks(float x, float y, float radius, int onlyslow)
        int i;
        float dx, dy, n;
 
+       if(onlyslow) return;
+
        for(i = 0; i<MAXROCKS; i++ ) {
                if(rock[i].x <= 0) continue;
 
@@ -231,8 +242,8 @@ blast_rocks(float x, float y, float radius, int onlyslow)
 
                n = sqrt(dx*dx + dy*dy);
                if(n < radius) {
-                       n *= 20;
-                       rock[i].dx += 54.0*(dx+30)/n;
+                       n *= 15;
+                       rock[i].dx += 54.0*dx/n;
                        rock[i].dy += 54.0*dy/n;
                }
        }