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.
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;
constfloat mass = 1;
constfloat force = 1000;
constfloat 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);
}