-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemyFinal1.cpp
96 lines (86 loc) · 2.91 KB
/
enemyFinal1.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
90
91
92
93
94
95
96
#include <iostream>
#include <cmath>
#include "enemyFinal1.h"
#include "sound.h"
EnemyFinal1::EnemyFinal1(const string& n,const string& no) :
MultiFrameSprite(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"))),
strength(Gamedata::getInstance()->getXmlInt(n+"Strength")),
dt(0),
bulletDirection(Vector2f(0,0)),
power("enemyFinal"),
offset("Offset"),
rnormal(FrameFactory::getInstance().getFrame(n,"RNormal")),
enemyFrame(FrameFactory::getInstance().getFrame("enemyFinal1Frame","")[0])
{
setFrameVector(rnormal);
}
EnemyFinal1::EnemyFinal1(const EnemyFinal1& s) :
MultiFrameSprite(s.getName(),s.getNumber(),s.getPosition(),s.getVelocity()),
strength(s.strength),
dt(s.dt),
bulletDirection(s.bulletDirection),
power(s.power),
offset(s.offset),
rnormal(s.rnormal),
enemyFrame(s.enemyFrame)
{ }
EnemyFinal1& EnemyFinal1::operator=(const EnemyFinal1& rhs) {
setName( rhs.getName() );
setPosition(rhs.getPosition());
setVelocity(rhs.getVelocity());
setMaxVelocity(rhs.getMaxVelocity());
currentFrame(rhs.currentFrame());
change(rhs.change());
setDirection(rhs.getDirection());
power = rhs.power;
offset = rhs.offset;
strength = rhs.strength;
dt = rhs.dt;
bulletDirection = rhs.bulletDirection;
setFrameVector(rhs.getFrameVector());
rnormal = rhs.rnormal;
enemyFrame = rhs.enemyFrame;
return *this;
}
void EnemyFinal1::update(Uint32 ticks){
uint8_t controls = getControls();
if(controls==0xff){
if(--strength==0){
std::cout<< "i will die soon --- "<<getName()<<std::endl;
}
else{
setControls(0x00);
}
}
else{
Vector2f location;
location = Location();
advanceFrame(ticks, 600.0, "RNormal");
bulletDirection = Vector2f(-cos((location[1]/360.0)*3.14),-sin((location[1]/360.0)*3.14));
//fire(power,offset);
float ms =1* (Gamedata::getInstance()->getXmlInt("enemyDistance"))/((Gamedata::getInstance()->getXmlInt(power+"NumberOfBullets"))*(Gamedata::getInstance()->getXmlInt(power+"Xspeed")));
dt += ticks;
int df = dt/ms;
dt -= df*ms;
if(df >= 1){
fire(power,offset);
//SDLSound::getInstance()["gun"];
}
}
}
void EnemyFinal1::draw() const {
Uint32 x = static_cast<Uint32>(X());
Uint32 y = static_cast<Uint32>(Y());
enemyFrame->draw(7456,95);
rnormal[currFrame]->draw(x, y - rnormal[currFrame]->getHeight());
}
void EnemyFinal1::fire(string& power,string& offset){
Bullets::getInstance().add(new Bullet(power,"",Vector2f(X()+Gamedata::getInstance()->getXmlInt(getName()+offset+"X"),
Y()+Gamedata::getInstance()->getXmlInt(getName()+offset+"Y")),
Vector2f(Gamedata::getInstance()->getXmlInt("redorbXspeed")*bulletDirection[0],
Gamedata::getInstance()->getXmlInt("redorbYspeed")*bulletDirection[1])));
}