2
* OpenTyrian: A modern cross-platform port of Tyrian
3
* Copyright (C) 2007-2009 The OpenTyrian Development Team
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
#define starlib_MAX_STARS 1000
33
JE_integer spX, spY, spZ;
34
JE_integer lastX, lastY;
37
static int tempX, tempY;
38
static JE_boolean run;
39
static struct JE_StarType star[starlib_MAX_STARS];
42
static JE_word stepCounter;
45
static JE_shortint nspVar2Inc;
47
/* JE: new sprite pointer */
49
static JE_real nspVarInc;
50
static JE_real nspVarVarInc;
52
static JE_word changeTime;
53
static JE_boolean doChange;
55
static JE_boolean grayB;
57
static JE_integer starlib_speed;
58
static JE_shortint speedChange;
60
static JE_byte pColor;
63
void JE_starlib_main( void )
69
struct JE_StarType *stars;
76
starlib_speed += speedChange;
79
for(stars = star, i = starlib_MAX_STARS; i > 0; stars++, i--)
81
/* Make a pointer to the screen... */
82
surf = VGAScreen->pixels;
84
/* Calculate the offset to where we wish to draw */
85
off = (stars->lastX)+(stars->lastY)*320;
88
/* We don't want trails in our star field. Erase the old graphic */
89
if (off >= 640 && off < (320*200)-640)
91
surf[off] = 0; /* Shade Level 0 */
93
surf[off-1] = 0; /* Shade Level 1, 2 */
106
tempX = (stars->spX / tempZ) + 160;
107
tempY = (stars->spY / tempZ) + 100;
108
tempZ -= starlib_speed;
111
/* If star is out of range, make a new one */
113
tempY == 0 || tempY > 198 ||
114
tempX > 318 || tempX < 1)
123
else /* Otherwise, update & draw it */
125
stars->lastX = tempX;
126
stars->lastY = tempY;
129
off = tempX+tempY*320;
133
tempCol = tempZ >> 1;
135
tempCol = pColor+((tempZ >> 4) & 31);
138
/* Draw the pixel! */
139
if (off >= 640 && off < (320*200)-640)
144
surf[off-1] = tempCol;
145
surf[off+1] = tempCol;
146
surf[off-320] = tempCol;
147
surf[off+320] = tempCol;
150
surf[off-2] = tempCol;
151
surf[off+2] = tempCol;
152
surf[off-640] = tempCol;
153
surf[off+640] = tempCol;
160
switch (toupper(lastkey_char))
217
nspVarVarInc = mt_rand_1() * 0.01f - 0.005f;
236
doChange = !doChange;
239
wait_noinput(true, false, false);
240
wait_input(true, false, false);
250
if (stepCounter > changeTime)
256
if ((mt_rand() % 1000) == 1)
258
nspVarVarInc = mt_rand_1() * 0.01f - 0.005f;
261
nspVarInc += nspVarVarInc;
264
void JE_wackyCol( void )
266
/* YKS: Does nothing */
269
void JE_starlib_init( void )
271
static JE_boolean initialized = false;
282
for (int x = 0; x < starlib_MAX_STARS; x++)
284
star[x].spX = (mt_rand() % 64000) - 32000;
285
star[x].spY = (mt_rand() % 40000) - 20000;
291
void JE_resetValues( void )
296
nspVarVarInc = 0.0001f;
303
void JE_changeSetup( JE_byte setupType )
306
changeTime = (mt_rand() % 1000);
312
setup = mt_rand() % (MAX_TYPES + 1);
319
if (nspVarInc > 2.2f)
325
void JE_newStar( void )
329
tempX = (mt_rand() % 64000) - 32000;
330
tempY = (mt_rand() % 40000) - 20000;
332
nsp = nsp + nspVarInc; /* YKS: < lol */
336
tempX = (int)(sinf(nsp / 30) * 20000);
337
tempY = (mt_rand() % 40000) - 20000;
340
tempX = (int)(cosf(nsp) * 20000);
341
tempY = (int)(sinf(nsp) * 20000);
344
tempX = (int)(cosf(nsp * 15) * 100) * ((int)(nsp / 6) % 200);
345
tempY = (int)(sinf(nsp * 15) * 100) * ((int)(nsp / 6) % 200);
348
tempX = (int)(sinf(nsp / 60) * 20000);
349
tempY = (int)(cosf(nsp) * (int)(sinf(nsp / 200) * 300) * 100);
352
tempX = (int)(sinf(nsp / 2) * 20000);
353
tempY = (int)(cosf(nsp) * (int)(sinf(nsp / 200) * 300) * 100);
356
tempX = (int)(sinf(nsp) * 40000);
357
tempY = (int)(cosf(nsp) * 20000);
360
tempX = (int)(sinf(nsp / 2) * 40000);
361
tempY = (int)(cosf(nsp) * 20000);
364
tempX = mt_rand() % 65535;
365
if ((mt_rand() % 2) == 0)
367
tempY = (int)(cosf(nsp / 80) * 10000) + 15000;
369
tempY = 50000 - (int)(cosf(nsp / 80) * 13000);
374
if ((nsp2 == 65535) || (nsp2 == 0))
376
nspVar2Inc = -nspVar2Inc;
378
tempX = (int)(cosf(sinf(nsp2 / 10.0f) + (nsp / 500)) * 32000);
379
tempY = (int)(sinf(cosf(nsp2 / 10.0f) + (nsp / 500)) * 30000);
383
if ((nsp2 == 65535) || (nsp2 == 0))
385
nspVar2Inc = -nspVar2Inc;
387
tempX = (int)(cosf(sinf(nsp2 / 5.0f) + (nsp / 100)) * 32000);
388
tempY = (int)(sinf(cosf(nsp2 / 5.0f) + (nsp / 100)) * 30000);
392
if ((nsp2 == 65535) || (nsp2 == 0))
394
nspVar2Inc = -nspVar2Inc;
396
tempX = (int)(cosf(sinf(nsp2 / 1000.0f) + (nsp / 2)) * 32000);
397
tempY = (int)(sinf(cosf(nsp2 / 1000.0f) + (nsp / 2)) * 30000);
403
if ((nsp2 == 65535) || (nsp2 == 0))
405
nspVar2Inc = -nspVar2Inc;
407
tempX = (int)(cosf(sinf(nsp2 / 2.0f) / (sqrtf(fabsf(nsp)) / 10.0f + 1) + (nsp2 / 100.0f)) * 32000);
408
tempY = (int)(sinf(cosf(nsp2 / 2.0f) / (sqrtf(fabsf(nsp)) / 10.0f + 1) + (nsp2 / 100.0f)) * 30000);
415
if ((nsp2 == 65535) || (nsp2 == 0))
417
nspVar2Inc = -nspVar2Inc;
419
tempX = (int)(cosf(sinf(nsp2 / 10.0f) / 2 + (nsp / 20)) * 32000);
420
tempY = (int)(sinf(sinf(nsp2 / 11.0f) / 2 + (nsp / 20)) * 30000);
425
tempX = (int)((sinf(nsp) + cosf(nsp2 / 1000.0f) * 3) * 12000);
426
tempY = (int)(cosf(nsp) * 10000) + nsp2;