-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCLayer.cpp
More file actions
43 lines (38 loc) · 1.02 KB
/
CLayer.cpp
File metadata and controls
43 lines (38 loc) · 1.02 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "CLayer.h"
CLayer::CLayer(std::vector<CEntity*> entities)
{
for (std::vector<CEntity*>::iterator itr = entities.begin(); itr != entities.end(); itr++)
_entities.insert(std::make_pair((*itr)->name(), *itr));
}
CLayer::~CLayer()
{
for (entityListing::iterator itr = _entities.begin(); itr != _entities.end(); itr++)
{
if (itr->second != nullptr)
{
delete (itr->second);
itr->second = nullptr;
}
}
_entities.clear();
for (std::vector<CHitBox*>::iterator itr = _hitBoxes.begin(); itr != _hitBoxes.end(); itr++)
{
if ((*itr) != nullptr)
{
delete (*itr);
(*itr) = nullptr;
}
}
_hitBoxes.clear();
}
CEntity & CLayer::getEntity(std::string name)
{
return *(_entities[name]);
}
void CLayer::_checkCollisions()
{
for (std::vector<CHitBox*>::iterator outter = _hitBoxes.begin(); outter != _hitBoxes.end(); outter++)
for (std::vector<CHitBox*>::iterator inner = outter + 1; inner != _hitBoxes.end(); inner++)
if ((*outter)->checkCollision(*(*inner)))
(*outter)->addCollision((*inner)->entity);
}