-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoss.cpp
More file actions
139 lines (129 loc) · 3.45 KB
/
Boss.cpp
File metadata and controls
139 lines (129 loc) · 3.45 KB
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
134
135
136
137
138
139
#include "Boss.hpp"
#include "Projectile.hpp"
Boss::Boss(int posX, int posY, char drawingChar, int speed, int hp, int damage, int attackSpeed) :
Enemy(posX, posY, drawingChar, speed, false, hp, damage, attackSpeed, 0), _up(false), _fire(false), _die(false)
{
}
Boss::Boss(void) {
return;
}
Boss::Boss(Boss const &src) {
*this = src;
return;
}
Boss::~Boss(void) {
Game::Instance->BossDeath();
}
Boss &Boss::operator=(Boss const &rhs) {
if (this != &rhs) {
}
return *this;
}
void Boss::TakeDamage(int damage)
{
this->_hp -= damage;
if (this->_hp <= 0 && !this->_die)
{
Game::Instance->AddScore(this->_maxHp);
this->_damage += 1000;
this->_die = true;
}
}
void Boss::Shoot()
{
if (this->_frameCount % this->_attackSpeed == 0 && this->_fire)
{
Projectile *proj = new Projectile(this->_posX - 19, this->_posY + 2, '-', 2, false, false, this->_damage, 0);
Game::Instance->AddEntity(proj);
proj = new Projectile(this->_posX - 19, this->_posY + 3, '-', 2, false, false, this->_damage, 0);
Game::Instance->AddEntity(proj);
proj = new Projectile(this->_posX - 19, this->_posY + 4, '-', 2, false, false, this->_damage, 0);
Game::Instance->AddEntity(proj);
}
if (this->_frameCount % this->_attackSpeed == 0)
{
if (this->_hp <= this->_maxHp / 2)
{
Projectile *proj = new Projectile(this->_posX - 19, this->_posY + 3, '/', 5, false, false, this->_damage, 1);
Game::Instance->AddEntity(proj);
proj = new Projectile(this->_posX - 19, this->_posY + 3, '\\', 5, false, false, this->_damage, -1);
Game::Instance->AddEntity(proj);
}
if (this->_hp <= this->_maxHp / 4)
{
Projectile *proj = new Projectile(this->_posX - 15, this->_posY + 5, '/', 5, false, false, this->_damage, 1);
Game::Instance->AddEntity(proj);
proj = new Projectile(this->_posX - 15, this->_posY, '\\', 5, false, false, this->_damage, -1);
Game::Instance->AddEntity(proj);
}
if (this->_hp <= this->_maxHp / 4 && this->_fire)
{
Projectile *proj = new Projectile(this->_posX - 19, this->_posY + 1, '-', 2, false, false, this->_damage, 0);
Game::Instance->AddEntity(proj);
proj = new Projectile(this->_posX - 19, this->_posY + 5, '-', 2, false, false, this->_damage, 0);
Game::Instance->AddEntity(proj);
}
if (this->_hp <= this->_maxHp / 8 && this->_fire)
{
Projectile *proj = new Projectile(this->_posX - 19, this->_posY, '-', 2, false, false, this->_damage, 0);
Game::Instance->AddEntity(proj);
proj = new Projectile(this->_posX - 19, this->_posY + 6, '-', 2, false, false, this->_damage, 0);
Game::Instance->AddEntity(proj);
}
}
}
void Boss::Update()
{
if (this->_die)
{
this->_oldX = this->_posX;
this->_posX--;
}
else
{
this->_frameCount++;
this->Shoot();
if (this->_frameCount % 75 == 0)
this->_fire = true;
if (this->_frameCount % 300 == 0)
this->_fire = false;
if (this->_frameCount % this->_speed == 0)
{
this->_oldX = this->_posX;
this->_oldY = this->_posY;
if (this->_up)
{
if (this->_posY > 1)
{
this->_posY--;
}
else
{
this->_up = false;
}
}
else
{
if (this->_posY < Display::sizeY - 8)
{
this->_posY++;
}
else
{
this->_up = true;
}
}
}
}
if (Display::IsInMap(this->_posX, this->_posY))
{
Display::Erase(this->_oldX, this->_oldY);
Display::PutChar(_drawingChar, this->_posX, this->_posY);
Entity::Update();
}
else
{
Display::Erase(this->_oldX, this->_oldY);
Game::Instance->RemoveEntity(this);
}
}