- begin_generate = SDL_GetTicks();
-
- SDL_LockSurface(s);
- rawpixel = (Uint16 *) s->pixels;
-
- //for(n = 0; n <= power/2; n++) {
-
- endcount = 0;
- while (endcount<3) {
- for(x = 0; x<s->w; x++) {
- for(y = 0; y<s->h; y++) {
- c = rawpixel[s->pitch/2*y + x];
- if(c && c != s->format->colorkey) {
+void
+new_engine_dots(void) {
+ int dir, i;
+ int n = t_frame * 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(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->decay = 3;
+ dotptr->heat = 6;
+
+ // dot was created at a random time during the time span
+ time = frnd() * t_frame; // 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
+ // t_frame.
+ 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->mass = 60 * fabs(dy);
+ } else {
+ dotptr->dx = past_ship_dx + 20*dx;
+ dotptr->dy = past_ship_dy + 2*dy;
+ dotptr->mass = 60 * fabs(dx);
+ }