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

2015/1/16

Is this code correct for having an enemy moving left to right in my maze?

pingster pingster

2015/1/16

#
It works but my enemies wander out of my set location ever so slightly. Is this code most suitable for the job?
public void move()
    {
        move(4);
        if(Greenfoot.getRandomNumber(2)==0)
        {
        move(Greenfoot.getRandomNumber(100)-3);
        }
        if (getX() <= 0 || getY() >= getWorld().getWidth() -10 )
        { 
            move(180);
        }
        if (getY() <= 5 || getY() >= getWorld().getHeight() -10 )
        {
            move(-180);
        }
        setLocation(getX()-5, getY());
Super_Hippo Super_Hippo

2015/1/16

#
Line 6 is probably not what you want. With this and line 3, the enemy could walk 100 steps in one act cycle.
pingster pingster

2015/1/16

#
Firstly thanks for the reply . Could you possibly give me a suggestion of what the code in line 3 and 6 needs to be?
You need to login to post a reply.