Hi. So I am a complete beginner with Qt. I am tasked to make a Plant vs. Zombie esque game from my professor and I am at complete loss about the collision detection.

I have been doing Google searches everywhere regarding the use of Qt Timeline, GraphicsItem, GraphicsScene for collision handling and I gave up.

A short description about my game: There are three sprites on the playing field: Towers, Cannonballs and Mobs. Towers are placed by player to guard the left side of the screen and mobs appear from the right side of the screen. Towers constantly fire cannonballs every few seconds.

Qt Code:
  1. cannonball::cannonball()
  2. {
  3. QTimeLine * timer = new QTimeLine(4000);
  4.  
  5. animation->setItem(this);
  6. animation->setTimeLine(timer);
  7.  
  8. timer->setLoopCount(0);
  9.  
  10. for (int i = this->pos().x(); i < 640; ++i)
  11. {
  12. animation->setPosAt(i / 640.0, QPointF(i, this->pos().y() ));
  13. if (hits_enemy())
  14. timer->setCurrentTime(0);
  15. }
  16.  
  17. timer->start();
  18. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. bool cannonball::hits_enemy()
  2. {
  3. for (int i=0; i<this->collidingItems().count(); i++)
  4. if (qgraphicsitem_cast<mobs*>(this->collidingItems()[i]) ) return true;
  5.  
  6. return false;
  7. }
To copy to clipboard, switch view to plain text mode 

Basically, those are some codes from the cannonball class.

I would like the cannonball upon collision to a mob sprite to disappear, damage the mob and fire again once the cooldown cleared.

I am pretty desperate right now as I have been looking for similar solutions for over 6 hours with no solid result. Please help!