2D Tank Game.

Hello, I am looking to make a type of tank game in C++, The main idea of the game is simple, kill the enemy using the angles you input in the program. For example, if the enemy is placed at the distance of 42, you put in the angle for your bullet to shoot at the opponent and it calculates wherever you hit or missed the opponent.
I got some equations that helps and i included it in my program but I need that tiny push to do 2 things in my code.

1. I need to make an enemy and make him big enough for me to hit him rather than just 1 co-ordinate,

2. I need the formula to actually shoot at the enemy, It needs to include gravity and have a motion to shoot.

Thank you.

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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
void game(void)
{
	char choiceb;

	int exit_1=0;
	do
	{
		system("cls");
		cout << "\n Game will begin...";
		Sleep(1000);
		cout << "\n There is a very mild wind (2.0 miles an hour)";
		Sleep(5000);
		cout << "\n You place yourself in a very cold tank, preparing to face the enemy. ";
		Sleep(2500);
		cout << "\n Good Luck.";
		Sleep(500);
		//cin >> choiceb;


		//Game Start here 
		// F= m A




		double angle;
		int DistanceCalc (double in_angle);
		float radians;
		float distance;
		int maxrange;


		Sleep (1000);
		cout << "\n You have spotted your enemy..";
		Sleep(500);
		cout << "\n You have loaded 5 bullets in your Tank";
		Sleep(500);





		//Placing a Random Enemy on the map to kill.


		int enemy_position_x; 
		int enemy_position_y; 
		//int enemy_position;
		int r; //random

		//Generate Random number between Distance Minimum -- Distance Maximum


		// F = mA 
		// Force = Mass * Acceleration
		// A = F
		// V += A * dt
		
	
		
		float time = 1/60;
		const float mass = 1;
		const float force = 1000;
		const float acceleration = 20; 
		float directionx;
		float directiony;
		float velocity = 1;
		int distance = 3.5;
		
		directionx = cos(angle) * 1000;
		directiony = sin(angle) * 1000;
		velocity = acceleration * distance * time;

	
		//hit:



		//(enemy_position - distance <=1);
		if (hit == true) //true
		{
			//enemy_killed++;
			Sleep (500);
			cout << "\n He is hit, he is hit! Target down";
			Sleep (500);
			cout << "\n I see another target, would you like to face him? (Y/N)" <<endl;


			cin >> choiceb;

			int loop_on = 1;
			switch (choiceb)
			{

			case 'y': 

			case 'Y':
				cout << "\n Start again!";
				loop_on=1;
				break;

			case 'n': 

			case 'N':
				cout << "\n Coward! See you soon!";
				loop_on=0;
				break;



			default :
				cout << "\n Invalid Input" <<endl;
				break;

				while (loop_on == 1);

			}

		}

		{

		}
		while ((NumberOfShots >0));
		//if (NumberofShots == 0)
		//	cout << "\n You have run out of ammunition and the enemy kills you" <<endl;
		////return player_killed;


	}
	while(exit_1 == 0);


}
Topic archived. No new replies allowed.