Im making a Touhou parody in Greenfoot but my Charackter can fly to the scoreboard is there a code where I can adjust the space where all charackter are able to spawn/move?
this.addObject(new <class name>, Greenfoot.getRandomNumber(200) + 100, Greenfoot.getRandomNumber(200) + 100);
int newX = <code to calculate the next x-coordinate>; int newY = <code to calculate the next y-coordinate>; if (newX > 100 && newX < 300 && newY > 100 && newY < 300) this.setLocation(newX, newY);
int dx =0, dy = 0;
if (Greenfoot.isKeyDown("d")) dx++;
if (Greenfoot.isKeyDown("a")) dx--;
if (Greenfoot.isKeyDown("s")) dy++;
if (Greenfoot.isKeyDown("w")) dy--;if (dx*dy == 0 && dx+dy != 0 // one, and only one, direction is not zero
&& getX()+dx*speed >= 50 && getX()+dx*speed <= 500 // new x allowable
&& getY()+dy*speed >= 50 && getY()+dy*speed <= 550) // new y allowable
{
setLocation(getX()+dx*speed, getY()+dy*speed);
}public void move()
{
int newX = this.getX();
int newY = this.getY();
if (Greenfoot.isKeyDown("w")) newY--;
else if (Greenfoot.isKeyDown("a")) newX--;
else if (Greenfoot.isKeyDown("s")) newY++;
else if (Greenfoot.isKeyDown("d")) newX++;
if (newX > 50 && newX < 500 && newY > 50 && newY < 500) this.setLocation(newX, newY);
}move();
this.addObject(new <class name>, Greenfoot.getRandomNumber(450) + 50, Greenfoot.getRandomNumber(450) + 50);