O'Reilly logo

Beginning C++ Game Programming by John Horton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Moving the clouds and the bee

Let's use the elapsed time since the last frame, to breathe life into the bee and the clouds. This will solve the problem of having a consistent frame rate across different PCs.

Giving life to the bee

The first thing we want to do is to set up the bee at a certain height and a certain speed. We only want to do this when the bee is inactive. So we wrap the next code in an if block. Examine and add the highlighted code, then we will discuss it:

/* 
**************************************** 
Update the scene 
**************************************** 
*/ 
 
// Measure time 
Time dt = clock.restart(); 
 
// Setup the bee if (!beeActive) { // How fast is the bee srand((int)time(0)); beeSpeed = (rand() % 200) + 200; // How high is the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required