Der Ball geht überall ins Tor, wir wollen es aber natürlich begrenzen! HELP!!
public void act(){
//player.setLocation(player.getX(),getY());
ball.setLocation(ball.getX() + dx, ball.getY() + dy);
if(ball.getY() >= computer.getY() - 25 && ball.getY() <= computer.getY() + 25 && ball.getX() + dx >= computer.getX()){
dx = -dx;
dy = (ball.getY() - computer.getY())/2;
Greenfoot.playSound("beep.wav");
}
if(ball.getY() >= player.getY() - 25 && ball.getY() <= player.getY() + 25 && ball.getX() + dx <= player.getX()){
dx = -dx;
dy = (ball.getY() - player.getY())/2;
Greenfoot.playSound("beep.wav");
}
if(ball.getY() <= 5){
ball.setLocation(ball.getX(),6);
dy = - dy;
}
if(ball.getY() >= this.getHeight() - 5 ){
ball.setLocation(ball.getX(),this.getHeight() -6);
dy = -dy;
}
else if(ball.getX() <= 5 || ball.getX() >= this.getWidth() -5){
if(ball.getX() <= 5){
c++;
cScore = String.valueOf(c);
read2.clear();
read2.drawString(cScore,2,20);
s2.setImage(read2);
}
else if( ball.getX() >= this.getWidth() -5){
p++;
pScore = String.valueOf(p);
read1.clear();
read1.drawString(pScore,2,20);
s1.setImage(read1);
}
if(p == 4 || c == 4){
Greenfoot.stop();
}
ball.setLocation(getWidth()/2, getHeight()/2);
player.setLocation(50, getHeight()/2);
computer.setLocation(getWidth()-50 , getHeight()/2);
dy = 0; // Codes von anderm Spiel übernommen!
}
DANKE IM VORAUS!!!!