-new_engine_dots(float time_span, int dir) {
- int i;
- int n = time_span * ENGINE_DOTS_PER_TIC;
- float a, r; // angle, random length
- float dx, dy;
- float hx, hy; // half ship width/height.
- static const int s[4] = { 2, 1, 0, 1 };
- float time;
- float accelh, accelv, past_ship_dx, past_ship_dy;
-
- hx = ship.image->w / 2;
- hy = ship.image->h / 2;
-
- for(i = 0; i<n; i++) {
- if(dotptr->active == 0) {
- a = frnd()*M_PI + (dir-1)*M_PI_2;
- r = sin(frnd()*M_PI);
- dx = r * cos(a);
- dy = r * -sin(a); // screen y is "backwards".
-
- dotptr->active = 1;
-
- // dot was created at a random time during the time span
- time = frnd() * time_span; // this is how long ago
-
- // calculate how fast the ship was going when this engine dot was
- // created (as if it had a smooth acceleration). This is used in
- // determining the velocity of the dots, but not their starting
- // location.
- accelh = ((ship.jets >> 2) & 1) - (ship.jets & 1);
- accelh *= THRUSTER_STRENGTH * time;
- past_ship_dx = ship.dx - accelh;
- accelv = ((ship.jets >> 1) & 1) - ((ship.jets >> 3) & 1);
- accelv *= THRUSTER_STRENGTH * time;
- past_ship_dy = ship.dy - accelv;
-
- // the starting position (not speed) of the dot is calculated as
- // though the ship were traveling at a constant speed for this
- // time_span.
- dotptr->x = (ship.x - (ship.dx - screendx) * time) + s[dir]*hx;
- dotptr->y = (ship.y - (ship.dy - screendy) * time) + s[(dir+1)&3]*hy;
- if(dir&1) {
- dotptr->dx = past_ship_dx + 2*dx;
- dotptr->dy = past_ship_dy + 20*dy;
- dotptr->life = 60 * fabs(dy);
- } else {
- dotptr->dx = past_ship_dx + 20*dx;
- dotptr->dy = past_ship_dy + 2*dy;
- dotptr->life = 60 * fabs(dx);
- }
-
- // move the dot as though it were created in the past
- dotptr->x += (dotptr->dx - screendx) * time;
- dotptr->y += (dotptr->dy - screendy) * time;
-
- if(dotptr - edot < MAXENGINEDOTS-1) dotptr++;
- else dotptr = edot;
- }
- }
-}
-
-void
-move_engine_dots(float ticks) {
- int i;
- Sprite *hit;
-
- for(i = 0; i<MAXENGINEDOTS; i++) {
- if(!edot[i].active) continue;
-
- edot[i].x += (edot[i].dx - screendx)*ticks;
- edot[i].y += (edot[i].dy - screendy)*ticks;
- edot[i].life -= t_frame*3;
- if(edot[i].life < 0 || edot[i].x<0 || edot[i].x >= XSIZE || edot[i].y < 0 || edot[i].y >= YSIZE) {
- edot[i].active = 0;
- }