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

2016/4/22

how to make my actor move per cell?

Raftiana Raftiana

2016/4/22

#
hello, i'm beginner on greenfoot . i want to make my actor move upwards/downwards just one cell, but how ? note : there's only 2 path for my actor to move upwards/downwards please help :')
danpost danpost

2016/4/22

#
Raftiana wrote...
i want to make my actor move upwards/downwards just one cell, but how ? note : there's only 2 path for my actor to move upwards/downwards
Would this be a user controlled actor? What movement code are you trying (try something -- then post what you tried)?
Raftiana Raftiana

2016/4/24

#
we already found the way out .. but then 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 space(){
      this.addObject(new Controller(), 600, 80);
}
the code on class Controller :
public class Controller extends Actor
{
    private int stepCounter;
    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);
        }
    }
}
danpost danpost

2016/4/24

#
You have your 'stepCounter' field getting assigned a value less than 100 at line 14. Now, the modulus ('%') result on that value will be zero on any number greater than or equal to 100. Therefore, the conditions on lines 25, 29, 44 and 47 will be true every time, It would be better on your 'if' statements to use the following format (this example would replace line 47):
if (stepCounter == 200)
But the number compared with should be one that the field could possibly have assigned to it (a number less than 100).
You need to login to post a reply.