Applying the update method for prototyping gameplay
The update method is all about abstraction. Let’s learn through an example. Imagine building a Pong clone with only rudimentary knowledge of C++. It might look something like this:
Naïve Pong code
Entity aiPaddle; Entity ball; Vector2D direction; // Main game loop while (looping) { Vector2D ballPos = ball.GetPosition(); ballPos += direction; ball.SetPosition(ballPos); if (ballPos.y > aiPaddle.GetPosition().y) { aiPaddle.MoveUp(); } else { aiPaddle.MoveDown(); } // Input, collisions, and rendering... }
This code may work for Pong but the problem is pretty clear. As you add more and...