Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
How to reuse this code? don't want to wright it 1000 times
I have the player's car with his own speed N.
N goes from 1 to 15(15 = max). So I create another car with a T speed(the max speed of T is 8). Then...
if (n==0) t+=something;
if (n==1) t+=something less;
if (n==15)t-= something.
So I have this other car in the screen with his own speed.
And the Crash:
if ( (x,y+n,..) of the first car == (x,y+h,..) of the second) )
crash; // (this is not the real code, this is the way it works)
So, that car has own speed and can crash with the main car from any side.
the (x,y,x,y) coordinates of the car in the screen.
//it sould be at the begining
I want to put many cars in the screen, and I dont want to repeat all that code for each of them. T has a relation with N
so I cant use it again, (if I use it, all the cars will move the same). And if I use a new variable for each car I should type this code 1000 times.(or maybe not?)
So, How can I reuse this code with other cars?
Sorry about my prehistorik english :)