Hey... Anyway below I have pasted an excerpt from my in-progress racing game (sorta).
I was trying to use time.h to have it where the opponent's car would move after 1 second regardless if the user has moved or not, but that's the problem. The opponent only moves after you move, so I would like to know how could I make the opponent's car keep on moving even if I haven't moved my car.
Also I included the whole code (in case you want to look at it).
Code:
unsigned int c; //For arrow keys.
char lane[16];
const char blnk = ' ';
const char ucar = '>';
const char ocar = '<';
lane[0] = ucar;
lane[1] = blnk;
lane[2] = blnk;
lane[3] = blnk;
lane[4] = blnk;
lane[5] = blnk;
lane[6] = blnk;
lane[7] = blnk;
lane[8] = blnk;
lane[9] = blnk;
lane[10] = blnk;
lane[11] = blnk;
lane[12] = blnk;
lane[13] = blnk;
lane[14] = blnk;
lane[15] = blnk;
int a = 15; //For opponents car to move.
while(1){
cout<<"\n\
================\n\
"<<lane[0]<<" "<<lane[1]<<" "<<lane[2]<<" "<<lane[3]<<" "<<lane[4]<<" "<<lane[5]<<" "<<lane[6]<<" "<<lane[7]<<"\n\
----------------\n\
"<<lane[8]<<" "<<lane[9]<<" "<<lane[10]<<" "<<lane[11]<<" "<<lane[12]<<" "<<lane[13]<<" "<<lane[14]<<" "<<lane[15]<<"\n\
================\
\n\n";
time(&start_time);
time(&cur_time);
lane[a] = ocar;
lane[a + 1] = blnk;
a--;
if (a < 0){
a = 15;
}
/*
if ( ( time(&cur_time) - time(&start_time) ) != 1){
lane[a] = ocar;
lane[a + 1] = blnk;
a--;
if (a < 0){
a = 15;
}
}
*/
c = getch();
if (c == 72 || c == 77){ //Up & Right - In Order
if (lane [8] = ucar){
lane[8] = blnk;
lane[0] = ucar;
}
}
else if (c == 80 || c == 75){ //Down & Left - In Order
if (lane [0] = ucar){
lane[0] = blnk;
lane[8] = ucar;
}
}
clrscr();
}
Thanks for any help,
~BW