Running two loops at the same time ? moving and traveling using loops.

Hi, I am creating a game where there are two spaceships shooting each other. I currently succeeded making the first spaceship move by using a while loop and the GetASyncKeyState function. but now I am making the bullets travel. Currently I though of using for loop, and I did succeed in making the bullet travel upward. But there's a problem, I can't move the spaceship until the bullet travels or the for loop stop. is there a way to both run the for loop and while at the same time ? or to run two function at a time

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  void GameMovements()
{
	bool FirstInitialization = true;
	int Player1XCoordinate = 55, Player2XCoordinate = 55;
	int Player1YCoordinateU = 28, Player1YCoordinateD = 29;


	while (true)
	{
		BulletPattern(Player1XCoordinate);

		if (FirstInitialization == true)
		{
			GameBorderAndStatus();
			SetCoordinate(Player1XCoordinate, Player1YCoordinateU);
			cout << "   ^  \n";
			SetCoordinate(Player1XCoordinate, Player1YCoordinateD);
			cout << "^==|==^ \n";
			FirstInitialization = false;
		}

		//MOVEMENTS FOR PLAYER 1
		else if (GetAsyncKeyState(VK_LEFT) && Player1XCoordinate != 16)
		{
			system("cls");
			GameBorderAndStatus();

			Sleep(10);
			Player1XCoordinate -= 3;
			SetCoordinate(Player1XCoordinate, Player1YCoordinateU);
			cout << "   ^  \n";
			SetCoordinate(Player1XCoordinate, Player1YCoordinateD);
			cout << "^==|==^ \n";
		}
		else if (GetAsyncKeyState(VK_RIGHT) && Player1XCoordinate != 94)
		{
			system("cls");
			GameBorderAndStatus();
			Player1XCoordinate += 3;

			Sleep(10);
			SetCoordinate(Player1XCoordinate, Player1YCoordinateU);
			cout << "   ^  \n";
			SetCoordinate(Player1XCoordinate, Player1YCoordinateD);
			cout << "^==|==^ \n";
		}
		else if (GetAsyncKeyState(VK_UP) && Player1YCoordinateU != 24)
		{
			system("cls");
			GameBorderAndStatus();
			Player1YCoordinateU -= 2;
			Player1YCoordinateD -= 2;

			Sleep(10);
			SetCoordinate(Player1XCoordinate, Player1YCoordinateU);
			cout << "   ^  \n";
			SetCoordinate(Player1XCoordinate, Player1YCoordinateD);
			cout << "^==|==^ \n";
		}
		else if (GetAsyncKeyState(VK_DOWN) && Player1YCoordinateU != 28)
		{
			system("cls");
			GameBorderAndStatus();
			Player1YCoordinateU += 2;
			Player1YCoordinateD += 2;

			Sleep(10);
			SetCoordinate(Player1XCoordinate, Player1YCoordinateU);
			cout << "   ^  \n";
			SetCoordinate(Player1XCoordinate, Player1YCoordinateD);
			cout << "^==|==^ \n";
		}

	}
}

void BulletPattern(int Player1MuzzleLocation)
{
	for (int i = 25; i != 3; i--)
	{
		Sleep(10);
		SetCoordinate(Player1MuzzleLocation + 3, i);

	}
}
Think more carefully about what you need to do. You don't really need to run two loops at the same time. What you really need to do is progressively change two variables over a period of time. Think about how you'd do that.
Already did, thanks anyway :)
Topic archived. No new replies allowed.