This site requires JavaScript, please enable it in your browser!
Greenfoot back
marzukr
marzukr wrote ...

2012/12/16

Enemy AI

marzukr marzukr

2012/12/16

#
I have a enemy in my scenario and I want it to move left and right in one area so here is what I have:
public void move()
{
    speed = 4;
    setLocation ( getX() + speed, getY() );
    setLocation (getX() - speed, getY() );
}
But the enemy (polymetheus) will stand still because essentially I am telling it to move right the move left to it's original position and it executes this so fast you can't see it so I need some sort of delay after the first setLocation method but I don't want to delay the whole scenario, just polymetheus.class. How do I do this?
marzukr marzukr

2012/12/16

#
Can someone please help, I need it!
marzukr marzukr

2012/12/16

#
Help anyone?
davemib123 davemib123

2012/12/16

#
you probably want this on the polymetheus class:
public void polymetheusMovementPattern()
    {
        setLocation ( getX() + speed, getY());
        if (speed< 0 && getX() <= 500)
        { // moving left and past left limit
            setLocation(500, getY()); // reset position
            speed= -speed; // change direction
        }
        if (speed> 0 && getX() >= 800)
        { // moving right and past right limit
            setLocation(800, getY()); // reset position
            speed= -speed; // change direction
        }
    }
marzukr marzukr

2012/12/16

#
THANKS!!!! This worked but I had to reduce the numbers because my space was smaller.
You need to login to post a reply.