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

2018/2/19

Non_moving Actors

Heet_Patel Heet_Patel

2018/2/19

#
So I have these randomly moving objects. Now when I place some of the actors on the world they don't go around the world but they actually go all crazy in one area and don't move. Now I don't know if this is a bug or something else but please could anyone help me please. I have got the code already and it works sometimes and sometimes goes all spastic
danpost danpost

2018/2/19

#
It is most definitely a bug -- but I am quite sure it is of your own doing (not a greenfoot bug). It is nice that you have got the code already -- but we cannot help fix it blindly.
Heet_Patel Heet_Patel

2018/2/24

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Villian here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Villian extends Actor
{
    /**
     * Act - do whatever the Villian wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
       move(2);
       if (Greenfoot.getRandomNumber(100) < 10)
       {
           turn(Greenfoot.getRandomNumber(90) - 45);
       }   
       if (getX() <= 5 || getX() >= getWorld().getHeight() - 5)
       {
           turn(180);
       }
       if (getY() <= 5 || getY() >= getWorld().getHeight() - 5)
       {
           turn(180);
       }
}
}  
Heet_Patel Heet_Patel

2018/2/24

#
It works but it doesn't work properly all the time. They don't go spastic anymore but when they go to the edge of the world they don't move. I still don't understand if it is a bug or not.
Vercility Vercility

2018/2/24

#
Line 22 should be getWidth
You need to login to post a reply.