Hi guys,
I'm new to this board, tried searching for possible threads that could be of help, but even implementing the ideas from the first thread in search results didn't help. I know it's more of a coding issue, the program runs, but collisions are not detected. And well, that's quite necessary :) Can anyone help?
I've posted only an excerpt of the code. Should more be necessary, I'll definitely post more!
FYI, the draw-function resides in a class, and is called from the applet's main draw-function.
Code: void draw() {
order();
NewPie pie;
for (int i = 0; i < this._pies.length; i++) {
pie = (NewPie) this._pies[i];
pie.setDiameter(this._maxDiam - i * (this._maxDiam / this._pies.length));
if (!pie.isDrawn()) {
checkCollision(pie);
}
pie.draw(this._items);
}
this.evaluateMouseMove();
}
void checkCollision(NewPie pie) {
NewPie temp;
float tempX = random(pie.getDiameter()/2, width - pie.getDiameter()/2);
float tempY = random(pie.getDiameter()/2, height - pie.getDiameter()/2);
boolean isColliding = false;
for (int i = 0; i < this._pies.length; i++) {
temp = (NewPie) this._pies[i];
if (temp.isDrawn() && !temp.equals(pie)) {
if (dist(temp.getPosX(), temp.getPosY(), tempX, tempY) < (temp.getDiameter() / 2 + pie.getDiameter() / 2)) {
checkCollision(pie);
isColliding = true;
}
}
}
if (isColliding) {
pie.setPosition(tempX, tempY);
}
}
Any help greatly appreciated, I've been breaking my head over this for hours!