2 * Elite - The New Kind.
4 * Reverse engineered from the BBC disk version of Elite.
5 * Additional material by C.J.Pinder.
7 * The original Elite code is (C) I.Bell & D.Braben 1984.
8 * This version re-engineered in C by C.J.Pinder 1999-2001.
10 * email: <christian@newkind.co.uk>
34 struct star stars[20];
37 void create_new_stars (void)
42 nstars = witchspace ? 3 : 12;
44 for (i = 0; i < nstars; i++)
46 stars[i].x = (rand255() - 128) | 8;
47 stars[i].y = (rand255() - 128) | 4;
48 stars[i].z = rand255() | 0x90;
55 void front_starfield (void)
67 nstars = witchspace ? 3 : 12;
69 delta = warp_stars ? 50 : flight_speed;
70 alpha = (double)flight_roll;
71 beta = (double)flight_climb;
76 for (i = 0; i < nstars; i++)
78 /* Plot the stars in their current locations... */
91 (sx >= GFX_VIEW_TX) && (sx <= GFX_VIEW_BX) &&
92 (sy >= GFX_VIEW_TY) && (sy <= GFX_VIEW_BY))
94 gfx_plot_pixel (sx, sy, GFX_COL_WHITE);
97 gfx_plot_pixel (sx+1, sy, GFX_COL_WHITE);
101 gfx_plot_pixel (sx, sy+1, GFX_COL_WHITE);
102 gfx_plot_pixel (sx+1, sy+1, GFX_COL_WHITE);
107 /* Move the stars to their new locations...*/
109 Q = delta / stars[i].z;
112 yy = stars[i].y + (stars[i].y * Q);
113 xx = stars[i].x + (stars[i].x * Q);
116 yy = yy + (xx * alpha);
117 xx = xx - (yy * alpha);
121 xx = xx + (tx * tx * 2);
130 gfx_draw_line (sx, sy, (xx + 128) * GFX_SCALE, (yy + 96) * GFX_SCALE);
135 if ((sx > 120) || (sx < -120) ||
136 (sy > 120) || (sy < -120) || (zz < 16))
138 stars[i].x = (rand255() - 128) | 8;
139 stars[i].y = (rand255() - 128) | 4;
140 stars[i].z = rand255() | 0x90;
151 void rear_starfield (void)
163 nstars = witchspace ? 3 : 12;
165 delta = warp_stars ? 50 : flight_speed;
166 alpha = -flight_roll;
167 beta = -flight_climb;
172 for (i = 0; i < nstars; i++)
174 /* Plot the stars in their current locations... */
187 (sx >= GFX_VIEW_TX) && (sx <= GFX_VIEW_BX) &&
188 (sy >= GFX_VIEW_TY) && (sy <= GFX_VIEW_BY))
190 gfx_plot_pixel (sx, sy, GFX_COL_WHITE);
193 gfx_plot_pixel (sx+1, sy, GFX_COL_WHITE);
197 gfx_plot_pixel (sx, sy+1, GFX_COL_WHITE);
198 gfx_plot_pixel (sx+1, sy+1, GFX_COL_WHITE);
203 /* Move the stars to their new locations...*/
205 Q = delta / stars[i].z;
208 yy = stars[i].y - (stars[i].y * Q);
209 xx = stars[i].x - (stars[i].x * Q);
212 yy = yy + (xx * alpha);
213 xx = xx - (yy * alpha);
217 xx = xx + (tx * tx * 2);
225 ex = (ex + 128) * GFX_SCALE;
226 ey = (ey + 96) * GFX_SCALE;
228 if ((sx >= GFX_VIEW_TX) && (sx <= GFX_VIEW_BX) &&
229 (sy >= GFX_VIEW_TY) && (sy <= GFX_VIEW_BY) &&
230 (ex >= GFX_VIEW_TX) && (ex <= GFX_VIEW_BX) &&
231 (ey >= GFX_VIEW_TY) && (ey <= GFX_VIEW_BY))
232 gfx_draw_line (sx, sy, (xx + 128) * GFX_SCALE, (yy + 96) * GFX_SCALE);
238 if ((zz >= 300) || (abs(yy) >= 110))
240 stars[i].z = (rand255() & 127) + 51;
244 stars[i].x = rand255() - 128;
245 stars[i].y = (rand255() & 1) ? -115 : 115;
249 stars[i].x = (rand255() & 1) ? -126 : 126;
250 stars[i].y = rand255() - 128;
260 void side_starfield (void)
272 nstars = witchspace ? 3 : 12;
274 delta = warp_stars ? 50 : flight_speed;
278 if (current_screen == SCR_LEFT_VIEW)
285 for (i = 0; i < nstars; i++)
298 (sx >= GFX_VIEW_TX) && (sx <= GFX_VIEW_BX) &&
299 (sy >= GFX_VIEW_TY) && (sy <= GFX_VIEW_BY))
301 gfx_plot_pixel (sx, sy, GFX_COL_WHITE);
304 gfx_plot_pixel (sx+1, sy, GFX_COL_WHITE);
308 gfx_plot_pixel (sx, sy+1, GFX_COL_WHITE);
309 gfx_plot_pixel (sx+1, sy+1, GFX_COL_WHITE);
317 delt8 = delta / (zz / 32);
320 xx += (yy * (beta / 256));
321 yy -= (xx * (beta / 256));
323 xx += ((yy / 256) * (alpha / 256)) * (-xx);
324 yy += ((yy / 256) * (alpha / 256)) * (yy);
332 gfx_draw_line (sx, sy, (xx + 128) * GFX_SCALE, (yy + 96) * GFX_SCALE);
335 if (abs(stars[i].x) >= 116)
337 stars[i].y = rand255() - 128;
338 stars[i].x = (current_screen == SCR_LEFT_VIEW) ? 115 : -115;
339 stars[i].z = rand255() | 8;
341 else if (abs(stars[i].y) >= 116)
343 stars[i].x = rand255() - 128;
344 stars[i].y = (alpha > 0) ? -110 : 110;
345 stars[i].z = rand255() | 8;
355 * When we change view, flip the stars over so they look like other stars.
358 void flip_stars (void)
365 nstars = witchspace ? 3 : 12;
366 for (i = 0; i < nstars; i++)
376 void update_starfield (void)
378 switch (current_screen)