20 struct rock_struct rock[MAXROCKS], *rockptr = rock;
22 SDL_Surface *surf_rock[NROCKS];
23 struct shape rock_shapes[NROCKS];
25 // timers for rock generation.
29 uint32_t nrocks_timer;
30 uint32_t nrocks_inc_ticks = 2*60*1000/(F_ROCKS-I_ROCKS);
32 // constants for rock generation.
33 #define KH 32.0 // 32 s for a speed=1 rock to cross the screen horizontally.
34 #define KV 24.0 // 24 s for a speed=1 rock to cross the screen vertically.
35 #define RDX 2.5 // range for rock dx values (+/-)
36 #define RDY 2.5 // range for rock dy values (+/-)
40 #define crnd() (2*(rnd()-0.5))
50 for(i = 0; i<NROCKS; i++) {
51 snprintf(a,MAX_PATH_LEN,add_path("sprites/rock%02d.png"),i);
52 NULLERROR(temp = IMG_Load(a));
53 NULLERROR(surf_rock[i] = SDL_DisplayFormat(temp));
54 get_shape(surf_rock[i], &rock_shapes[i]);
64 for(i = 0; i<MAXROCKS; i++) rock[i].active = 0;
69 enum { LEFT, RIGHT, TOP, BOTTOM };
72 rock_timer_increments(float *ti)
74 float dx0,dx1, dy0,dy1;
75 float hfactor, vfactor;
78 for(i=0; i<4; i++) ti[i] = 0;
79 hfactor = nrocks/KH; vfactor = nrocks/KV;
81 dx0 = -RDX - screendx; dx1 = RDX - screendx;
82 dy0 = -RDY - screendy; dy1 = RDY - screendy;
86 if(dx1 < 0) ti[RIGHT] = -(dx0+dx1)/2;
91 } else ti[LEFT] = (dx0+dx1)/2;
98 if(dy1 < 0) ti[BOTTOM] = -(dy0+dy1)/2;
103 } else ti[TOP] = (dy0+dy1)/2;
106 ti[BOTTOM] *= vfactor;
115 if(nrocks < F_ROCKS) {
116 nrocks_timer += ticks_since_last;
117 if(nrocks_timer >= nrocks_inc_ticks) {
118 nrocks_timer -= nrocks_inc_ticks;
123 rock_timer_increments(ti);
126 rtimers[i] += ti[i]*gamerate/20;
127 if(rtimers[i] >= 1) {
129 while(rockptr->active && j<MAXROCKS) {
130 if(++rockptr - rock >= MAXROCKS) rockptr = rock;
133 if(!rockptr->active) {
135 rockptr->type_number = random() % NROCKS;
136 rockptr->image = surf_rock[rockptr->type_number];
137 rockptr->shape = &rock_shapes[rockptr->type_number];
141 rockptr->y = rnd()*(YSIZE + rockptr->image->h);
144 rockptr->x = -rockptr->image->w;
145 rockptr->y = rnd()*(YSIZE + rockptr->image->h);
148 rockptr->x = rnd()*(XSIZE + rockptr->image->w);
152 rockptr->x = rnd()*(XSIZE + rockptr->image->w);
153 rockptr->y = -rockptr->image->h;
157 rockptr->dx = RDX*crnd();
158 rockptr->dy = RDY*crnd();
171 // Move all the rocks
172 for(i = 0; i < MAXROCKS; i++) {
175 rock[i].x += (rock[i].dx-screendx)*gamerate;
176 rock[i].y += (rock[i].dy-screendy)*gamerate;
178 if(rock[i].x < -rock[i].image->w || rock[i].x >= XSIZE
179 || rock[i].y < -rock[i].image->h || rock[i].y >= YSIZE) {
192 src.x = 0; src.y = 0;
194 for(i = 0; i<MAXROCKS; i++) {
196 src.w = rock[i].image->w;
197 src.h = rock[i].image->h;
201 dest.x = (int) rock[i].x;
202 dest.y = (int) rock[i].y;
204 SDL_BlitSurface(rock[i].image,&src,surf_screen,&dest);
211 hit_rocks(float x, float y, struct shape *shape)
215 for(i=0; i<MAXROCKS; i++) {
217 if(collide(x-rock[i].x, y-rock[i].y, rock[i].shape, shape))
225 blast_rocks(float x, float y, float radius, int onlyslow)
232 for(i = 0; i<MAXROCKS; i++ ) {
233 if(rock[i].x <= 0) continue;
235 // This makes it so your explosion from dying magically doesn't leave
236 // any rocks that aren't moving much on the x axis. If onlyslow is set,
237 // only rocks that are barely moving will be pushed.
238 if(onlyslow && (rock[i].dx-screendx < -4 || rock[i].dx-screendx > 3)) continue;
243 n = sqrt(dx*dx + dy*dy);
246 rock[i].dx += 54.0*dx/n;
247 rock[i].dy += 54.0*dy/n;