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 // constants for rock generation.
30 #define KH 32.0 // 32 s for a speed=1 rock to cross the screen horizontally.
31 #define KV 24.0 // 24 s for a speed=1 rock to cross the screen vertically.
32 #define RDX 2.5 // range for rock dx values (+/-)
33 #define RDY 2.5 // range for rock dy values (+/-)
37 #define crnd() (2*(rnd()-0.5))
47 for(i = 0; i<NROCKS; i++) {
48 snprintf(a,MAX_PATH_LEN,add_path("sprites/rock%02d.png"),i);
49 NULLERROR(temp = IMG_Load(a));
50 NULLERROR(surf_rock[i] = SDL_DisplayFormat(temp));
51 get_shape(surf_rock[i], &rock_shapes[i]);
62 for(i = 0; i<MAXROCKS; i++) rock[i].active = 0;
65 enum { LEFT, RIGHT, TOP, BOTTOM };
68 rock_timer_increments(float *ti)
70 float dx0,dx1, dy0,dy1;
71 float hfactor, vfactor;
74 for(i=0; i<4; i++) ti[i] = 0;
75 hfactor = nrocks/KH; vfactor = nrocks/KV;
77 dx0 = -RDX - screendx; dx1 = RDX - screendx;
78 dy0 = -RDY - screendy; dy1 = RDY - screendy;
82 if(dx1 < 0) ti[RIGHT] = -(dx0+dx1)/2;
87 } else ti[LEFT] = (dx0+dx1)/2;
94 if(dy1 < 0) ti[BOTTOM] = -(dy0+dy1)/2;
99 } else ti[TOP] = (dy0+dy1)/2;
102 ti[BOTTOM] *= vfactor;
111 rock_timer_increments(ti);
114 rtimers[i] += ti[i]*gamerate/20;
115 if(rtimers[i] >= 1) {
117 while(rockptr->active && j<MAXROCKS) {
118 if(++rockptr - rock >= MAXROCKS) rockptr = rock;
121 if(!rockptr->active) {
123 rockptr->type_number = random() % NROCKS;
124 rockptr->image = surf_rock[rockptr->type_number];
125 rockptr->shape = &rock_shapes[rockptr->type_number];
129 rockptr->y = rnd()*(YSIZE + rockptr->image->h);
132 rockptr->x = -rockptr->image->w;
133 rockptr->y = rnd()*(YSIZE + rockptr->image->h);
136 rockptr->x = rnd()*(XSIZE + rockptr->image->w);
140 rockptr->x = rnd()*(XSIZE + rockptr->image->w);
141 rockptr->y = -rockptr->image->h;
145 rockptr->dx = RDX*crnd();
146 rockptr->dy = RDY*crnd();
159 // Move all the rocks
160 for(i = 0; i < MAXROCKS; i++) {
163 rock[i].x += (rock[i].dx-screendx)*gamerate;
164 rock[i].y += (rock[i].dy-screendy)*gamerate;
166 if(rock[i].x < -rock[i].image->w || rock[i].x >= XSIZE
167 || rock[i].y < -rock[i].image->h || rock[i].y >= YSIZE) {
180 src.x = 0; src.y = 0;
182 for(i = 0; i<MAXROCKS; i++) {
184 src.w = rock[i].image->w;
185 src.h = rock[i].image->h;
189 dest.x = (int) rock[i].x;
190 dest.y = (int) rock[i].y;
192 SDL_BlitSurface(rock[i].image,&src,surf_screen,&dest);
199 hit_rocks(float x, float y, struct shape *shape)
203 for(i=0; i<MAXROCKS; i++) {
205 if(collide(x-rock[i].x, y-rock[i].y, rock[i].shape, shape))
213 blast_rocks(float x, float y, float radius, int onlyslow)
218 for(i = 0; i<MAXROCKS; i++ ) {
219 if(rock[i].x <= 0) continue;
221 // This makes it so your explosion from dying magically doesn't leave
222 // any rocks that aren't moving much on the x axis. If onlyslow is set,
223 // only rocks that are barely moving will be pushed.
224 if(onlyslow && (rock[i].dx-screendx < -4 || rock[i].dx-screendx > 3)) continue;
229 n = sqrt(dx*dx + dy*dy);
232 rock[i].dx += 54.0*dx/n;
233 rock[i].dy += 54.0*dy/n;