Hello i have a question about my game.
i have an object and i want to move it to start moving 5 steps up and then down again infinitly,
im just a beginner so sorry if i sound stupid..
I would do something like this:
int counter = -1; //member variable
public void act()
{
counter = (counter +1) % 10;
if(counter < 5)
{
setY(getY() + 5);
}
else
{
setY(getY() - 5);
}
}
Something like that. the counter will go from 0 to 9 forever, if the counter is go up and when it is it goes back down.
You can make it start at a random part in the wave by doing this:
int counter = Greenfoot.getRandomNumber(10);
the +5 and -5 are just numbers I pulled out of thin air; it can be whatever you need it to be.