Hey guys,
I am trying to code a game where the player is centered at the screen and, using Danpost's Infinite Scrolling Background (Opens in Greenfoot as "continuous scroller test") I have gotten it to work. I have other actors that are my enemies.
Here's what I need help with:
I would like to make the enemies spawn outside of the height and width of the screen (offscreen).
I would like to have the enemies move off screen/out of view without seeing them on the edge of the screen(move completely out of view but still be there).
I would like to make my enemies move around randomly WITHOUT turning (rotating). For this, I have tried multiple things. I tried setting their number to a random rotation and then setting it back to 0 (didn't work), and I tried having a random number between 0 and 4 choose one of four scenarios: turn left, turn right, go up, go down. This works, but, once as soon as I implement the code to make these turns (using setLocation), the enemies do not run off of the screen correctly as they had before. As I run around, I seem to drag the enemies sometimes. This happens when the enemies are running downwards and I move sideways and catch them on the side of the screen, or when they are running sideways and I move vertically and catch them on the top or bottom.
Does anyone know how to fix the third problem in particular? I guess this is a question mainly for Danpost, as he made the Infinite Scrolling Background.
I will attach the code that, when implemented, makes the enemies get dragged.
Thank you.
if(Greenfoot.getRandomNumber(100) == 1)
{
int random = Greenfoot.getRandomNumber(4);
if(random == 1)
{
one = true;
two = false;
three = false;
four = false;
}
if(random == 2)
{
one = false;
two = true;
three = false;
four = false;
}
if(random == 3)
{
one = false;
two = false;
three = true;
four = false;
}
if(random ==4)
{
one = false;
two = false;
three = false;
four = true;
}
}
if(one)this.setLocation(getX(), getY() +(int)3);
if(two)this.setLocation(getX(), getY() -(int)3);
if(three)this.setLocation(getX()+ (int)3, getY());
if(four)this.setLocation(getX()-(int)3, getY());
}

