D
das hier ist zwar java, aber vielleicht hilfts dir etwas weiter..
private void mirror (double alpha) {
this.dir = 180.0 - (this.dir - alpha);
if (this.dir > 360.0) {
this.dir -= 360.0;
}
if (this.dir < 0) {
this.dir += 360;
}
}
public void redirect(Ball foreign) {
double a = foreign.getPosX() - this.posX;
double b = foreign.getPosY() - this.posY;
double c = Math.sqrt((a * a) + (b * b));
double alpha = Math.asin(b/c);
mirror (alpha);
}
public boolean collides(double x, double y, int r, double dir) {
double newX = posX, newY = posY;
/* test for collision */
newX = this.posX + (Math.sin(Math.PI / 180.0 * this.dir) * this.impulse );
newY = this.posY + (Math.cos(Math.PI / 180.0 * this.dir) * this.impulse );
double a = x - newX;
double b = y - newY;
/* if collision */
if ((a * a) + (b * b) <= (double)((r + this.size)* (r + this.size))) {
return true;
}
return false;
}
P.S.: Ist wirklich nicht grad auf Geschwindigkeit ausgelegt wollte damals in nem Java-Kurs nur etwas mit awt und threads rumspielen..