Pong power ups

I just finished my Pong game and now I would like to add some power ups. I would like for some of them to be active for only a certain amount of seconds (fx. the ball moving faster for 20 seconds).

I’m not sure how to go about it. Should I make a thread for it? Is that what “multi-threading” is? I’ve heard about it, but I’m not sure what it is, so please explain! :slight_smile:

This does not sound like a reason to use threads.

Threads are basically a way to make the computer do two things at once- in reality, the computer is simply switching between two different things. An example would be loading a file while updating a progress bar- one thread would load the file, another thread would draw the progress bar.

Most games use a single game loop thread, that way they don’t have to worry about a bunch of synchronization.

One approach to your problem would be to simply store the “start” time of and temporary objects, then remove them when the elapsed time exceeds the time limit. No need for threads there.

No, no threads in your game loop.

You just add a counter that is decreased at each iteration, until it reaches 0. Something like:


long powerUpCount = 20*1000; //miliseconds

private loop (long deltaT)
{
...
powerUpCount = powerUpCount - deltaT;
if (powerUpCount >0)
 applyPowerUp();
...
}

Where deltaT is the time passed from the last iteration.

I see. Thank you!