Hi,
I have to make a Breakout-Game for a schoolproject.
But I have the problem that my ball is sticking onthe right side and on the floor (on the floor he has to get removed).
On the left and the top he is bouncing...
I hope you can help me.
public class Ball extends Actor
{
private int dx;
private int dy;
public Ball() {
dx = 10 - Greenfoot.getRandomNumber(21);
dy = -5 - Greenfoot.getRandomNumber(6);
}
/*
* Check the 4 sides
*/
private void pruefeKontaktRandRechts() {
if (getX() >= 626) {
dx = -dx;
}
}
private void pruefeKontaktRandLinks() {
if (getX() <= 0 ){
dx = -dx;
}
}
private void pruefeKontaktRandUnten() {
if (getY() >= 466) {
getWorld().removeObject(this);
}
}
private void pruefeKontaktRandOben() {
if(getY() <= 0) {
dy = -dy;
}
}
public void act()
{
pruefeKontaktRandRechts();
pruefeKontaktRandLinks();
pruefeKontaktRandUnten();
pruefeKontaktRandOben();
setLocation (getX() + dx, getY() + dy);
}
