15 int dead; // has been blown out of the way
16 // to make room for a new ship appearing.
22 struct rock_struct rock[MAXROCKS], *rockptr = rock;
24 float rockrate,rockspeed;
26 SDL_Surface *surf_rock[NROCKS];
27 struct shape rock_shapes[NROCKS];
44 for(i = 0; i<NROCKS; i++) {
45 snprintf(a,MAX_PATH_LEN,add_path("sprites/rock%02d.png"),i);
46 NULLERROR(temp = IMG_Load(a));
47 NULLERROR(surf_rock[i] = SDL_DisplayFormat(temp));
48 get_shape(surf_rock[i], &rock_shapes[i]);
56 if(--countdown <= 0 && (rnd()*100.0<(rockrate += 0.025))) {
57 // Possibly create a rock
59 if(rockptr-rock >= MAXROCKS) {
62 if(!rockptr->active) {
63 rockptr->dx = -(rockspeed)*(1 + rnd());
64 rockptr->dy = rnd()-0.5;
65 rockptr->type_number = random() % NROCKS;
66 rockptr->image = surf_rock[rockptr->type_number];
67 rockptr->shape = &rock_shapes[rockptr->type_number];
68 rockptr->x = (float)XSIZE;
69 rockptr->y = rnd()*(YSIZE + rockptr->image->h);
71 area += rockptr->shape->area;
74 countdown = (int)(ROCKRATE/gamerate);
87 for(i = 0; i < MAXROCKS; i++) {
89 rock[i].x += rock[i].dx*gamerate;
90 rock[i].y += rock[i].dy*gamerate + yscroll;
91 if(rock[i].y > YSIZE || rock[i].y < -rock[i].image->h) {
93 area -= rock[i].shape->area;
98 rock[i].y = (YSIZE - rock[i].image->h) - rock[i].y;
99 rock[i].y += (rock[i].dy*gamerate + yscroll) * 1.01;
102 if(rock[i].x < -rock[i].image->w || rock[i].x > XSIZE) {
103 area -= rock[i].shape->area;
117 for(i = 0; i<MAXROCKS; i++ ) {
132 src.x = 0; src.y = 0;
134 for(i = 0; i<MAXROCKS; i++) {
136 src.w = rock[i].image->w;
137 src.h = rock[i].image->h;
141 dest.x = (int) rock[i].x;
142 dest.y = (int) rock[i].y;
144 SDL_BlitSurface(rock[i].image,&src,surf_screen,&dest);
151 hit_rocks(float x, float y, struct shape *shape)
155 for(i=0; i<MAXROCKS; i++) {
157 if(collide(x-rock[i].x, y-rock[i].y, rock[i].shape, shape))
165 blast_rocks(float x, float y, float radius, int onlyslow)
170 for(i = 0; i<MAXROCKS; i++ ) {
171 if(rock[i].x <= 0) continue;
173 // This makes it so your explosion from dying magically doesn't leave
174 // any rocks that aren't moving much on the x axis. If onlyslow is set,
175 // only rocks that are barely moving will be pushed.
176 if(onlyslow && (!rock[i].dead || rock[i].dx < -4 || rock[i].dx > 3)) {
183 n = sqrt(dx*dx + dy*dy);
186 rock[i].dx += rockrate*(dx+30)/n;
187 rock[i].dy += rockrate*dy/n;