-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobManager.cpp
89 lines (80 loc) · 1.95 KB
/
globManager.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <cmath>
#include "globManager.h"
#include "imageFactory.h"
GlobManager::GlobManager(const std::string& n) :
owner(n),
globImage(ImageFactory::getInstance().getImage(owner+"/glob")),
freeList(),
globList(),
strategy()
{}
GlobManager::GlobManager(const GlobManager& other) :
owner(other.owner),
globImage(other.globImage),
freeList(other.freeList),
globList(other.globList),
strategy(other.strategy)
{}
GlobManager::~GlobManager() {
std::list<Glob*>::iterator globIt = globList.begin();
while(globIt != globList.end()) {
delete *globIt;
globIt++;
}
std::list<Glob*>::iterator freeIt = freeList.begin();
while(freeIt != freeList.end()) {
delete *freeIt;
freeIt++;
}
}
void GlobManager::draw() const {
for( Glob* glob : globList ) {
glob->draw();
}
}
void GlobManager::update(Uint32 ticks) {
std::list<Glob*>::iterator it = globList.begin();
while(it != globList.end()) {
(*it)->update(ticks);
if((*it)->isExpired()) {
freeList.push_back(*it);
it = globList.erase(it);
}
else {
it++;
}
}
}
void GlobManager::shoot(const Vector2f& pos, const Vector2f& vel) {
if(freeList.empty()) {
globList.push_back(new Glob(owner, globImage, pos, vel));
}
else {
Glob* glob = freeList.front();
freeList.pop_front();
glob->reset();
glob->setPosition(pos);
glob->setVelocity(vel);
globList.push_back(glob);
}
}
void GlobManager::reset() {
std::list<Glob*>::iterator it = globList.begin();
while(it != globList.end()) {
freeList.push_back(*it);
it = globList.erase(it);
}
for(Glob* glob : freeList) {
glob->reset();
}
}
/*
bool GlobManager::collided(const Drawable* target) const {
for(Glob* glob : globList) {
if(strategy.execute(*glob, *target))
return true;
}
return false;
}
*/