newt
I have multiple instances of cars. I dont even know how many cars i'll have. I spawn cars every n seconds, and they can be destroyed.
what I want to do is prevent colissions between cars, so if a car is going to collide with another car, I would like it to stop it before they crash.
as a programmer, the solution for that is:
for each car car1
{
for each car car2
{
if car1 "is going to collide with" car2
{
stop car1;
}
}
}
im not asking here how to write a condition to determine if car1 is going to collide with car2.
what im asking is how do I differentiate the cars of each "foreach" loop.
i need to measure the distance beween both cars, for which i need to know the position of both, and write something like
distance(car1.x, car1.y, car2.x, car2.y)
but i just dont have that car1 and car2 references. you said something about an "instance variable"
am i missing something?