/
Agent47.cpp
133 lines (123 loc) · 3.54 KB
/
Agent47.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "Agent47.h"
Agent47::Agent47(Game *cipher)
{
Qcomponent = new Agent47QComponent(cipher);
Wcomponent = new Agent47WComponent(cipher);
Ecomponent = new Agent47EComponent(cipher);
//Rcomponent = new Agent47RComponent();
Q_CoolDown = Agent47NS::QSkillCD;
W_CoolDown = Agent47NS::WSkillCD;
E_CoolDown = Agent47NS::ESkillCD;
if (!characterTexture.initialize(cipher->getGraphics(), AGENT47_IMAGE))
throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing Player texture"));
if (!this->initialize(cipher, charactersNS::WIDTH, charactersNS::HEIGHT, Agent47NS::TEXTURE_COLS, &characterTexture))
throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing player"));
currentFrame = startFrame;
startFrame = Agent47NS::AGENT_START_FRAME; // first frame of ship animation
endFrame = Agent47NS::AGENT_END_FRAME; // last frame of ship animation
}
bool Agent47::initialize(Game *gamePtr, int width, int height, int ncols, TextureManager *textureM)
{
return(Entity::initialize(gamePtr, width, height, ncols, textureM));
}
void Agent47::draw()
{
Image::draw(); // draw ship
Qcomponent->draw();
Wcomponent->draw();
//Ecomponent->draw();
//Rcomponent->draw();
}
void Agent47::skillUpdate(float frameTime)
{
Qcomponent->update(frameTime);
Wcomponent->update(frameTime);
float speedbuff = Ecomponent->update(frameTime);
VECTOR2 vel;
if (facingRight)
{
if (this->getMoveComponent()->getVelocity().x <= 150 && this->getMoveComponent()->getVelocity().x >= -150)
{
vel.x = this->getMoveComponent()->getVelocity().x + speedbuff;
vel.y = this->getMoveComponent()->getVelocity().y;
this->getMoveComponent()->setVelocity(vel);
}
}
else
{
if (this->getMoveComponent()->getVelocity().x <= 150 && this->getMoveComponent()->getVelocity().x >= -150)
{
vel.x = this->getMoveComponent()->getVelocity().x - speedbuff;
vel.y = this->getMoveComponent()->getVelocity().y;
this->getMoveComponent()->setVelocity(vel);
}
}
//Rcomponent->update(frameTime);
}
void Agent47::resetSkill(std::string letter)
{
if (letter == "Q")
{
Q_CoolDown = Agent47NS::QSkillCD;
Q_on_CoolDown = false;
}
else if (letter == "W")
{
W_CoolDown = Agent47NS::WSkillCD;
W_on_CoolDown = false;
}
else if (letter == "E")
{
E_CoolDown = Agent47NS::ESkillCD;
E_on_CoolDown = false;
}
else if (letter == "ALL")
{
Q_CoolDown = Agent47NS::QSkillCD;
W_CoolDown = Agent47NS::WSkillCD;
E_CoolDown = Agent47NS::ESkillCD;
Q_on_CoolDown = false;
W_on_CoolDown = false;
E_on_CoolDown = false;
}
}
void Agent47::useQ(bool facingRight, VECTOR2 center, Game *cipher)
{
if (facingRight)
{
float punchX = center.x + spriteData.width / 2;
float punchY = center.y - spriteData.height / 4;
Qcomponent->activate(facingRight, punchX, punchY, cipher);
}
else if (!facingRight)
{
float punchX = center.x - spriteData.width / 2;
float punchY = center.y - spriteData.height / 4;
Qcomponent->activate(facingRight, punchX, punchY, cipher);
}
Q_on_CoolDown = true;
}
void Agent47::useW(bool facingRight, VECTOR2 center, Game *cipher)
{
if (facingRight)
{
float zapX = center.x + spriteData.width / 2;
float zapY = center.y - spriteData.height / 4;
Wcomponent->activate(facingRight, zapX, zapY, cipher);
}
else if (!facingRight)
{
float zapX = center.x - spriteData.width / 2;
float zapY = center.y - spriteData.height / 4;
Wcomponent->activate(facingRight, zapX, zapY, cipher);
}
W_on_CoolDown = true;
}
void Agent47::useE(bool facingRight, VECTOR2 center, Game *cipher)
{
Ecomponent->activate();
E_on_CoolDown = true;
}
void Agent47::useR()
{
}