public class Ball extends Actor
{
/**
* Responds to motion control from the arrow keys and removes
* any buttons from the world when it intersects them.
*/
public void act() {
handleKeyPress();
lookForButton();
}
/**
* Handles input from the arrow keys.
*/
public void handleKeyPress() {
checkLeftArrow() ;
checkRightArrow() ;
checkUPArrow() ;
checkDownArrow() ;
}
}
/**
* Checks to see if the left arrow key is being pressed.
* If it is, then the ball sets its rotation angle to zero degrees
* and moves backward 5 units. If it is not being pressed,
* this method does nothing.
*/
public void checkLeftArrow() {
public void act() {
if (Greenfoot.isKeyDown("left")
{
setRotation(0);
turn(-5);
}
}
}
/**
* Checks to see if the right arrow key is being pressed.
* If it is, then the ball sets its rotation angle to zero degrees
* and moves forward 5 units. If it is not being pressed,
* this method does nothing.
*/
public void checkRightArrow() {
public void act() {
if (Greenfoot.isKeyDown("right")
{
setRotation(0);
turn(5);
}
}
}
/**
* Checks to see if the up arrow key is being pressed.
* If it is, then the ball sets its rotation angle to 270 degrees
* and moves forward 5 units. If it is not being pressed,
* this method does nothing.
*/
public void checkUpArrow() {
public void act() {
if (Greenfoot.isKeyDown("up")
{
setRotation(270);
turn(5);
}
}
}
/**
* Checks to see if the down arrow key is being pressed.
* If it is, then the ball sets its rotation angle to 90 degrees
* and moves forward 5 units. If it is not being pressed,
* this method does nothing.
*/
public void checkDownArrow() {
public void act() {
if (Greenfoot.isKeyDown("down")
{
setRotation(90);
turn(5);
}
}
}
public class Button extends Actor
{
/**
* Checks to see if the ball is "touching" an object of the Button class.
* If it is, then the ball removes from the World a Button that it touches.
* If the ball isn't touching an object of the Button class, then this
* method does nothing.
*/
public void lookForButton() {
Actor B =getOneIntersectingObject(Ball.class)
if (isTouching(Ball.Class))
{
removeTouching(Ball.class)
}
}
}