Vectors and Obstacles HELP 2
in
Programming Questions
•
1 year ago
Hello again,
I am still struggling to have my vectors read the background image. I want my ellipses to change directions when they reach a black obstacle on the background image. At the moment I am using:
void avoid() {
for (int i = 0; i < ballCollection.size(); i++) {
color locationColour = get (int(loc.x), int(loc.y));
if (locationColour != -1) { //if locationColour is not equal to white
for (int i = 0; i < ballCollection.size(); i++) {
color locationColour = get (int(loc.x), int(loc.y));
if (locationColour != -1) { //if locationColour is not equal to white
speed.x = speed.x * -1;
speed.y = speed.y * -1;
}
}
}
speed.y = speed.y * -1;
}
}
}
It is not working at all. I tested if it is reading the backround colour by using :
void display() {
for (int i = 0; i < ballCollection.size(); i++) {
color locationColour = get (int(loc.x), int(loc.y));
if (locationColour != -1) {
fill(255,0,0);
}
if (locationColour == -1){
fill(0,255,0);
}
}
noStroke();
ellipse(loc.x, loc.y, 5, 5);
}
for (int i = 0; i < ballCollection.size(); i++) {
color locationColour = get (int(loc.x), int(loc.y));
if (locationColour != -1) {
fill(255,0,0);
}
if (locationColour == -1){
fill(0,255,0);
}
}
noStroke();
ellipse(loc.x, loc.y, 5, 5);
}
and it did seem to be reading the background gif...
does anyone know how to use background images (black and white two bif gifs) as obstacles??
Thanks
kbwhi1
1