OK. The code is as follows:
exec_seconds = 6;
start_sec = sys_seconds;
//walking
while(1)
{
c_move (guard, vector(1, 0, 0), nullvector, GLIDE);
guard.pan -= 1 * time_step;
ent_animate(guard,"walk",auto_play_percentage, ANM_CYCLE);
auto_play_percentage += 6 * time_step;
if((start_sec + exec_seconds) % 60 == sys_seconds)
break;
else
{
int temp_sec = sys_seconds;
if(temp_sec > 0 && temp_sec <5)
temp_sec += 60;
if((temp_sec - start_sec) > 2)//turn right
guard.pan += 3.5 * time_step;
}
wait(1);
}
//crawling
exec_seconds = 4;
start_sec = sys_seconds;
guard.z = 29;
while(1)
{
c_move (guard, vector(0.5, 0, 0), nullvector, GLIDE);
ent_animate(guard,"crawl",auto_play_percentage, ANM_CYCLE);
auto_play_percentage += 8 * time_step;
guard.pan += 1.5 * time_step;
if((start_sec + exec_seconds) % 60 == sys_seconds)
break;
wait(1);
}
wait(-0.5);
//jumping
auto_play_percentage = 0;
guard.z = 44;
wait(-0.5); //rest for 1 min
int one_jump_dist = 160; //the distance of jumping
int jump_time = 3; //the time of jumping
int jumping_dist = 0; //the realtime distance while jumping (as for one jump)
VECTOR start_pos; //the position of starting jumping each time
vec_set(start_pos, vector(guard.x,guard.y,0)); //jumping
while(1)
{
c_move (guard, vector(2, 0, 0), nullvector, GLIDE);
ent_animate(guard,"jump",auto_play_percentage, ANM_CYCLE);
auto_play_percentage += 6 * time_step;
jumping_dist = vec_dist(vector(guard.x,guard.y,0), start_pos);
if(jumping_dist <= (one_jump_dist/2))
guard.z += 4 * time_step;
else if(jumping_dist > (one_jump_dist/2) && jumping_dist < one_jump_dist)
guard.z -= 4 * time_step;
else if(jumping_dist >= one_jump_dist)
{
guard.z = 44;
jump_time -= 1;
vec_set(start_pos, vector(guard.x,guard.y,0));
auto_play_percentage = 0;
wait(-0.5);
}
if(jump_time == 0)
break;
wait(1);
}
//running
exec_seconds = 6;
start_sec = sys_seconds;
auto_play_percentage = 0;
while(1)
{
c_move (guard, vector(2, 0, 0), nullvector, GLIDE);
guard.pan += 7 * time_step;
ent_animate(guard,"run",auto_play_percentage, ANM_CYCLE);
auto_play_percentage += 9 * time_step;//adjust animation with the factor of time_step
if((start_sec + exec_seconds) % 60 == sys_seconds)
break;
else
{
int temp_sec = sys_seconds;
if(temp_sec > 0 && temp_sec <5)
temp_sec += 60;
if((temp_sec - start_sec) > 1.5) //turn right
guard.pan -= 11 * time_step;
}
wait(1);
}