//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
VECTOR force;
VECTOR dist;
VECTOR absdist;
VECTOR speed_xyz;
VECTOR old_mypos;
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
var my_height;
var jump_time = 1;
var jump_height = 55;
var speed_z = 0;
var fall_damage = 0;
var bit_press[10];
var damage;
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#define health skill1
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
SOUND* damage_snd = "damage_snd.wav";
SOUND* death_snd = "death_snd.wav";
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
function main()
{
fps_max = 75;
fps_lock = 1; // NEEDED FOR PROPER WORK
level_load("1.WMB");
wait(3);
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
function handle_camera()
{
camera.arc = 90;
vec_lerp(camera.x,camera.x,vector(my.x,my.y,my.z + 50),0.5);
my.pan = camera.pan;
camera.pan -= 10 * mouse_force.x * time_step;
camera.tilt += 10 * mouse_force.y * time_step;
camera.tilt = clamp(camera.tilt,-80,80);
}
function handle_jump()
{
proc_kill(1);
jump_time = 1;
while (jump_time > -1 && player.health > 0)
{
on_space = NULL;
absdist.z = jump_height * time_step * jump_time;
jump_time -= 0.2 * time_step;
wait (1);
}
while (my_height > 10) {wait (1);}
jump_time = 1;
}
function handle_movement()
{
if(my_height <= 10)
{
if(jump_time == 1){on_space = handle_jump;}
if(!key_shift)
{
force.x = 10 * (key_w - key_s) * time_step;
accelerate(dist.x,force.x,0.5);
force.y = 10 * (key_a - key_d) * time_step;
accelerate(dist.y,force.y,0.5);
}
else
{
force.x = 10 * (key_w - key_s) * time_step;
accelerate(dist.x,force.x,1);
force.y = 10 * (key_a - key_d) * time_step;
accelerate(dist.y,force.y,1);
}
}
}
function handle_gravity()
{
my_height = c_trace(my.x,vector(my.x,my.y,my.z - 1000),IGNORE_ME|IGNORE_FLAG2|IGNORE_PASSABLE|USE_POLYGON|USE_BOX);
if(my_height > 10)
{
accelerate(absdist.z,-10 * time_step,-0.1);
}
else
{
if(jump_time == 1)
{
absdist.z = -(my_height/1.2) + 5;
absdist.z = clamp(absdist.z,-5,5);
if((my_height + absdist.z) > 10){absdist.z = -my_height -10;}
}
}
vec_set(old_mypos,my.x); // NEEDED FOR PROPER WORK
}
function handle_falldamage()
{
vec_diff(speed_xyz,my.x,old_mypos);
speed_z = abs(speed_xyz.z) * time_step;
if(speed_z > 3.5) // PLAY WITH 3.5 TO CUSTOMIZE THE HEIGHT
{
fall_damage += speed_z * time_step;
}
if(speed_z <= 1 && fall_damage != 0 && my_height <= 10)
{
my.health -= fall_damage * 4 + random(4); // PLAY WITH 4 TO CUSTOMIZE DAMAGE
damage = 1;
fall_damage = 0;
}
if(damage == 1 && fall_damage == 0 && my_height <= 10)
{
if(bit_press[0] == 0 )
{
snd_play(damage_snd,100,0);
bit_press[0]= 1;
}
damage = 0;
}
else
{
bit_press[0]= 0;
}
}
function handle_death()
{
snd_play(death_snd,100,0);
while(1)
{
if(my_height <= 10){vec_set(dist,nullvector);}
handle_gravity(); // GRAVITY
c_move(my,dist,absdist,IGNORE_PASSABLE|GLIDE);
camera.arc = 90;
vec_lerp(camera.x,camera.x,vector(my.x,my.y,my.z),0.5);
my.pan = camera.pan;
camera.pan -= 10 * mouse_force.x * time_step;
camera.tilt += 10 * mouse_force.y * time_step;
camera.tilt = clamp(camera.tilt,-80,80);
wait(1);
}
}
action hero()
{
player = my;
set(my,INVISIBLE);
my.health = 100; // SET PLAYERS HEALTH TO 100
while(my.health > 0)
{
handle_movement(); // MOVEMENT
handle_gravity(); // GRAVITY
c_move(my,dist,absdist,IGNORE_PASSABLE|GLIDE);
handle_falldamage(); // FALL DAMAGE FUNCTION
handle_camera(); // CAMERA
wait(1);
}
handle_death();
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
PANEL* gui_ =
{
digits(10,0,4,"Arial#24bi",1,player.skill1);
flags = SHOW;
}