-
Notifications
You must be signed in to change notification settings - Fork 0
/
flame.cpp
52 lines (48 loc) · 1.72 KB
/
flame.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
#include <iostream>
#include <cmath>
#include "flame.h"
Flame::Flame(const string& n,const string& no) :
SingleFrameSprite(n,no,
Vector2f(Gamedata::getInstance()->getXmlInt(n+no+"X"),
Gamedata::getInstance()->getXmlInt(n+no+"Y")),
Vector2f(Gamedata::getInstance()->getXmlInt(n+no+"Xspeed"),
Gamedata::getInstance()->getXmlInt(n+no+"Yspeed"))),
frame(FrameFactory::getInstance().getFrame(n,"")[0]),
Xi(Gamedata::getInstance()->getXmlInt(n+no+"X"))
{ setFrame(frame); }
Flame::Flame(const Flame& s) :
SingleFrameSprite(s.getName(),s.getNumber(),s.getPosition(),s.getVelocity()),
frame(s.frame),
Xi(s.Xi)
{ }
Flame& Flame::operator=(const Flame& rhs) {
setName( rhs.getName() );
setPosition(rhs.getPosition());
setVelocity(rhs.getVelocity());
setMaxVelocity(rhs.getMaxVelocity());
setDirection(rhs.getDirection());
setFrame(rhs.getFrame());
frame = rhs.frame;
Xi = rhs.Xi;
return *this;
}
void Flame::update(Uint32 ticks) {
uint8_t controls = getControls();
if(controls==0xff){
std::cout<< "i will never die soon --- "<<getName()<<std::endl;
setControls(0x00);
}
else{
float incr = velocityX() * static_cast<float>(ticks) * 0.001;
X( X()+incr );
if((Xi-X())>(Gamedata::getInstance()->getXmlFloat(getName()+"Distance")/2) || (X()-Xi+Gamedata::getInstance()->getXmlFloat(getName()+"Width"))>(Gamedata::getInstance()->getXmlFloat(getName()+"Distance")/2)){
if(velocityX()>0){
X(Xi+(Gamedata::getInstance()->getXmlFloat(getName()+"Distance"))/2-Gamedata::getInstance()->getXmlFloat(getName()+"Width")-1);
}
if(velocityX()<0){
X(Xi-Gamedata::getInstance()->getXmlFloat(getName()+"Distance")/2+1);
}
velocityX(-velocityX());
}
}
}