How can I stop X from falling down

Hi ! I am currently creating a game to internalize all the things I have learned.

The game is called Choose The Path (stupid name eh), where player have 2 ways and he needs to choose the right path.

I am currently testing if the player will move down, (Since down is the only way)

but when I press DOWN (arrow key) it go straight to the bottom instead of just one step down, I figured out that it is because of the loop. how can I stop X from falling down.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  void drawboard()
{
	while(true)
	{
		//clear system screen
	    system("cls");

	    //draw path
	    cout << "\n\n\n";
	    cout << "\t\t                   | " << LevelNumbers[0] << " |                    " << endl;
	    cout << "\t\t                   |   |                   "<< endl;
	    cout << "\t\t                   |   |                   "<< endl;
	    cout << "\t\t                   | " << LevelNumbers[1] << " |                    " << endl;
	    cout << "\t\t                   |   |                   "<< endl;
	    cout << "\t\t ==================|   |=================== " << endl;
	    cout << "\t\t| " << LevelNumbers[5] << "        " << LevelNumbers[3]  << "         " << LevelNumbers[2] << "          " << LevelNumbers[4] << "        " << LevelNumbers[6] << " |" << endl;
	    cout << "\t\t|    ==================================    |" << endl;
	    cout << "\t\t|   |                                  |   |" << endl;
	    cout << "\t\t|   |                                  |   |" << endl;
	    cout << "\t\t|   |                                  |   |" << endl;
	    cout << "\t\t| " << LevelNumbers[7] << " |                                  | " << LevelNumbers[8] << " |" << endl;
	    cout << "\t\t|   |                                  |   |" << endl;
	    cout << "\t\t|   |                                  |   |" << endl;
	    cout << "\t\t|   |                                  |   |" << endl;
		while(1)
		{
			if(GetAsyncKeyState(VK_DOWN))
			{
				if(LevelNumbers[0] == 'X')
				{
					LevelNumbers[0] = ' ';
					LevelNumbers[1] = 'X';
					break;
				}
				if(LevelNumbers[1] == 'X')
				{
					LevelNumbers[1] = ' ';
					LevelNumbers[2] = 'X';
					break;
				}
				
			}
		}
	}
}


I looped the whole drawpath cause I do not know how else will I print the path.
add sleep statement at the end of the loop (about 2/10 of the seconds will be fine)
what loop ?

this :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
while(1)
		{
			if(GetAsyncKeyState(VK_DOWN))
			{
				if(LevelNumbers[0] == 'X')
				{
					LevelNumbers[0] = ' ';
					LevelNumbers[1] = 'X';
					break;
				}
				if(LevelNumbers[1] == 'X')
				{
					LevelNumbers[1] = ' ';
					LevelNumbers[2] = 'X';
					break;
				}
			}
		}


or the whole drawpath loop
Whole drawing loop. (actually it is better to place sleep between drawing and input handling, or subscribe to the keypress messages and do not use GetAsyncKeyState at all)
Topic archived. No new replies allowed.