-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglob.cpp
37 lines (32 loc) · 932 Bytes
/
glob.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
#include "gamedata.h"
#include "imageFactory.h"
#include "glob.h"
Glob::Glob(std::string& s, Image* globFrame, const Vector2f& pos, const Vector2f& vel) :
Sprite("spitGlob_"+s, pos, vel, globFrame),
owner(s),
distance(0),
maxDistance(Gamedata::getInstance().getXmlInt(owner+"/glob/expireDistance")),
expired(false)
{}
Glob::Glob(const Glob& other) :
Sprite(other),
owner(other.owner),
distance(other.distance),
maxDistance(other.maxDistance),
expired(other.expired)
{}
void Glob::update(Uint32 ticks) {
Vector2f pos = getPosition();
Sprite::update(ticks);
if(getY() < 0 || getY()+getScaledHeight() > worldHeight)
expired = true;
if(getX() < 0 || getX()+getScaledWidth() > worldWidth)
expired = true;
distance += ( hypot(getX()-pos[0], getY()-pos[1]) );
if(distance > maxDistance)
expired = true;
}
void Glob::reset() {
expired = false;
distance = 0;
}