- 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;
- dotptr->x = ship.x + s[dir]*hx + (frnd()-0.5)*3;
- dotptr->y = ship.y + s[(dir+1)&3]*hy + (frnd()-0.5)*3;
- if(dir&1) {
- dotptr->dx = ship.dx + 2*dx;
- dotptr->dy = ship.dy + 20*dy;
- dotptr->life = 60 * fabs(dy);
- } else {
- dotptr->dx = ship.dx + 20*dx;
- dotptr->dy = ship.dy + 2*dy;
- dotptr->life = 60 * fabs(dx);
- }
+ for(dir=0; dir<4; dir++) {
+ if(!(ship.jets & 1<<dir)) continue;
+
+ 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);
+ }