looping question (kind of)
I''m making a console game right now in C++, but I have a question. to move the character, I am using a getkey function in a while loop. So what it does is wait for a key press then goes trough the loop again to see if it is the escape key, if not it goes again. I also have the enemy movement in the loop. But having it set up like that means that the enemies only move when I press a key. How do I set it up so that even if I dont press anything and the character is just sitting there, the enemies still move around. Thanks in advance for the help.
while( 1 ) {
do some stuff...
if( keypress ) {
move player
}
update enemy
do some other stuff...
}
What I''m trying to say is: use an if statement to check for keyboard input
do some stuff...
if( keypress ) {
move player
}
update enemy
do some other stuff...
}
What I''m trying to say is: use an if statement to check for keyboard input
I wrote a very similar program and I used the function kbhit();
while(command != ''~'') {
while(!kbhit()) dostuff();
command = getch();
if(command = ''W'')
...
|
|
|
V
}
while(command != ''~'') {
while(!kbhit()) dostuff();
command = getch();
if(command = ''W'')
...
|
|
|
V
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement