only can generate movement but its not random...
random movement in C
Page 1 of 110 Replies - 6507 Views - Last Post: 20 August 2006 - 03:13 AM
#1
random movement in C
Posted 16 August 2006 - 07:21 AM
can anyone explain me how to generate random movement of a character horizontaly using rand function?
only can generate movement but its not random...
only can generate movement but its not random...
Replies To: random movement in C
#2
Re: random movement in C
Posted 16 August 2006 - 07:56 AM
the rand functions works like this:
you need to seed it first:
I use this:
then to use rand:
Where range is the number of random numbers to go between, and offset is where they should start from 0.
you need to seed it first:
I use this:
#include <time.h> #include <stdlib.h> srand(time(0));
then to use rand:
value = rand()%range + offset;
Where range is the number of random numbers to go between, and offset is where they should start from 0.
#3
Re: random movement in C
Posted 16 August 2006 - 09:50 AM
Ive understand how it works but for example how do I print the movement of a char?!
sory if its a dummy question but Im a newbie...
sory if its a dummy question but Im a newbie...
This post has been edited by jorijo: 16 August 2006 - 09:58 AM
#4
Re: random movement in C
Posted 16 August 2006 - 11:20 AM
how are you planning to generate any movement at all?? are you using graphics mode of text mode??
#5
Re: random movement in C
Posted 16 August 2006 - 11:33 AM
c.fcolor(0); /* atribui a cor azul ao Carro2*/
gotoxy(23,80-i);printf("%c",219); /* desenha o caracter do Carro2*/
gotoxy(22,80-i);printf("%c",219);
for(f=1;f<10000000;f++); /* movimento do Carro2*/
if (carro2==10) /* dimensão do Carro 2 - 10 caracateres*/
{
gotoxy(22,80-i+carro2);
printf(" "); /* apaga a posicao anterior à dimensao do Carro2*/
gotoxy(23,80-i+carro2);
printf(" ");
}
else
carro2=carro2+1;
this how Im making the movemement
This post has been edited by jorijo: 16 August 2006 - 11:36 AM
#6
Re: random movement in C
Posted 16 August 2006 - 11:44 AM
ohk that would be text mode. im not sure if im getting the co ordinates correct but the y axis is from 0-25 and x axis 0-80(correct me if im wrong) bow generate using rand() different values for coordinates in the loop and use them with the gotoxy() function. try that. i guess it should work
#8
Re: random movement in C
Posted 17 August 2006 - 03:04 AM
yes the co ordinates are right but I dont understand what you mean with this --> "... bow generate using rand() different values for coordinates in the loop and use them with the gotoxy() function."
born2code what do you mean with matrix effect?
born2code what do you mean with matrix effect?
#9
Re: random movement in C
Posted 18 August 2006 - 09:27 PM
oops
silly typo it was "now" and not "bow" . a little bit of explanation again. i hope you got the use of rand() . now you can generate different combintaion of coordinates from this .so you can use the found set of coordinates in the gotoxy() function and therefore you would get your random motion
#10
Re: random movement in C
Posted 19 August 2006 - 08:25 AM
now I can generate random using rand() but cant control the speed do you know someway to control it?
#11
Re: random movement in C
Posted 20 August 2006 - 03:13 AM
well yes you can always use the delay() function defined in dos.h . the argument passed to it is taken in milliseconds. it suspends the execution of the program for that much time.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|