Implementing the bouncing ball scene
Task introduction
The task set for this exercise was to implement two scenes, a checkerboard and a bouncing ball scene using the Game Programming framework provided in the lecture slides.
Purpose
The purpose of this post is to reflect on the debugging process that took place to fix the problems I was facing. After implementing the base game programming frame work from the lecture slides, I was able to then implement the bouncing ball scene however, just like the checkerboard scene there were some bugs.
Debugging
After I had implemented all the required classes for the bouncing ball scene and switched the current rendered sceen to the bouncing ball one this is what I recieved.
A blank screen, this was similar to the checkerboard scene so I double tripple checked my code again and this time was confident that nothing was wrong with my code.
After trying to debug this probelm for an hour or two I finally realized that the bug exists due to a boolean variable stored within each ball. This can be seen in the screenshot below:
Notice the variable named m_bAlive? It hasn't been set and defaulted to false. Well guess what the code that draws the ball checks? That's right, it checks if the ball is alive or not.
The fix
While finding this bug took quite some time, it was a relatively easy fix. All I needed to do was to make sure to set the m_bAlive variable for each ball to true when it was initialized.
After setting the variable to true I was presented with the scene that I had been trying to achieve, bouncing balls.
You'll just have to trust me that these balls were bouncing around the screen :D. I also decided that the size of the balls were too big and decided to reduce it further to better fix the window.