And the PlayerPick class, now.
public static int red;
public static int blue;
/**
* Constructor for objects of class PlayerPick.
* The screen where the user will decide which paddle they want to use.
*/
public PlayerPick()
{
super(1080, 600, 1); // Create a new world with 1100x600 cells with a cell size of 1x1 pixels.
addObject(new BackToOption(),150,560); //Creates a object of class BackButton
BlueRedPlayerPick bluepick = new BluePick();
addObject(bluepick,420,530); //Creates a object of class BluePick
BlueRedPlayerPick redpick = new RedPick();
addObject(redpick,675,530); //Creates a object of class RedPick
Start start2 = new Start2();
addObject(start2,975,560); //Creates a object of class Start2
}public Red()
{
PlayerRedControlled = PlayerPick.red;
}boolean playerBlueControlled;
/**
* Act - do whatever the Blue wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
checkKeypress(); // This statement calls the checkKeyPress method.
}
/**
* Check whether a control key on the keyboard has been pressed.
* If it has, react accordingly.
*/
public void checkKeypress()
{
Actor pongball = getWorld().getObjects(PongBall.class).get(0);
if(pongball.getX() < 490)
{
if(playerBlueControlled = true)
{
if (Greenfoot.isKeyDown("w")) // Pressing the w key will move the blue paddle up.
{
setLocation(getX(),getY() - 10);
}
if (Greenfoot.isKeyDown("s")) // Pressing the s key will move the blue paddle down.
{
setLocation(getX(),getY() + 10);
}
}
}
else if(playerBlueControlled = false)
{
if(getY() > pongball.getY())
{
if(Greenfoot.getRandomNumber(5) != 0)
{
setLocation(getX(),getY() - 10);
}
else
{
setLocation(getX(),getY() - 5);
}
}
else if(getY() < pongball.getY())
{
if(Greenfoot.getRandomNumber(5) != 0)
{
setLocation(getX(),getY() + 10);
}
else
{
setLocation(getX(),getY() + 5);
}
}
}
BorderCheck(); // This statement calls the BorderCheck method
}