Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

slickshoes113

looping question (kind of)

This topic is 5542 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
use GetAsyncKeyState rather than getch

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
I wrote a very similar program and I used the function kbhit();


while(command != ''~'') {

while(!kbhit()) dostuff();

command = getch();

if(command = ''W'')
...
|
|
|
V


}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!