/*
starfield by MMike (Lite-C)
Hello. I decided to contribute with this little code.
Instead of using a skycube with stars, that look blurred,
you can use this entity based starfield.
- It blinks like real stars do
- Blue / Red color shift distribution
- Rendered bellow all entities
- Follow player
->Add this image file to your project: star_point.tga
*/
//file: starfield.c
//images: star_point.tga
#include <acknex.h>
#include <default.c>
/// NUMBER OF STARS
int star_limit=500;
var star_dist = 30000; //-tD
//// star props
/******************************
starf_f
*******************************/
void starf_f(ENTITY* p) {
set(p,TRANSLUCENT | BRIGHT | LIGHT );
// Add random color based on red
p.red=225-random(90);
p.green=150;
p.blue=200-random(90);
while(1){
//blinking effect
p.alpha=50+random(50);
vec_set(you.pan,camera.pan);
//keep star size all the same and not by their distance to camera
you.scale_x=vec_dist(you.x,camera.x)/8200;
you.scale_y=you.scale_x;
you.scale_z=you.scale_x;
wait(1);
}
}
/******************************
starf_init
*******************************/
void starf_init() {
//// CREATOR
VECTOR star_pos;
int starf_count=0;
var angle;
while (starf_count<star_limit) {
angle=random(360);
star_pos.x=camera.x + star_dist * cos(random(360)) * cos(random(360));
star_pos.y=camera.y + star_dist *sin(random(360)) * cos(random(360));
star_pos.z=camera.z + star_dist * sin(random(360));
you=ent_createlayer("star_point.tga",SKY,2);
you.x=star_pos.x;
you.y=star_pos.y;
you.z=star_pos.z;
starf_f(you);
starf_count++;
}
}
/******************************
main
*******************************/
void main() {
vec_set(screen_color, vector(1, 1, 1));
vec_set(sky_color, vector(1, 1, 1));
video_mode = 7;
video_screen = 1;
level_load("");
wait(3);
starf_init();
}