///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <mtlFX.c>
#define STATE skill1
#define ANIMATION skill2
///////////////////////////////
function main()
{
//video_screen = 1;
detail_size = 2;
level_load("testgame.wmb");
}
function camera_follow(ENTITY* ent)
{
while(1)
{
vec_set(camera.x,vector(-150,10,50)); // camera position relative to the player
vec_rotate(camera.x,ent.pan); // rotate the camera position with the player
vec_add(camera.x,ent.x); // add player position
vec_set(camera.pan,vector(ent.pan,-10,0)); // look in player direction, slighty down
wait(1);
}
}
function jump()
{
//movedir.z = -jumpacc;
var jump_percentage = 0;
while(jump_percentage < 100)
{
ent_animate(my,"jump",jump_percentage,ANM_CYCLE);
jump_percentage += 10*time_step;
wait(1);
}
}
action move_guard()
{
camera_follow(me);
//Parameter
var movespeed = 10;
var turnspeed = 10;
var fallacc = 3.68;
var jumpacc = 15;
//Temporary
VECTOR movedir;
vec_set(movedir, vector(0, 0, 0));
ANGLE rotdir;
vec_set(rotdir, vector(0, 0, 0));
var grounddist;
//determine player height
c_setminmax(my);
wait(1);
var feedheight = -my.min_z;
//adjust bounding box
my.min_x *= 0.7;
my.min_y *= 0.8;
my.min_z = 0;
my.max_x *= 0.7;
my.max_y *= 0.8;
my.max_z *= 0.8;
proc_mode = PROC_EARLY;
while(1)
{
// //define key inputs
movedir.x = key_cuu-key_cud; //*(1+key_shift*2); FORWARD-BACKWARD
movedir.y = key_ctrl-key_ins; // STRAFE LEFT-RIGHT
// //calculate speed
movedir.x *= movespeed*time_step;
movedir.y *= movespeed*time_step;
my.pan += (key_cul-key_cur)*5*time_step; // TURN/ROTATE LEFT-RIGHT
c_move(my,vector(movedir.x, movedir.y, 0), nullvector, GLIDE|IGNORE_PASSABLE);
if(key_cuu | key_cud)
{
my.ANIMATION += 1*movedir.x;
ent_animate(my,"walk",my.ANIMATION,ANM_CYCLE);
}
else if(key_ins | key_ctrl)
{
my.ANIMATION += 1*movedir.y;
ent_animate(my,"walk", my.ANIMATION,ANM_CYCLE);
}
else if(key_cuu & key_ctrl | key_cuu & key_ins)
{
my.ANIMATION -= 1*movedir.x;
ent_animate(my,"walk", my.ANIMATION,ANM_CYCLE);
}
else if(key_cud & key_ctrl | key_cud & key_ins)
{
my.ANIMATION -= 1*movedir.x;
ent_animate(my,"walk", my.ANIMATION,ANM_CYCLE);
}
//check distance to ground
grounddist = c_trace(my.x, vector(my.x, my.y, my.z-10000), IGNORE_ME|IGNORE_PASSABLE)-feedheight;
if(grounddist > 0 || movedir.z < 0)
{
//gravity acceleration
movedir.z += fallacc*time_step;
}else
{
movedir.z = 0;
}
//apply gravity
my.z -= minv(movedir.z*time_step, grounddist);
if(grounddist-minv(movedir.z*time_step, grounddist) == 0)
{
//jump
if(key_space)
{
jump();
movedir.z = -jumpacc;
}
}
//
//
// if (my.STATE = 1)
// {
// var stand_percentage;
// ent_animate(my,"stand",stand_percentage, ANM_CYCLE);
// stand_percentage += 2 * time_step;
// }
wait(1);
}
}