-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollisionManager.cpp
More file actions
25 lines (23 loc) · 1.01 KB
/
Copy pathCollisionManager.cpp
File metadata and controls
25 lines (23 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "CollisionManager.h"
void CollisionManager::checkCollisions(QGraphicsScene* scene, Player* player) {
const auto& collisions = scene->collidingItems(player);
for (auto thing : scene->collidingItems(player)) {
auto linePtr = dynamic_cast<QGraphicsLineItem*>(thing);
if (linePtr != nullptr) {
player->manageLineCollision(linePtr);
} else if (dynamic_cast<Enemy*>(thing) != nullptr) {
player->loseHp();
}
}
}
void CollisionManager::checkEnemyCollisions(QGraphicsScene* scene, Enemy* enemy) {
const auto& collisions = scene->collidingItems(enemy);
for (auto thing : scene->collidingItems(enemy)) {
auto linePtr = dynamic_cast<QGraphicsLineItem*>(thing);
if (linePtr != nullptr) {
enemy->manageLineCollision(linePtr);
} else if (dynamic_cast<Weapon*>(thing) != nullptr || dynamic_cast<VerticalWeapon*>(thing) != nullptr || dynamic_cast<RightWeapon*>(thing) != nullptr) {
enemy->loseHp();
}
}
}