Game Programming using Qt 5 Beginner's Guide - Second Edition
by Pavel Strakhov, Witold Wysota, Lorenz Haas
What just happened?
First, we call the scene's QGraphicsScene::collidingItems() function, which takes the item for which colliding items should be detected as a first argument. With the second, optional argument, you can define how the collision should be detected. The type of that argument is Qt::ItemSelectionMode, which was explained earlier. By default, an item will be considered colliding with m_player if the shapes of the two items intersect.
Next, we loop through the list of found items and check whether the current item is a Coin object. This is done by trying to cast the pointer to Coin. If it is successful, we explode the coin by calling explode(). Calling the explode() function multiple times is no problem, since it will not allow ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access