deltaReflect method
Implementation
void deltaReflect(double width, double height) {
double x = pos.dx + dx;
double y = pos.dy + dy;
if (x < size / 2) {
dx *= -1;
x = size / 2;
} else if (x > width - size / 2) {
dx *= -1;
x = width - size / 2;
}
if (y < size / 2) {
dy *= -1;
y = size / 2;
} else if (y > height - size / 2) {
dy *= -1;
y = height - size / 2;
}
pos = Offset(x, y);
}