#include <acknex.h>
#include <default.c>
BMAP* star_map = "star.pcx";
var star_gen_pos[3]; //Starfield-Generator position
//Create a text on the left-top corner
//START//
TEXT* help = {
string = "TEST-PROGRAMM - CREATED BY MARCEL KLEE";
red = 255; green=255; blue=255;
flags=VISIBLE;
}
//END//
//////////////////////////////////////////////////////////
//Create Functions-Prototype//////////////////////////////
//////////////////////////////////////////////////////////
//START//
function plActor();
function part_alphafade(PARTICLE *p);
function effect_explo(PARTICLE *p);
//END//
function main(){
fps_max=60;
vec_set(screen_color,vector(1,1,1));
wait(1);
//Load the Environment
level_load("");
wait(3);
ent_create("s1.mdl", vector(0,0,0),plActor);
}
//////////////////////////////////////////////
/////////// PLAYER FUNCTION //////////////
//////////////////////////////////////////////
//The player-ship function
//START//
function plActor()
{
var vecPos[3] = {0,0,0}; //Position-Vector
var vecSpeed[3] = {0,0,0}; //Speed-Vector
var vecAng[3] = {0,0,0}; //Angular-Vector
//var vecForce1[3] = {0,0,0}; //Other force-Vectors ... function coming soon
var mySpeed = 0; //mySpeed describes the Engine-Force
var facCamAbst; //For the camera-distance to the playership -> only a factor x
var shipmass = 80; //80tons --- for the force calculation
while(1){
mySpeed += key_force.y*time_step/shipmass;
//calculate the effective force of the ship
//mySpeed adds the key_force (pressed = 1, not pressed = 0) * time_step / shipmass (80).
//The shipmass is only a factor. You can also say "hey the weight isn't 80tons, its 80 bannanas ;)
//For instance: Frame 1 -> mySpeed += 0*time_step/80 = 0. key not pressed = false
//For instance: Frame 2 -> mySpeed += 1*time_step/80 = 2,10. key pressed = true
//For instance: Frame 3 -> mySpeed += 1*time_step/80 = 2,10 + 2,10 = 4,20. ....and so on.....
//So how i use this "effective Force"?
//The effective Force only descripes the force we need to calculate a part of the speed vector.
//why only a part? -> there are maybe other forces. Maybe a collision with a other ship, or a explosion....
//We will see later.....
vecSpeed[1] += mySpeed*cos(my.pan);
vecSpeed[2] += mySpeed*sin(my.pan);
vecSpeed[3] = 0;
//Here we use the cos and sin function with mySpeed (we rember -> the effective force)
//to calculate the direction of the force + the force itself (vector-length)
//Attention! -> this will only calculate the vector for the engine-force.
//if we wanna use other forces, we have to write it again (or we write a function/macro)
vecAng[1] -= key_force.x*10*time_step;
//calculate the pan-angle for the player ship.
vec_add(vecPos[1], vecSpeed[1]);
//add the speed-vector to the position-vector of the ship.
accelerate(mySpeed, 0, 0.05);
accelerate(vecSpeed[1], 0, 0.05);
accelerate(vecSpeed[2], 0, 0.05);
accelerate(vecSpeed[3], 0, 0.05);
//its my way to simulate the friction.
//an other way: vecSpeed[1] *= vecSpeed*(0,95^time_step);
//i think it should also work.... i dont know yet.
my.pan = vecAng[1]; //nanonanet -> set my.pan to vecAng[1].
my.tilt = 0;
my.roll = 0;
my.x = vecPos[1]; //set my position to the vecPos.
my.y = vecPos[2];
my.z = vecPos[3];
camera.x = my.x; //set camera Position to my position
camera.y = my.y;
camera.z = my.z + 550 + facCamAbst; //my.z+550quants = the base-distance to my ship + factor facCamAbst
//facCamAbst is dynamic. (for instance speed * factor)
camera.tilt= -90; //camera look straight down to the ship.
camera.roll= 0;
camera.pan = 0;
facCamAbst = mySpeed*15*shipmass; //this is the "dynamic" camera factor.
facCamAbst = abs(facCamAbst);
vec_set(star_gen_pos[1],my.x);
//here we copy the my position information into the star_gen_pos vector.
effect(effect_explo,10 * time_step,star_gen_pos[1],normal);
//i use the particle effect generator for the starfield (i know, not the right name for this effect)
wait(1);
}
}
////////////////////////////////////
function part_alphafade(PARTICLE *p)
{
if(num_particles > 300) { p.lifespan -= 1*time_step; p.alpha -= 1*time_step; }
}
function effect_explo(PARTICLE *p)
{
var temp[3];
p.lifespan = random(500) - 200;
p.x = star_gen_pos[1] + random(600) - random(600);
p.y = star_gen_pos[2] + random(600) - random(600);
p.z = star_gen_pos[3] + random(600) - random(600);
p.size = random(8)-4;
p.alpha = 50 + random(25);
p.bmap = star_map;
p.flags |= (BRIGHT | TRANSLUCENT);
p.event = part_alphafade;
}