#include <acknex.h>
#include <default.c>
BMAP* star_map = "star.pcx"; //define a bitmap called star_map
var star_gen_pos[3]; //variable -> will safe coordinates
TEXT* help = { //create a text on screen
string = "TEST-PROGRAMM - CREATED BY MARCEL KLEE";
red = 255; green=255; blue=255;
flags=VISIBLE; //make text visible
}
function plActor(); //function-prototype for the player
function part_alphafade(PARTICLE *p); //particle function
function effect_explo(PARTICLE *p); //particle function
function main(){
fps_max=60;
//Load the Environment
level_load("");
wait(3);
ent_create("s1.mdl", vector(0,0,0),plActor);
//create the player in the level
//vector(0,0,0) is the start-position of the ship
}
function plActor()
{
//for the movement we need 3 var-arrays
//1- for the Ship Position -> vecPos[3]
//2- for the Ship-Speed -> vecSpeed[3]
//3- for the Ship-Direction -> vecAng[3]
//You will alse see vecForce1[3]
//This is one of the other forces you can use.
//for instance for gravitation or some other kinds of energie
//mySpeed is the force used for a "constant" force in x-
//direction of the ship.
var vecPos[3] = {0,0,0}; //i initialize all with zero
var vecSpeed[3] = {0,0,0}; //so there is no bad faulty effect
var vecAng[3] = {0,0,0}; //at the game-start
var vecForce1[3] = {0,0,0}; //use this var array for slide-effects :)
var mySpeed = 0;
var facCamAbst; //this is only used as a factor for
//the cam-movement
var shipmass = 80; //80tons -> change this to change the ship
//setup
while(1){
//with the arrow-key-Y you change the force.
mySpeed += key_force.y*time_step/shipmass;
//with pan and the trigometrics you calculate the vector
//vecSpeed in x and y diriction
vecSpeed[1] += mySpeed*cos(my.pan);
vecSpeed[2] += mySpeed*sin(my.pan);
vecSpeed[3] = 0;
//-----------------------------------------/*
//this a possible way to add a slide-function:
vecForce1[1] += mySpeed*key_force.x/shipmass*cos(my.pan-90);
vecForce1[2] += mySpeed*key_force.x/shipmass*sin(my.pan-90);
vecForce1[3] = 0;
vec_add(vecPos[1], vecForce1[1]);
accelerate(vecForce1[1], 0, 0.05);
accelerate(vecForce1[2], 0, 0.05);
accelerate(vecForce1[3], 0, 0.05);
//i havent tested this, but it should work.
//play with the values....
-------------------------------------------*/
vecAng[1] -= key_force.x*10*time_step;
vec_add(vecPos[1], vecSpeed[1]);
accelerate(mySpeed, 0, 0.05);
//i use accelerate to "simulate" friction
//change the value 0.05 to .... 0.9 -> you will see the changes
accelerate(vecSpeed[1], 0, 0.05);
accelerate(vecSpeed[2], 0, 0.05);
accelerate(vecSpeed[3], 0, 0.05);
my.pan = vecAng[1];
my.tilt = 0;
my.roll = 0;
my.x = vecPos[1];
my.y = vecPos[2];
my.z = vecPos[3];
//here comes some functions for the cam
camera.x = my.x; //there exists some easier ways to set the
camera.y = my.y; //position -> vec_set(camera.x, my.x)
camera.z = my.z + 550 + facCamAbst;
camera.tilt= -90; //cam-diretion - down
camera.roll= 0;
camera.pan = 0;
facCamAbst = mySpeed*12*shipmass; //integrate the shipmass
//to prefent a to big distance
facCamAbst = abs(facCamAbst);
vec_set(star_gen_pos[1],my.x);
effect(effect_explo,10 * time_step,star_gen_pos[1],normal);
//create particles for the star-field
wait(1);
}
}
//more comments will follow
//first i will optimze the code....
////////////////////////////////////
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(400) - random(400);
p.y = star_gen_pos[2] + random(400) - random(400);
p.z = star_gen_pos[3] + random(400) - random(400);
p.size = random(8)-4;
p.alpha = 50 + random(25);
p.bmap = star_map;
p.flags |= (BRIGHT | TRANSLUCENT);
p.event = part_alphafade;
}