why this doesnt work?
in
Programming Questions
•
2 years ago
Im trying to calculate collision between the mouse and a group of points stored in an .txt file in this way:
0.0915193 1 2.49807 -1.2045 -3.12577;
0.183039 2 2.384 -2.06928 -3.37606; .....
The third value is the x and 4th is y. The code is not working as expected , its to suppose to change the color of the points i touch with the mouse, but other points change its color, do anybody have an idea of what am i doing wrong?
agente[] bichos=new agente[344];
String[] sp;
String[] lines;
void setup(){
size(700,700);
background(250,0,0);
lines = loadStrings("primero.txt");
float ii = 0;
for(int i = 0; i < lines.length ; i++){
bichos[i]=new agente();
sp = split(lines[i] , ' ' );
}
}
void draw(){
background(0,0,0);
stroke(254, 0, 0);
float ii = 0;
float oo = 0;
for(int i = 0; i < lines.length ; i++){
sp = split(lines[i] , ' ' );
ii = 145 + float(sp[2]) * 21;
oo = 145 + float(sp[3]) * 21;
bichos[i].move(ii, oo);
if ( dist( mouseX , mouseY, ii, oo) < 10){
bichos[i].cambia();
}
else { bichos[i].nocambia();};
}
}
class agente{
int x;
float rand_x = random(200);
float rand_y = random(200);
agente() {
}
void move(float ii , float oo) {
x = x+ 1;
ellipse(ii, oo ,10,10);
}
void cambia() {
fill(250,250,0) ;
}
void nocambia() {
fill(250,0,0) ;
}
}
1
