Help! Enemy AI problem [SOLVED]


(Massimo) #1

Hi guys! I’m new in these community and i use FlashPunk since two weeks, so i have a lot of problem with some aspects of it.

I’m trying to add an enemy entity with a sort of simple AI, like a “Super Mario” goomba (follow a line and then, when he collide with a wall, turn back), but i had not success. May you suggest me a direction?

Thanks, and sorry for my poor english, but i’m italian :smile:


(David Williams) #2

Something similar to this might work:

private var direction:Boolean = false;
... Now into the update
override public function update():void
{
    if(direction) //lets make true be left
    {
        if(!collide("wall", x - 5, y))
        {
            x -= 5;
        }
        else
        {
            direction = !direction;
        }
    }
    else
    {
        if(!collide("wall", x + 5, y))
        {
            x += 5;
        }
        else
        {
            direction = !direction;
        }
    }
}

AI - Help for a beginner
(Massimo) #3

Thanks! Work perfectly!