They asked to write a program for the game in the console.

The task itself : The gun has a fixed position on the screen, the X coordinate of the target is set from the terminal, the angle a is also set - the slope of the tangent to the ballistic curve at the starting point (the angle of the tool) and the initial velocity of the projectile V0. During the game you need to choose a value of the initial velocity, so that the projectile hit the target. It is necessary to sequentially display on the screen all phases of the projectile movement (with the necessary delays), and at each subsequent time point it is necessary to erase the previous projectile position by outputting a point to this place (thus, the projectile’s trajectory will remain on the screen).

I am at a dead end, I do not know where to start. I wrote only the menu.

  • So on pure C or C ++? - gecube
  • Clean C - dizznt
  • You ask how to organize the process itself or how to do it all by software? ... and also, do you need to erase it or NOT? if there is a need for a trajectory, there will be a current projectile to move, and if you don’t erase, then a trace will remain - your trajectory of movement ... otherwise it’s not clear what is written at the end ... - Leshij_2005
  • How the code will look, where to start. And instead of a projectile should remain the trajectory in the form of points. - dizznt

4 answers 4

I propose to begin to calculate the array of coordinates of the projectile - that is, trajectory. Simply enumerate all the values ​​of x in the required order and get for them the corresponding y knowing the velocity vector V. Approximately like this:

int nframe = 0; for(x = x0; x < krai_ekrana; ++x) { tochka_traektorii[nframe].x = x; tochka_traektorii[nframe].y = y + Vy * (x - x0) / Vx; ++nframe; if(x == celi.x && y == celi.y) // дальше считать смысла нет break; } 

and then in a cycle to display them ... with pauses ...

Added: not taken into account physics. Apparently, you will need to replace the above formula for y, or rather, add a change to Vy:

 y = y + Vy * (1 / Vx); Vy = Vy + Gy * (1 / Vx); 

where Gy is the acceleration of the "free fall" of the projectile - only along the y axis ... You can summarize, derive formulas for an arbitrarily directed vector G - then Vx will also change ..

  • Added a change in physics ... - gote

Start by drawing in pencil on paper screens (with menus) that the player will see and descriptions of the sequence of his actions (buttons, mouse) leading to image changes. Imagine the dynamics (actually in fractions of a second) of an image of a shot and a projectile flight.

For good, you can then complicate the physical model by entering air resistance, etc.

    Create the equation of motion of the projectile as a function of X (a; V0; t) Y (a; V0; t). Program, get numerical solutions. How to draw it on the screen - the second stage and not too difficult

      One approach is to write the vector <coordinates> GetPosition (time) function, which will return the vector of pairs (time, coordinate), then display these coordinates in the console. The time parameter - with what accuracy to count (seconds, milliseconds, etc.).

      Another approach is a little more difficult - to set a timer, call the coordinate calculation function by a timer, and draw a point on the screen, which it returns.