Think of a traffic light that only turns green or red.
If it is green, the next car passing through the detection point (pink square) will be directed to the green path and will cause the traffic light to turn red.
This way the next car that passes, will be directed to the red path, also making the green light, and so on.
Let's assume that two cars are in the same place and at the same speed and thus collide with the pink square at the same time. How can we make both directions to the same path be green or red and so that the light of the traffic light changes only once?
Considering "obj_BolaAzul" as "obj_blueCar", "obj_BolaRoxa" as "obj_purpleCar" and "obj_Cannon" as "obj_trafficLight".
The codes are basically:
obj_traficLight collision with obj_blueCar
if greenLight==true{
obj_blueCar.move_towards_point(x+1,y,manSpeed); //go to right
testGreen=true;
}
if redLight==true{
obj_blueCar.move_towards_point(x-1,y,manSpeed); //go to left
testRed=true;
}
if testGreen==true{
greenLight=false;
redLight=true
}
if testRed==false{
redLight=false;
greenLight=true
}
There are more things besides in code, but it has no relation to the problem.
I'm sorry again for the translation errors, I'm still not speaking English.