Grundlagen der Programmierung 2 SS 2005 - Datei BounceBall.java
import java.lang.Math;
import java.awt.Image;
import gamelet.*;
public class BounceBall extends SimpleBall {
BounceBall(Gamelet theGamelet) {
super(theGamelet);
setWrapAround(false);
}
protected void calculateNewPosition() {
super.calculateNewPosition();
if (getXPos() < 0) {
setXVelocity(-getXVelocity());
setXPos(-getXPos());
} else if (getXPos() >= (getGamelet().getWidth() - getWidth())) {
setXVelocity(-getXVelocity());
setXPos(2 * (getGamelet().getWidth() - getWidth()) - getXPos());
}
if (getYPos() < 0) {
setYVelocity(-getYVelocity());
setYPos(-getYPos());
} else if (getYPos() >= (getGamelet().getHeight() - getHeight())) {
setYVelocity(-getYVelocity());
setYPos(2 * (getGamelet().getHeight() - getHeight()) - getYPos());
}
} /* calculateNewPosition */
} /* BounceBall */
Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 22.04.2005


