We are about to switch to a new forum software. Until then we have removed the registration on this forum.
//my balloons and towers are (40, 40)
void drawTower() {
for (int i=w.balloonList.size(); i == -1; i--) {
Balloon balloon = w.balloonList.get(i);
if (dist(pos.x+20, pos.y+20, balloon.pos.x + 20, balloon.pos.y + 20) < radius) {
bPosX = balloon.pos.x;
bPosY = balloon.pos.y;
}
}
float angle = atan2(bPosY - (pos.y+20), bPosX - (pos.x+20)) + HALF_PI;
pushMatrix();
translate(pos.x + 20, pos.y + 20);//origin
rotate(angle);
image(monkey, -20, -20);
popMatrix();
if (mouseX > pos.x && mouseX < pos.x+40
&& mouseY > pos.y && mouseY < pos.y+40) {
noStroke();
fill(0, 0, 155, 60);//sets a blue colour slightly visible
ellipse(pos.x+20, pos.y+20, radius*2-40, radius*2-40);//outer ring of radius around the tower
}
}
Answers
this is too briefly written
what is pos.x ?
why do you have monkey in line 14 ? Is that the tower?
the if clause and the for loop are ending in line 9/10 in your code (the very first post)
thus only the last ball that is close enough (the dist() thing) can turn the tower
so I took out the dist() and the for-loop (so maybe you need to fix that part)
I haven't changed the rotation itself (the block between pushMatrix and popMatrix)
;-)