var g_speeddown = 0;
//class name:CMonster
class CMonster
{
private:
int fps;
ENTITY* e;
double increment;
double per;
float dist_down;
var* speed_down;
VECTOR vFeet;
float move_speed;
long pan_speed;
void camera_lookat();
public:
CMonster(char* filename);
void monster_evt();
~CMonster();
};
CMonster::CMonster(char* filename){
//global var: g_fps
// g_temp
this->fps = g_fps;
this->e = ent_create(filename,_vec(0,0,0),NULL);
this->e->pan += _VAR(0);
this->e->flags = SHOW;
this->per = 0;
this->increment = 150/this->fps;
this->move_speed = (float)0.25/this->fps;
this->pan_speed = 140/this->fps;
}
CMonster::~CMonster(){
this->per=0;
}
void CMonster::monster_evt(){
this->per += this->increment;
double p = this->per;
long ad=v(key_a)-v(key_d);
long ws=v(key_w)-v(key_s);
if(0){
e->z = _VAR(-200);
if(ad!=0||ws!=0){
ent_animate(e,"run",_VAR(p),_VAR(ANM_CYCLE));
//animation:pain,stand,run,attack,jump,flip
e->pan += this->pan_speed * ad;
c_move( e,_vec(move_speed*ws,0,0),
_vec(0,0,0),
IGNORE_SPRITES);
}else{ent_animate(e,"stand",_VAR(p/10),_VAR(ANM_CYCLE));}
}
//----------------------------------------------------------------------------------------
else{
var v1=c_trace( (VECTOR*)&e->x,
_vec( _FLOAT(e->x), _FLOAT(e->y), _FLOAT(e->z -_VAR(5000))),
IGNORE_ME|IGNORE_PASSABLE|USE_BOX);
float dist_ahead = (float)ws * this->move_speed;
var t2 =0;
if(v1>_VAR(0)){
dist_down = 5;
//t2 = e->z - v(target).z;
//e->z = v(target).z;
//e->z -= _VAR(10);
}else{dist_down = 0;}
// c_move(e,_vec(dist_ahead,0,0),_vec(0,0,-dist_down),IGNORE_SPRITES|GLIDE);
c_move(e,_vec(move_speed*ws,0,0),_vec(0,0,-dist_down),GLIDE);
str_for_num(g_str1, v1 );//v(target).z
e->pan += pan_speed * ad;
ent_animate(e,"run",_VAR(p),_VAR(ANM_CYCLE));
}
this->camera_lookat();
}
void CMonster::camera_lookat(){
//camere look at character
v(camera).x = e->x + _VAR(-400);//-400
v(camera).y = e->y + _VAR(-200);//-200
v(camera).z = e->z + _VAR( 500);// 200
vec_set(g_temp,vector(e->x,e->y,e->z));
vec_sub(g_temp,vector(v(camera).x,v(camera).y,v(camera).z));
vec_to_angle( (ANGLE*) &(v(camera).pan) ,g_temp);
}