random action
Posted: Sun Nov 06, 2011 4:08 am
okay how would I create a random action in my game.
like lets say I want my character after being shot to stop and turn around and move in negative x direction meaning like if I walk from point A to B now I want it to go back to point B. based on a random probability. how?
this is the script I am using but its not working.
int main()
{
int Direction1=1;
int Direction2=-1;
int face;
for(int Direction=1; Direction <=7; ++Direction);
{
face=1+rand() %7;
switch(face)
{
case 1:
++Direction1;
Direction=1;
Speed++;
break;
case 2:
++Direction2;
Direction=-1;
Speed++;
break;
Default:
cout<<"Program should never get here";
}
}
cout<<"face" <<setw(7)<<"Direction"<< endl;
cout<<" 1" <<setw(7)<<Direction1
<<"\n 2" <<setw(7)<<Direction2 << endl;
}
like lets say I want my character after being shot to stop and turn around and move in negative x direction meaning like if I walk from point A to B now I want it to go back to point B. based on a random probability. how?
this is the script I am using but its not working.
int main()
{
int Direction1=1;
int Direction2=-1;
int face;
for(int Direction=1; Direction <=7; ++Direction);
{
face=1+rand() %7;
switch(face)
{
case 1:
++Direction1;
Direction=1;
Speed++;
break;
case 2:
++Direction2;
Direction=-1;
Speed++;
break;
Default:
cout<<"Program should never get here";
}
}
cout<<"face" <<setw(7)<<"Direction"<< endl;
cout<<" 1" <<setw(7)<<Direction1
<<"\n 2" <<setw(7)<<Direction2 << endl;
}