Do 2 functions at the same time

Hy,i want to recreate a game,it was with a ball,that you had to hit a horizontal stick(kind of stick) and then the ball hit the vertical surface and bounced off.. The main problem is that the ball was moving while you could move the stick..How can i do 2 actions at the same time in c++?
People may give you overly literal answers to your question, but you almost certainly don't actually need to do two things at the same time.
You only need to make it look like you are doing two things at the same time.

Move the ball just a tiny little bit, maybe based off of the amount of time passed since the last time you moved the ball.
Then move the stick just a little bit according to the same criteria.
Then, update what is shown on the screen.
Repeat until you quit the game.

This process happens very quickly. Move this, move that, show it. Move this, move that, show it.

You will find a similar process in essentially every kind of interactive software. It's called a main-loop, or in the case of games, a game-loop. Each iteration of this main loop - each update - is often called a "tick".
To add to mbozzi's answer, I offer this analogy.

Imagine that you're making a claymation movie. To prepare a frame of animation you set up the scene and press the shoot button on your camera.
Now imagine that you have a scene where two characters are performing tasks independently of each other. You don't need to actually move both characters simultaneously while you're preparing the shot. You can move one character and then the other, and then take the shot. The camera is only taking a snapshot of an instant of the action, so it doesn't care how you position the characters for the shot, it only cares about their positions at the time the shot is taken.

The exact same thing happens when a single frame in a video game is rendered.
Topic archived. No new replies allowed.