By the way, when I use your idea the Paddle rotates a full round and will not come back.
if (getY() >= (world.getHeight() - 10))
{
world.removeObject(this);
world.addObject(ball, 460, 530);
removed++;
}
if (getX() <= 7 || getX() >= (getWorld().getWidth()-7))
{
motionX = -motionX;
} import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Right here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Right extends Flippers
{
private boolean isDown;
private int paddleRotation;
/**
* Act - do whatever the Right wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public Right()
{
this(30);
}
public Right(int rotation)
{
setRotation(getRotation()-rotation);
paddleRotation = 0;
}
public void act()
{
rotatePaddle();
}
public void rotatePaddle()
{
if (!isDown && Greenfoot.isKeyDown("right"))
{
isDown = true;
int xPosition = this.getX();
int yPosition = this.getY();
if (paddleRotation <= 60 && paddleRotation >= 120)
{
setRotation(getRotation()+1);
paddleRotation++;
}
int newX = xPosition + 10;
int newY = yPosition - 50;
setLocation(newX, newY);
}
if (isDown && !Greenfoot.isKeyDown("right"))
{
isDown = false;
if (paddleRotation >= 60 && paddleRotation <= 120)
{
setRotation(getRotation()-1);
paddleRotation--;
}
int xPosition = this.getX();
int yPosition = this.getY();
int newX = xPosition - 10;
int newY = yPosition + 50;
setLocation(newX, newY);
}
}
}
if (!isDown && Greenfoot.isKeyDown("right"))
{
isDown = true;
int xPosition = this.getX();
int yPosition = this.getY();
if (paddleRotation < 60)
{
setRotation(getRotation()+1);
paddleRotation++;
}
int newX = xPosition + 10;
int newY = yPosition - 50;
setLocation(newX, newY);
}
if (isDown && !Greenfoot.isKeyDown("right"))
{
isDown = false;
int xPosition = this.getX();
int yPosition = this.getY();
int newX = xPosition - 10;
int newY = yPosition + 50;
setLocation(newX, newY);
}
if (!isDown && paddleRotation > 0) {
setRotation(getRotation()-1);
paddleRotation++;
}public void rotatePaddle()
{
int xPosition = this.getX();
int yPosition = this.getY();
int change = 0;
if (Greenfoot.isKeyDown("right") && paddleRotation < 60) change = 1;
if (!Greenfoot.isKeyDown("right") && paddleRotation > 0) change = -1;
if (change == 0) return;
setRotation(getRotation()+change);
paddleRotation += change;
int newX = xPosition + 10 * change;
int newY = yPosition - 50 * change;
setLocation(newX, newY);
}public void rotatePaddle()
{
int xPosition = this.getX();
int yPosition = this.getY();
int change = 0;
if (Greenfoot.isKeyDown("right") && paddleRotation < 60) change = 1;
if (!Greenfoot.isKeyDown("right") && paddleRotation > 0) change = -1;
if (change == 0) return;
setRotation(getRotation() + 6 * change);
paddleRotation += 6 * change;
int newX = xPosition + 1 * change;
int newY = yPosition - 5 * change;
setLocation(newX, newY);
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.lang.Math;
/**
* Write a description of class Ball here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Ball extends Actor
{
private double motionY;
private double fired;
private int motionX;
private double rightDown;
private double leftDown;
private boolean hitFlipper;
private int changeMotionX;
private int score;
private boolean worldTwo;
public Ball()
{
this(0.0);
}
public Ball(double speed)
{
motionY = -speed;
motionX = 0;
fired = 0;
rightDown = 0;
leftDown = 0;
hitFlipper = true;
score = 0;
worldTwo = false;
}
/**
* Act - do whatever the Ball wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
newLevel();
moveBall();
}
public void moveBall()
{
int xPosition = this.getX();
double yPosition = this.getY();
simulateGravity();
checkForSpringle();
fire();
changeMotionX++;
changeMotionX();
checkForLine();
checkForCirkel();
checkForBlock();
checkForFlipper();
checkForProtonWave();
float newY = Math.round(yPosition + motionY);
int newX = xPosition + motionX;
setLocation(newX,(int)newY);
if (fired != 0)
{
ATM myATM = (ATM) getWorld();
myATM.addScore();
score++;
}
}
private void newLevel()
{
if(score >= 3000)
{
Greenfoot.setWorld(new ATM(1));
worldTwo = true;
}
if (worldTwo && score >= 3000)
{
ATM myATM = (ATM) getWorld();
myATM.youWon();
}
}
private void changeMotionX()
{
if(changeMotionX == 10 && getX() != 460)
{
motionX = -(1 + Greenfoot.getRandomNumber(5));
changeMotionX = 0;
}
}
private void fire()
{
if (getX()==460 && Greenfoot.isKeyDown("space"))
{
fired++;
}
if (fired == 500)
{
fired = 500;
}
}
private void checkForSpringle()
{
Actor actor = getOneIntersectingObject(Springle.class);
if (actor != null)
{
motionY = (-0.3 * fired);
}
}
private void simulateGravity()
{
if (fired >= 1)
{
if (motionY < 0)
{
motionY = motionY - (motionY * 0.005);
}
if (motionY > -0.5 && motionY <= 0)
{
motionY = 0.48;
}
if (motionY > 0)
{
motionY = motionY + (motionY * 0.005);
}
}
}
private void checkForLine()
{
Actor line = getOneIntersectingObject(Line.class);
if (getX() >=430 && getY() <=60)
{
if (line != null)
{
motionX = -(1+Greenfoot.getRandomNumber(1));
motionY = -motionY;
ATM myATM = (ATM) getWorld();
myATM.addFiveScore();
score = score + 5;
}
}
else
{
if (line != null)
{
motionX = -motionX;
}
}
if (line != null && getY() >=420)
{
motionY = -motionY;
}
}
private void checkForCirkel()
{
Actor cirkel = getOneIntersectingObject(Cirkel.class);
if (cirkel != null)
{
motionX = -motionX;
motionY = -motionY;
ATM myATM = (ATM) getWorld();
myATM.addFiveScore();
score = score + 5;
}
}
private void checkForBlock()
{
Actor block = getOneIntersectingObject(Block.class);
if (block != null)
{
motionX = -motionX;
motionY = -motionY;
ATM myATM = (ATM) getWorld();
myATM.addFiveScore();
score = score + 5;
}
}
private void checkForFlipper()
{
Actor right = getOneIntersectingObject(Right.class);
if (right != null && hitFlipper)
{
motionY = -motionY;
motionX = -motionX;
hitFlipper = false;
if(Greenfoot.isKeyDown("right"))
{
rightDown = rightDown + 0.3;
}
else
{
rightDown = 1;
}
if (rightDown == 2)
{
rightDown = 1.9;
}
motionY = (2-rightDown) * motionY;
ATM myATM = (ATM) getWorld();
myATM.addTenScore();
score = score + 10;
}
Actor left = getOneIntersectingObject(Left.class);
if (left != null && hitFlipper)
{
motionY = -motionY;
motionX = -motionX;
hitFlipper = false;
if(Greenfoot.isKeyDown("left"))
{
leftDown = leftDown + 0.3;
}
else
{
leftDown = 1;
}
if (rightDown == 2)
{
leftDown = 1.9;
}
motionY = (2-leftDown)*motionY;
ATM myATM = (ATM) getWorld();
myATM.addTenScore();
score = score + 10;
}
if (getY() <=530)
{
hitFlipper = true;
}
}
private void checkForProtonWave()
{
Actor protonwave = getOneIntersectingObject(ProtonWave.class);
if (protonwave != null)
{
ATM myATM = (ATM) getWorld();
myATM.endGame();
}
}
private void checkSide()
{
World world = getWorld();
Ball ball = new Ball();
Springle springle = new Springle();
if (getY() == 7)
{
motionY = -motionY;
ATM myATM = (ATM) getWorld();
myATM.addFiveScore();
score = score + 5;
}
if (getX() <= 7 || getX() >= (getWorld().getWidth()-7))
{
motionX = -motionX;
}
if (getY() >= (world.getHeight() - 10))
{
ATM myATM = (ATM) getWorld();
myATM.endGame();
world.removeObject(this);
Greenfoot.stop();
}
}
}