Guest_imported
New member
- Jan 1, 1970
- 0
How can I let a simple 30 second countdown timer (I used a for loop with Sleep(1000); to make a timer)run, while other parts of my program are running during its course?
for(x=30;x>-1;x--) // Here's the timer
{
printf("%i", x);
Sleep(1000);
SetConsoleCursorPosition(hOutput, timer);
printf(" "
SetConsoleCursorPosition(hOutput, timer);
}
//... and a few lines down
while(1)
{
INPUT_RECORD InputRecord;
DWORD Events=0;
ReadConsoleInput(hInput,&InputRecord,1,&Events);
if(InputRecord.EventType == KEY_EVENT && InputRecord.Event.KeyEvent.bKeyDown)
{
if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_UP)
{
SetConsoleCursorPosition(hOutput, Info.location);
printf(" "
Info.location.Y--;
SetConsoleCursorPosition(hOutput, Info.location);
printf("%c", 1);
}
else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_DOWN)
{
SetConsoleCursorPosition(hOutput, Info.location);
printf(" "
Info.location.Y++;
SetConsoleCursorPosition(hOutput, Info.location);
printf("%c", 1);
}
else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_LEFT)
{
SetConsoleCursorPosition(hOutput, Info.location);
printf(" "
Info.location.X--;
SetConsoleCursorPosition(hOutput, Info.location);
printf("%c", 1);
}
else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_RIGHT)
{
SetConsoleCursorPosition(hOutput, Info.location);
printf(" "
Info.location.X++;
SetConsoleCursorPosition(hOutput, Info.location);
printf("%c", 1);
}
}
if(Info.location.X == 55 && Info.location.Y == 21)
{
SetConsoleCursorPosition(hOutput, Stats.victory);
printf("You've won! Congratulations!\n"
Sleep(2000);
SetConsoleCursorPosition(hOutput, Stats.victory);
printf(" "
SetConsoleCursorPosition(hOutput, Stats.home );
break;
}
}
//and thats the loop that I want to run during the timer's running... its the beginnings of a game in which the player has 30 seconds to reach a specified goal on the screen. I'm sure there's a way to let both the timer and the game loop run at the same time... if someone could help it would be great. thanks.
for(x=30;x>-1;x--) // Here's the timer
{
printf("%i", x);
Sleep(1000);
SetConsoleCursorPosition(hOutput, timer);
printf(" "
SetConsoleCursorPosition(hOutput, timer);
}
//... and a few lines down
while(1)
{
INPUT_RECORD InputRecord;
DWORD Events=0;
ReadConsoleInput(hInput,&InputRecord,1,&Events);
if(InputRecord.EventType == KEY_EVENT && InputRecord.Event.KeyEvent.bKeyDown)
{
if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_UP)
{
SetConsoleCursorPosition(hOutput, Info.location);
printf(" "
Info.location.Y--;
SetConsoleCursorPosition(hOutput, Info.location);
printf("%c", 1);
}
else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_DOWN)
{
SetConsoleCursorPosition(hOutput, Info.location);
printf(" "
Info.location.Y++;
SetConsoleCursorPosition(hOutput, Info.location);
printf("%c", 1);
}
else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_LEFT)
{
SetConsoleCursorPosition(hOutput, Info.location);
printf(" "
Info.location.X--;
SetConsoleCursorPosition(hOutput, Info.location);
printf("%c", 1);
}
else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_RIGHT)
{
SetConsoleCursorPosition(hOutput, Info.location);
printf(" "
Info.location.X++;
SetConsoleCursorPosition(hOutput, Info.location);
printf("%c", 1);
}
}
if(Info.location.X == 55 && Info.location.Y == 21)
{
SetConsoleCursorPosition(hOutput, Stats.victory);
printf("You've won! Congratulations!\n"
Sleep(2000);
SetConsoleCursorPosition(hOutput, Stats.victory);
printf(" "
SetConsoleCursorPosition(hOutput, Stats.home );
break;
}
}
//and thats the loop that I want to run during the timer's running... its the beginnings of a game in which the player has 30 seconds to reach a specified goal on the screen. I'm sure there's a way to let both the timer and the game loop run at the same time... if someone could help it would be great. thanks.