نقل قول:
//enemy code
action enemy ;
{
VECTOR temp;
vec_zero(temp);
var idle_percentage = 0;
var run_percentage = 0;
var death_percentage = 0;
set(my,POLYGON);
my.health = 100;
my.emask = ENABLE_IMPACT;
my.event = got_shot;
my.status = idle;
while (my.status != dead)
{
if (my.status == idle) // hanging around?
{
ent_animate(my, "stand", idle_percentage,ANM_CYCLE); // play the "stand" aka idle animation
idle_percentage += 3 * time_step; // "3" controls the animation speed
if (vec_dist (player.x, my.x) < 1000) // the player has come too close?
{
my.status = attacking; // then attack the player even if it hasn't fired at the enemy yet
}
}
if (my.status == attacking) // shooting at the player?
{
vec_set(temp, player.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan, temp); // turn the enemy towards the player
if (vec_dist (player.x, my.x) > 500)
{
c_move (my, vector(10 * time_step, 0, 0), nullvector, GLIDE);
ent_animate(my, "run", run_percentage, ANM_CYCLE); // play the "run" animation
run_percentage += 6 * time_step; // "6" controls the animation speed
}
else
{
ent_animate(my, "alert", 100, NULL); // use the last frame from the "alert" animation here
}
if ((total_frames % 80) == 1) // fire a bullet each second
{
vec_for_vertex (temp, my, 8);
// create the bullet at enemy's position and attach it the "move_enemy_bullets" function
ent_create (bullet_mdl, temp, move_enemy_bullets);
}
if (vec_dist (player.x, my.x) > 1500) // the player has moved far away from the enemy?
{
my.status = idle; // then switch to "idle"
}
}
wait (1);
}
while (death_percentage < 100) // the loop runs until the "death" animation percentage reaches 100%
{
ent_animate(my, "deatha", death_percentage, NULL); // play the "die" animation only once
death_percentage += 3 * time_step; // "3" controls the animation speed
wait (1);
}
set(my,PASSABLE); // allow the player to pass through the corpse now
}
function got_shot()
{
if (you.skill30 != 1) {return;} // didn't collide with a bullet? Then nothing should happen
my.health -= 35;
if (my.health <= 0) // dead?
{
my.status = dead; // stop the loop from "action my_enemy"
my.event = NULL; // the enemy is dead, so it should stop reacting to other bullets from now on
return; // end this function here
}
else // got shot but not (yet) dead?
{
my.status = attacking; // same thing with my.skill1 = 2
}
}
function move_enemy_bullets()
{
VECTOR bullet_speed; // this var will store the speed of the bullet
my.skill30 = 1; // I'm a bullet
my.emask = ENABLE_IMPACT | ENABLE_ENTITY | ENABLE_BLOCK;
my.event = remove_bullets; // when it collides with something, its event function (remove_bullets) will run
my.pan = you.pan; // the bullet has the same pan
my.tilt = you.tilt; // and tilt with the enemy
bullet_speed.x = 50 * time_step; // adjust the speed of the bullet here
bullet_speed.y = 0; // the bullet doesn't move sideways
bullet_speed.z = 0; // or up / down on the z axis
// the loop will run for as long as the bullet exists (it isn't "null")
while (my)
{
// move the bullet ignoring its creator (the enemy)
c_move (my, bullet_speed, nullvector, IGNORE_YOU);
wait (1);
}
}