-
Notifications
You must be signed in to change notification settings - Fork 2
/
ProjectileManager.cpp
281 lines (240 loc) · 8.21 KB
/
ProjectileManager.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
#include "stdafx.h"
#include "ProjectileManager.h"
void ProjectileManager::init()
{
IMAGEMANAGER->addImage("BowArrow", "Images/이미지/아이템/img_UI_bowArrow.bmp", 56, 56, true, RGB(255, 0, 255));
IMAGEMANAGER->findImage("BowArrow")->initForRotateImage(false);
IMAGEMANAGER->addFrameImage("wratihMissile", "Images/이미지/NPC/wratihMissile.bmp", 990, 90, 11, 1, true, RGB(255, 0, 255));
IMAGEMANAGER->addFrameImage("demonBrass", "Images/이미지/NPC/firebrass.bmp", 2560, 180, 8, 2, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("slimeMissile", "Images/이미지/NPC/slime_bullet.bmp", 30, 30, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("slimeBossMissile", "Images/이미지/NPC/red_bullet.bmp", 30, 30, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("smallMuMissile", "Images/이미지/NPC/seed.bmp", 30, 30, true, RGB(255, 0, 255));
//IMAGEMANAGER->addFrameImage("muMissile", "Images/이미지/NPC/baby_mu.bmp", 198, 45, 6, 1, true, RGB(255, 0, 255));
for (int i = 0; i < PROJECTILE_MAX; i++) {
_projectiles[i].imgKey = "temp";
_projectiles[i].x = 0;
_projectiles[i].y = 0;
_projectiles[i].angle = 0.0f;
_projectiles[i].damage = 0;
_projectiles[i].frameX = 0;
_projectiles[i].frameY = 0;
_projectiles[i].isAppear = false;
_projectiles[i].isEnemyProjectTile = false;
_projectiles[i].isStretch = false;
_projectiles[i].isBrassing = false;
_projectiles[i].speed = 0;
_projectiles[i].count = 0;
_projectiles[i].brassCount = 0;
_projectiles[i]._playerTargetRc = nullptr;
_projectiles[i].isFollowing = false;
}
}
void ProjectileManager::release()
{
for (int i = 0; i < PROJECTILE_MAX; i++) {
_projectiles[i].isAppear = false;
}
}
void ProjectileManager::update()
{
for (int i = 0; i < PROJECTILE_MAX; i++) {
if (_projectiles[i].isAppear)
{
//해당 투사체가 isFollowing인 경우,
if (_projectiles[i].isFollowing) {
float targetAngle = shootToTarget(i);
float destAngle = (targetAngle + _projectiles[i].angle) * 0.5f;
_projectiles[i].angle = destAngle;
if (_projectiles[i].brassCount++ > 240) {
_projectiles[i].isAppear = false;
}
}
// 이미지 출력 안 하는, 투사체겸 장판 데미지용
if (_projectiles[i].imgKey == _strDamageBoundary) {
if (_projectiles[i].count++ > 3) {
_projectiles[i].isAppear = false;
}
}
// 이미지 출력하는 일반 투사체
else
{
// 일반 화살같은
if (!_projectiles[i].isBrassing)
{
_projectiles[i].x += cosf(_projectiles[i].angle * PI / 180.0f) * _projectiles[i].speed;
_projectiles[i].y -= sinf(_projectiles[i].angle * PI / 180.0f) * _projectiles[i].speed;
// 프레임이 필요한 투사체의 경우-
if (_projectiles[i].isFrame)
{
if (_projectiles[i].count++ % 10 == 0)
{
_projectiles[i].frameX++;
if (_projectiles[i].frameX > 10)
{
_projectiles[i].frameX = 11;
_projectiles[i].frameY = 0;
}
}
}
}
// 브레스같은
else
{
if (_projectiles[i].count++ % 12 == 0)
{
_projectiles[i].frameX += _projectiles[i].isPingPong ? 1 : -1;
if (_projectiles[i].frameX > 8)
_projectiles[i].isPingPong = false;
if (_projectiles[i].isPingPong == false && _projectiles[i].frameX == 0)
_projectiles[i].isAppear = false;
}
}
}
// 카메라 바깥으로 나가면 삭제
RECT temp;
if (!IntersectRect(&temp, &CAMERA->GetCameraRect(), &RectMakeCenter(_projectiles[i].x, _projectiles[i].y, 20, 20)))
_projectiles[i].isAppear = false;
}
}
}
void ProjectileManager::render(HDC hdc)
{
if (CAMERA->movelimit) {
for (int i = 0; i < PROJECTILE_MAX; i++)
{
if (_projectiles[i].isAppear) {
if (_projectiles[i].imgKey == _strDamageBoundary)
continue;
// 일반 렌더
if (!_projectiles[i].isFrame)
IMAGEMANAGER->findImage(_projectiles[i].imgKey)->rotateRender(hdc, CAMERA->GetRelativeX(_projectiles[i].x), CAMERA->GetRelativeY(_projectiles[i].y), _projectiles[i].angle * PI / 180.0f);
// 프레임 렌더
else {
IMAGEMANAGER->frameRender(_projectiles[i].imgKey, hdc, CAMERA->GetRelativeX(_projectiles[i].x), CAMERA->GetRelativeY(_projectiles[i].y), _projectiles[i].frameX, _projectiles[i].frameY, CAMERA->GetZoom());
}
}
}
}
}
void ProjectileManager::CreateProjectile(string imgKey, int x, int y, int damage, float angle, float speed, int size, bool isEnemy, bool isFrame, bool isStretch)
{
for (int i = 0; i < PROJECTILE_MAX; i++) {
if (!_projectiles[i].isAppear) {
_projectiles[i].imgKey = imgKey;
_projectiles[i].x = x;
_projectiles[i].y = y;
_projectiles[i].damage = damage;
_projectiles[i].angle = angle;
_projectiles[i].speed = speed;
_projectiles[i].isEnemyProjectTile = isEnemy;
_projectiles[i].isStretch = isStretch;
_projectiles[i].count = 0;
_projectiles[i].isAppear = true;
_projectiles[i].width = size;
_projectiles[i].height = size;
_projectiles[i].isFrame = isFrame;
_projectiles[i].frameX = 0;
_projectiles[i].frameY = 0;
_projectiles[i].isBrassing = false;
_projectiles[i].brassCount = 0;
_projectiles[i].isPingPong = false;
_projectiles[i].isFollowing = false;
_projectiles[i]._playerTargetRc = nullptr;
break;
}
}
}
void ProjectileManager::CreateProjectile(string imgKey, RECT * playerTargetRc, int x, int y, int damage, float angle, float speed, int size, bool isEnemy, bool isFrame, bool isFollowing)
{
for (int i = 0; i < PROJECTILE_MAX; i++)
{
if (!_projectiles[i].isAppear) {
_projectiles[i].imgKey = imgKey;
_projectiles[i].x = x;
_projectiles[i].y = y;
_projectiles[i].damage = damage;
_projectiles[i].angle = angle;
_projectiles[i].speed = speed;
_projectiles[i].width = size;
_projectiles[i].height = size;
_projectiles[i].isEnemyProjectTile = isEnemy;
_projectiles[i].isFrame = isFrame;
_projectiles[i].isFollowing = isFollowing;
_projectiles[i].frameX = 0;
_projectiles[i].frameY = 0;
_projectiles[i].count = 0;
_projectiles[i]._playerTargetRc = playerTargetRc;
_projectiles[i].isBrassing = false;
_projectiles[i].brassCount = 0;
_projectiles[i].isPingPong = false;
_projectiles[i].isAppear = true;
break;
}
}
}
float ProjectileManager::shootToTarget(int index)
{
int cX = _projectiles[index].x;
int cY = _projectiles[index].y;
int pL = _projectiles[index]._playerTargetRc->left;
int pR = _projectiles[index]._playerTargetRc->right;
int pT = _projectiles[index]._playerTargetRc->top;
int pB = _projectiles[index]._playerTargetRc->bottom;
int cPx = pL + (pR - pL) / 2;
int cPy = pT + (pB - pT) / 2;
return atan2(-(cPy - cY), (cPx - cX)) / PI * 180;
}
void ProjectileManager::CreateProjectile(string imgKey, int x, int y, int damage, int width, int height, bool isLeft)
{
for (int i = 0; i < PROJECTILE_MAX; i++) {
if (!_projectiles[i].isAppear) {
_projectiles[i].imgKey = imgKey;
_projectiles[i].x = x;
_projectiles[i].y = y;
_projectiles[i].damage = damage;
_projectiles[i].angle = 0;
_projectiles[i].speed = 0;
_projectiles[i].isEnemyProjectTile = true;
_projectiles[i].isStretch = false;
_projectiles[i].count = 0;
_projectiles[i].isAppear = true;
_projectiles[i].width = width;
_projectiles[i].height = height;
_projectiles[i].isFrame = true;
_projectiles[i].isBrassing = true;
_projectiles[i].brassCount = 0;
_projectiles[i].isPingPong = true;
_projectiles[i].frameX = 0;
_projectiles[i].frameY = isLeft ? 1 : 0;
_projectiles[i].isFollowing = false;
_projectiles[i]._playerTargetRc = nullptr;
break;
}
}
}
void ProjectileManager::CreateProjectile(int x, int y, int damage, int width, int height)
{
for (int i = 0; i < PROJECTILE_MAX; i++)
{
if (!_projectiles[i].isAppear) {
_projectiles[i].imgKey = _strDamageBoundary;
_projectiles[i].x = x;
_projectiles[i].y = y;
_projectiles[i].damage = damage;
_projectiles[i].width = width;
_projectiles[i].height = height;
_projectiles[i].isStretch = false;
_projectiles[i].isEnemyProjectTile = true;
_projectiles[i].speed = 0;
_projectiles[i].count = 0;
_projectiles[i].angle = 0.0f;
_projectiles[i].isBrassing = false;
_projectiles[i].brassCount = 0;
_projectiles[i].isPingPong = false;
_projectiles[i].isAppear = true;
_projectiles[i].isFollowing = false;
_projectiles[i]._playerTargetRc = nullptr;
break;
}
}
}