M
Marko Kajtazi
Guest
Hey everyone,
I made a nice enemy state machine for scouting and shooting. When it is in scouting mode it just moves around, but when it gets in shooting mode it starts to shoot in it's direction. The problem is when it sets back to the scouting state it continues to shoot while moving.
Here is the code:
Can anyone help me?.
Thanks.
I made a nice enemy state machine for scouting and shooting. When it is in scouting mode it just moves around, but when it gets in shooting mode it starts to shoot in it's direction. The problem is when it sets back to the scouting state it continues to shoot while moving.
Here is the code:
Code:
// Create Event
vspd = 0;
grav = 1;
hspd = 0;
dir = 1;
acc = 2;
dis_to_plater = noone;
movespeed = 10;
max_movedelay = 30;
movedelay = max_movedelay;
bullet = noone;
hp = 2;
state = "scout";
Code:
// Step Event
dis_to_plater = sign(oPlayer.x - x);
switch(state)
{
case "scout": {
with(bullet) {
instance_destroy();
}
if(movedelay == 0) {
dir *= -1;
movedelay = max_movedelay;
}
hspd = dir * movespeed;
vspd += grav;
movedelay--;
if((dis_to_plater == dir) && (oPlayer.y == y)) {
hspd = 0;
state = "attack";
}
}
case "attack": {
bullet = instance_create_layer(x + dir * 20, y, "Bullet", oBullet_enemy);
with(bullet) {
speed = 6;
if(oEnemy.dir == 1) {
direction = 0;
}
if(oEnemy.dir == -1) {
direction = 180;
}
}
if(!(dis_to_plater == dir) || !(oPlayer.y == y)){
state = "scout";
}
}
}
Thanks.