-
Notifications
You must be signed in to change notification settings - Fork 2
/
BossEnemyModel.cpp
384 lines (317 loc) · 9.03 KB
/
BossEnemyModel.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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
//=====================================
//
//ボスエネミーモデル処理[BossEnemyModel.cpp]
//Author:GP12A332 21 立花雄太
//
//=====================================
#include "BossEnemyModel.h"
#include "BossEnemyActor.h"
#include "BossInit.h"
#include "BossRebarAttack.h"
#include "BossHomingAttack.h"
#include "BossDamageable.h"
#include "BossLargeDamage.h"
#include "BossDefeat.h"
#include "BossIdle.h"
#include "BossUIManager.h"
#include "EnemyBulletController.h"
#include "Framework\ResourceManager.h"
#include "Framework\CameraShakePlugin.h"
#include "GameParticleManager.h"
#include "sound.h"
#include "ScoreManager.h"
#include <random>
#include <algorithm>
using namespace std;
/**************************************
マクロ定義
***************************************/
/**************************************
コンストラクタ
***************************************/
BossEnemyModel::BossEnemyModel(const Transform& player, BossUImanager& uiManager) :
player(player),
isDestroyed(false),
uiManager(uiManager),
flgBomberHit(false),
cntLoop(0),
playerPositionIndex(0)
{
actor = new BossEnemyActor();
bulletController = new EnemyBulletController();
colliderController = new BossColliderController(*this);
//ステートマシン作成
fsm[State::Init] = new BossInit();
fsm[State::RebarAttack] = new BossRebarAttack();
fsm[State::HomingAttack] = new BossHomingAttack();
fsm[State::Damageable] = new BossDamageable();
fsm[State::LargeDamage] = new BossLargeDamage();
fsm[State::Defeat] = new BossDefeat;
fsm[State::Idle] = new BossIdle();
//鉄筋のモデルをロード
ResourceManager::Instance()->LoadMesh("RebarObstacle", "data/MODEL/rebar.x");
//レベル初期化
level = 0;
//Initステートへ遷移
ChangeState(State::Init);
}
/**************************************
デストラクタ
***************************************/
BossEnemyModel::~BossEnemyModel()
{
SAFE_DELETE(actor);
SAFE_DELETE(bulletController);
SAFE_DELETE(colliderController);
for (auto&& pair : fsm)
{
SAFE_DELETE(pair.second);
}
fsm.clear();
for (auto&& rebar : rebarList)
{
rebar.reset();
}
rebarList.clear();
}
/**************************************
更新処理
***************************************/
int BossEnemyModel::Update()
{
if (flgBomberHit)
{
ChangeState(State::LargeDamage);
flgBomberHit = false;
}
int nextState = state->OnUpdate(this);
if (nextState != currentState)
{
ChangeState((State)nextState);
}
for (auto&& rebar : rebarList)
{
rebar->Update();
}
actor->Update();
bulletController->Update();
colliderController->Update();
rebarList.remove_if([](auto&& rebar)
{
return rebar->IsDestroyed();
});
return 0;
}
/**************************************
描画処理
***************************************/
void BossEnemyModel::Draw()
{
for (auto&& rebar : rebarList)
{
rebar->Draw();
}
actor->Draw();
bulletController->Draw();
colliderController->Draw();
}
/**************************************
状態遷移処理
***************************************/
void BossEnemyModel::ChangeState(State next)
{
prevState = currentState;
currentState = next;
cntAttack = 0;
state = fsm[next];
state->OnStart(this);
}
/**************************************
鉄筋セット処理
***************************************/
void BossEnemyModel::SetRebar(int num)
{
float z = 300.0f;
for (int i = 0; i < num; i++)
{
int start = Math::RandomRange(0, 5);
int end = Math::WrapAround(0, 5, start + Math::RandomRange(1, 4));
LineTrailModel model = LineTrailModel(start, end);
D3DXVECTOR3 right, left;
model.GetEdgePos(&right, &left);
D3DXVECTOR3 pos = right + (left - right) / 2.0f;
pos.z = z;
pos.y -= 500.0f;
std::shared_ptr<RebarObstacle> rebar = std::make_shared<RebarObstacle>(pos, model, player);
rebar->Move(D3DXVECTOR3(0.0f, 500.0f, 0.0f), 120, EaseType::OutCubic);
rebarList.push_back(rebar);
z += 100.0f;
}
}
/**************************************
鉄筋投擲処理
***************************************/
void BossEnemyModel::ThrowRebar()
{
//投擲SE
Sound::GetInstance()->SetPlaySE(REBAR, true, (Sound::GetInstance()->changevol / 5.0f));
const int DelayDelta = 20;
int delay = 0;
for (auto&& rebar : rebarList)
{
rebar->Move(2500.0f, 180, EaseType::InSine, delay);
delay += DelayDelta;
}
}
/**************************************
チャージ開始処理
***************************************/
void BossEnemyModel::StartBulletCharge()
{
D3DXVECTOR3 SetPos = D3DXVECTOR3(0.0f, 0.0f, 500.0f);
GameParticleManager::Instance()->SetBossCharge(&SetPos);
}
/**************************************
バレット通知
***************************************/
void BossEnemyModel::NotifyBullet()
{
const int EdgeMax[Const::LevelMax] = { 3, 3, 4 };
std::vector<int> edgeList;
MakeOneStrokeEdge(EdgeMax[level], edgeList);
bulletReserve.clear();
for (UINT i = 0; i < edgeList.size() - 1; i++)
{
LineTrailModel model = LineTrailModel(edgeList[i], edgeList[i + 1]);
bulletReserve.push_back(model);
uiManager.SetBulletGuide(model);
}
}
/**************************************
バレット発射処理
**************************************/
void BossEnemyModel::FireBullet()
{
//バレット発射SE
Sound::GetInstance()->SetPlaySE(BOSSSHOT, true, (Sound::GetInstance()->changevol / 5.0f));
static std::vector<D3DXVECTOR3> Emitter = { D3DXVECTOR3(0.0f, 0.0f, 500.0f), D3DXVECTOR3(0.0f, 0.0f, 500.0f), D3DXVECTOR3(0.0f, 0.0f, 500.0f) };
for (auto&& model : bulletReserve)
{
bulletController->Set(Emitter, model, 60, D3DXVECTOR3(2.0f, 2.0f, 2.0f));
}
bulletReserve.clear();
}
/**************************************
コライダーセット処理
**************************************/
void BossEnemyModel::SetCollider()
{
const int EdgeMax[Const::LevelMax] = { 4, 5, 6 };
vector<int> edgeList;
MakeOneStrokeEdge(EdgeMax[level], edgeList);
colliderController->SetCollider(edgeList);
}
/**************************************
ダメージ処理
**************************************/
void BossEnemyModel::OnDamage()
{
actor->ChangeAnimation(BossEnemyActor::AnimID::Damage);
//ダメージSE
Sound::GetInstance()->SetPlaySE(ENEMYDOWN2, true, (Sound::GetInstance()->changevol / 10.0f));
//スコア・コンボ加算
const int HitScorePoint = 10;
SetAddCombo(1);
SetAddScore(HitScorePoint);
}
/**************************************
爆発処理
**************************************/
void BossEnemyModel::Explode()
{
actor->SetActive(false);
D3DXVECTOR3 actorPos = actor->GetActorPosition();
GameParticleManager::Instance()->SetBossExplosion(&actorPos);
const D3DXVECTOR3 ShakeAmplitude = D3DXVECTOR3(100.0f, 100.0f, 100.0f);
const int ShakeDuraiton = 360;
Camera::ShakePlugin::Instance()->Set(ShakeAmplitude, ShakeDuraiton);
const int BaseScorePoint = 500;
SetAddScore(BaseScorePoint);
}
/**************************************
爆発チャージ処理
**************************************/
void BossEnemyModel::ChargeExplode(Transform*& charge, Transform*& core)
{
//ボス撃破SE
Sound::GetInstance()->SetPlaySE(BOSSEXPLODE, true, (Sound::GetInstance()->changevol / 2.0f));
D3DXVECTOR3 actorPos = actor->GetActorPosition();
BaseEmitter* emitter = GameParticleManager::Instance()->SetBossExplosionCharge(&actorPos);
charge = &emitter->transform;
emitter = GameParticleManager::Instance()->SetBossExplosionCore(&actorPos);
core = &emitter->transform;
actor->SetWriteableZ(false);
}
/**************************************
撃墜判定
**************************************/
bool BossEnemyModel::IsDesteoyed()
{
return isDestroyed;
}
/**************************************
ボンバー着弾処理
**************************************/
void BossEnemyModel::OnHitBomber()
{
flgBomberHit = true;
colliderController->DeleteAll();
bulletController->DisableAll();
}
/**************************************
座標取得処理
**************************************/
D3DXVECTOR3 BossEnemyModel::GetPosition()
{
return actor->GetActorPosition();
}
/**************************************
鉄骨リスト取得
**************************************/
void BossEnemyModel::GetRebarList(std::list<std::shared_ptr<RebarObstacle>>& out)
{
out.assign(rebarList.begin(), rebarList.end());
}
/**************************************
プレイヤー座標インデックス受け渡し処理
**************************************/
void BossEnemyModel::ReceivePlayerPosition(int index)
{
playerPositionIndex = index;
}
/**************************************
生存判定
**************************************/
bool BossEnemyModel::IsAlive()
{
return currentState != State::Defeat;
}
/**************************************
一筆書きの軌跡作成処理
**************************************/
void BossEnemyModel::MakeOneStrokeEdge(int edgeNum, std::vector<int>& edgeList)
{
edgeList.clear();
edgeList.reserve(edgeNum);
vector<int> numberList = { 0, 1, 2, 3, 4 };
random_device randDevice;
mt19937_64 getRandMt(randDevice());
shuffle(numberList.begin(), numberList.end(), getRandMt);
//プレイヤーの位置のインデックスを計算
auto itr = find(numberList.begin(), numberList.end(), playerPositionIndex);
int baseIndex = itr != numberList.end() ? std::distance(numberList.begin(), itr) : 0;
for (int i = 0; i < edgeNum; i++)
{
edgeList.push_back(numberList[WrapAround(0, numberList.size(), i + baseIndex)]);
}
}