Monday, 21 January 2013

[GM] My first AI

I'm happy and proud because I did my first AI ! and I did it without help~ (for now...U teehee).

However, I have problems with the easiest function, lol.

GMZ file: http://rghost.net/43213252


I have basically two problems:
  • I tried to script a "automatic depth" (according to "y edge") but objets superimpose badly yet :S
  • I need two men follow to player, atack him and, when his life was 0, leave the room. I got "follow" and "atack" actions but I didn't get to "reduce life to 0" :S And sometimes (mainly when I put only a man on the room), men do odd movements and try "run away" (I programmed a coward AI, lol).



Step Code:
/*Walking around street*/
if o_control.optionI = 1 //Player (Petros) isn't hidding, so look for him!
    {
    if o_Maton_1.x < 30
        {
        hspeed = walk_speed
        facing = "right";
        }
    if o_Maton_1.x > 2140
        {
        hspeed -= walk_speed
        facing = "left";
        }
    }
if o_control.optionI = 3 //Petros is hidding. Man thinks Petros ran away, so he decides stop to look him and go home
    {
    if o_Maton_1.x < 30 {instance_destroy()}
    }

/*If Man see player Petros... go to atack him!*/
if o_control.optionI= 1
    {
    if (distance_to_object(o_Petros) < 100 )
        {
        mp_potential_step(o_Petros.x+20, o_Petros.y, 1,false) /*Follow code*/
        if o_Petros.x > o_Maton_1.x {facing = "right"}
        if o_Petros.x < o_Maton_1.x {facing = "left"}
        }
    if (distance_to_object(o_Petros) <= 20 ) /*Atack Mode*/
        {
        atk = true;
        alarm[1] = 100; //Man don't want kill Petros, he only wants "teach him a lesson", lol. So, man'll stop to atack him -> o_control.OptionI = 2
        o_Petros.sprite_index = spr_Petros_stand; //Petros' hurt animation
        o_Petros.image_index = 2; //Petros' hurt animation
        }
    else atk = false;
    }
/*Stop atack Petros and finish the scene*/
if o_control.optionI = 2
    {
    mp_potential_step(2130, y, 1,false); //When x will be 2130 -> Finish room
    facing = "right";
    }

No comments:

Post a Comment

Please, sign your comments; Anonymous comments will be mark like spam.