-
Notifications
You must be signed in to change notification settings - Fork 2
/
demon.cpp
307 lines (289 loc) · 7.7 KB
/
demon.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#include "stdafx.h"
#include "demon.h"
HRESULT demon::init()
{
_state4 = DIDLE;
demonWaitCount = 0;
demonBrassCount = 0;
demonHitCount = 0;
searchCount = 0;
demonAttackRange = 350;
skillFireCount = 0;
tryAttack = false;
isattacking = true;
return S_OK;
}
void demon::update()
{
demonAnimation();
demonLookDirection();
demonAttack();
demonMove();
}
void demon::render(HDC hdc)
{
if ((float)currentHp / maxHp <= 0.8f) {
_hpBar.setGauge(maxHp, currentHp, CAMERA->GetRelativeX(rc.left - 11), CAMERA->GetRelativeY(rc.bottom + 16));
_hpBar.render(hdc);
}
switch (_state4)
{
case DWALK:
IMAGEMANAGER->frameRender("demonWalk", hdc, CAMERA->GetRelativeX(rc.left - 13),
CAMERA->GetRelativeY(rc.top - 10), objFrameX, objFrameY, CAMERA->GetZoom());
break;
case DIDLE:
IMAGEMANAGER->frameRender("demonIdle", hdc, CAMERA->GetRelativeX(rc.left - 13),
CAMERA->GetRelativeY(rc.top - 10), objFrameX, objFrameY, CAMERA->GetZoom());
break;
case DYELL:
IMAGEMANAGER->frameRender("demonYell", hdc, CAMERA->GetRelativeX(rc.left - 13),
CAMERA->GetRelativeY(rc.top - 10), objFrameX, objFrameY, CAMERA->GetZoom());
break;
}
RECT temp;
if (IntersectRect(&temp, &CAMERA->GetCameraRect(), &rc)) {
if (_state4 == DWALK) {
POINT ptCenter = { rc.left + (rc.right - rc.left) / 2 + RANDOM->range(-10, 0), rc.top + (rc.bottom - rc.top) / 2 - RANDOM->range(-1, -6) };
// 발걸음 이펙트
if (_count % 10 == 0) {
float randomScale = RANDOM->range(0.5f, 0.7f);
EFFECTMANAGER->ShowEffectAlphaSize("Walk1", ptCenter, 0.25f, randomScale, 50, 200, true);
}
}
}
}
void demon::demonMove()
{
if (_state4 == DIDLE)
{
if (!checkDestination)
{
searchCount++;
if (searchCount > 1)
{
if (isattacking) {
auto path = ASTAR->pathFinding(_map->GetTiles(), _enemyTilePos, _target->GetPlayerTilePos(), true, true);
//_vDestTileIndex = path;
if (path.size() > 0) {
_vDestTileIndex.push_back(path[0]);
_enemyTilePos = path[0];
checkDestination = true;
_destCount = 0;
}
else {
vector<int> vPossibleDestination;
//동
if (_map->GetTileX(_enemyTilePos) < MAPTILEX - 1 &&
!_map->GetTile(_enemyTilePos + 1).hasUnit &&
_map->GetTile(_enemyTilePos + 1).terrKey == "plaintile") {
vPossibleDestination.push_back(_enemyTilePos + 1);
}
//서
if (_map->GetTileX(_enemyTilePos) > 0 &&
!_map->GetTile(_enemyTilePos - 1).hasUnit &&
_map->GetTile(_enemyTilePos - 1).terrKey == "plaintile") {
vPossibleDestination.push_back(_enemyTilePos - 1);
}
//남
if (_map->GetTileY(_enemyTilePos) < MAPTILEY - 1 &&
!_map->GetTile(_enemyTilePos + MAPTILEX).hasUnit &&
_map->GetTile(_enemyTilePos + MAPTILEX).terrKey == "plaintile") {
vPossibleDestination.push_back(_enemyTilePos + MAPTILEX);
}
//북
if (_map->GetTileX(_enemyTilePos) > 0 &&
!_map->GetTile(_enemyTilePos - MAPTILEX).hasUnit &&
_map->GetTile(_enemyTilePos - MAPTILEX).terrKey == "plaintile") {
vPossibleDestination.push_back(_enemyTilePos - MAPTILEX);
}
if (vPossibleDestination.size() > 0) {
int randDestInd = RANDOM->range(int(vPossibleDestination.size()));
if (vPossibleDestination[randDestInd] > _enemyTilePos) {
isLeft = false;
}
else if (vPossibleDestination[randDestInd] <= _enemyTilePos) {
isLeft = true;
}
_vDestTileIndex.push_back(vPossibleDestination[randDestInd]);
_enemyTilePos = vPossibleDestination[randDestInd];
}
checkDestination = true;
_destCount = 0;
}
}
else {
vector<int> vPossibleDestination;
//동
if (_map->GetTileX(_enemyTilePos) < MAPTILEX - 1 &&
!_map->GetTile(_enemyTilePos + 1).hasUnit &&
_map->GetTile(_enemyTilePos + 1).terrKey == "plaintile") {
vPossibleDestination.push_back(_enemyTilePos + 1);
}
//서
if (_map->GetTileX(_enemyTilePos) > 0 &&
!_map->GetTile(_enemyTilePos - 1).hasUnit &&
_map->GetTile(_enemyTilePos - 1).terrKey == "plaintile") {
vPossibleDestination.push_back(_enemyTilePos - 1);
}
//남
if (_map->GetTileY(_enemyTilePos) < MAPTILEY - 1 &&
!_map->GetTile(_enemyTilePos + MAPTILEX).hasUnit &&
_map->GetTile(_enemyTilePos + MAPTILEX).terrKey == "plaintile") {
vPossibleDestination.push_back(_enemyTilePos + MAPTILEX);
}
//북
if (_map->GetTileX(_enemyTilePos) > 0 &&
!_map->GetTile(_enemyTilePos - MAPTILEX).hasUnit &&
_map->GetTile(_enemyTilePos - MAPTILEX).terrKey == "plaintile") {
vPossibleDestination.push_back(_enemyTilePos - MAPTILEX);
}
if (vPossibleDestination.size() > 0) {
int randDestInd = RANDOM->range(int(vPossibleDestination.size()));
if (vPossibleDestination[randDestInd] > _enemyTilePos) {
isLeft = false;
}
else if (vPossibleDestination[randDestInd] <= _enemyTilePos) {
isLeft = true;
}
_vDestTileIndex.push_back(vPossibleDestination[randDestInd]);
_enemyTilePos = vPossibleDestination[randDestInd];
}
checkDestination = true;
_destCount = 0;
}
}
}
else
{
_state4 = DWALK;
if (_vDestTileIndex.size() > 0)
{
POINT tDestination = { _map->GetTile(_vDestTileIndex[_destCount]).rc.left , _map->GetTile(_vDestTileIndex[_destCount]).rc.top };
if (abs(rc.left - tDestination.x) > enemySpeedX || abs(rc.top - tDestination.y) > enemySpeedY)
{
if (tDestination.x < rc.left)
{
OffsetRect(&rc, -enemySpeedX, 0);
}
else if (tDestination.x > rc.left)
{
OffsetRect(&rc, enemySpeedX, 0);
}
if (tDestination.y > rc.top)
{
OffsetRect(&rc, 0, enemySpeedY);
}
else if (tDestination.y < rc.top)
{
OffsetRect(&rc, 0, -enemySpeedY);
}
}
else
{
_destCount++;
if (_vDestTileIndex.size() <= _destCount)
{
checkDestination = false;
searchCount = 0;
_vDestTileIndex.clear();
}
}
}
}
}
}
void demon::demonAttack()
{
if (!tryAttack)
{
if (abs(_target->rc.left - rc.left) <= demonAttackRange && abs(_target->rc.top - rc.top) <= 30) {
tryAttack = true;
isattacking = true;
}
else
_state4 = DIDLE;
}
else
{
demonWaitCount++;
if (demonWaitCount > 23)
{
_state4 = DYELL;
demonBrassFire();
}
else
_state4 = DIDLE;
}
}
void demon::demonAnimation()
{
switch (_state4)
{
case DWALK:
objFrameY = (isLeft) ? 1 : 0;
objFrameX = _index;
if (_count++ % 10 == 0)
{
if (_index++ > 11)
_index = 0;
}
break;
break;
case DIDLE:
objFrameY = (isLeft) ? 1 : 0;
objFrameX = _index;
if (_count++ % 10 == 0)
{
if (_index++ > 4)
_index = 0;
}
break;
case DYELL:
objFrameY = (isLeft) ? 1 : 0;
objFrameX = _index;
if (_count++ % 15 == 0)
{
if (_index++ > 10)
{
_index = 0;
demonWaitCount = 0;
demonHitCount = 1;
tryAttack = false;
_attackIndex = 0;
searchCount = 0;
checkDestination = false;
isattacking = true;
_state4 = DWALK;
}
}
break;
}
}
void demon::demonLookDirection()
{
if (_state4 == DIDLE || _state4 == DWALK)
{
if (rc.right > _target->rc.right && rc.left > _target->rc.left)
isLeft = true;
else
isLeft = false;
}
}
void demon::demonBrassFire()
{
skillFireCount++;
if (skillFireCount % 200 == 0) {
SOUNDMANAGER->play("악마불지질때소리");
_count = 0;
_index = 0;
for (int i = 0; i < 2; i++)
{
if(isLeft)
UNITMANAGER->GetProjectileMG()->CreateProjectile("demonBrass", GetCenterX() - 320, GetCenterY() - 40, atk, 320, 40, isLeft);
else
UNITMANAGER->GetProjectileMG()->CreateProjectile("demonBrass", GetCenterX(), GetCenterY() - 40, atk, 320, 40, isLeft);
}
skillFireCount = 0;
}
}