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

2016/4/24

How do i creating object on a random time but in the dafult coordinate

Raftiana Raftiana

2016/4/24

#
we stuck on creating object on a random time but we put the default of coordinate. everytime press "run" it always creating the same object and it pile up . the object i use in this scenario is "coin" and "meteor". the code on space :
public class space extends World
{
       public space()
    {
            this.addObject(new Controller(), 600, 80);
     }
}
The code on Controller :
public class Controller extends Actor
{
    private int stepCounter;
    private int randNum;
    private nyan s;
    public Controller()
    {
      GreenfootImage gfi = this.getImage();
      gfi.clear();
      this.setImage(gfi);
      stepCounter = 0;
    }
     public void act() 
    {
        stepCounter = Greenfoot.getRandomNumber(100);
        
        World w = this.getWorld();
        if ((stepCounter % 50 == 0)== true)
        {
          w.addObject(new koin(), 610, 55);
        }
        if ((stepCounter % 82 == 0)== true)
        {
          w.addObject(new koin(), 610, 155);
        }
        if ((stepCounter % 101 == 0)== true)
        {
          w.addObject(new koin(), 610, 255);
        }
        if ((stepCounter % 201 == 0)== true)
        {
          w.addObject(new koin(), 610, 355);
        }

        
        if ((stepCounter % 51 == 0) == true)
        {  
            w.addObject(new meteor(), 610, 55);
        }
        if ((stepCounter % 70 == 0) == true)
        {  
            w.addObject(new meteor(), 610, 155);
        }
        if ((stepCounter % 102 == 0) == true)
        {  
            w.addObject(new meteor(), 610, 255);
        }
        if ((stepCounter % 200 == 0) == true)
        {  
            w.addObject(new meteor(), 610, 355);
        }
    }
}
this Mockup Game that i meant :
You need to login to post a reply.