forked from YutaTachibana0310/SankouGoudou2019Summer
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnemyBulletModel.cpp
206 lines (168 loc) · 4.35 KB
/
EnemyBulletModel.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
//=====================================
//
//エネミーバレットモデル処理[EnemyBulletModel.cpp]
//Author:GP12A332 21 立花雄太
//
//=====================================
#include "EnemyBulletModel.h"
#include "EnemyBullet.h"
#include "GameParticleManager.h"
#include "Framework\BoxCollider3D.h"
/**************************************
マクロ定義
***************************************/
#define ENEMYBULLET_REACH_DEFAULT (45)
#define ENeMYBULLET_EFFECTIVE_FRAME (120)
/**************************************
コンストラクタ
***************************************/
EnemyBulletModel::EnemyBulletModel()
{
active = false;
posZ = 0.0f;
collider = new TrailCollider(TrailColliderTag::EnemyBullet);
collider->SetAddressZ(&posZ);
collider->active = false;
const D3DXVECTOR3 ColliderSize = D3DXVECTOR3(10.0f, 10.0f, 10.0f);
colliderL = new BoxCollider3D(BoxCollider3DTag::EnemyBullet, &edgeL, ColliderSize);
colliderR = new BoxCollider3D(BoxCollider3DTag::EnemyBullet, &edgeR, ColliderSize);
colliderL->active = false;
colliderR->active = false;
effect = NULL;
}
/**************************************
デストラクタ
***************************************/
EnemyBulletModel::~EnemyBulletModel()
{
for (auto& bullet : bullets)
{
SAFE_DELETE(bullet);
}
bullets.clear();
SAFE_DELETE(collider);
SAFE_DELETE(colliderL);
SAFE_DELETE(colliderR);
}
/**************************************
初期化処理
***************************************/
void EnemyBulletModel::Init(std::vector<D3DXVECTOR3> emitters, LineTrailModel target)
{
cntFrame = 0;
targetLine = target;
collider->SetTrailIndex(target);
bullets.reserve(emitters.size());
//弾の着弾点を計算
target.GetEdgePos(&edgeR, &edgeL);
D3DXVECTOR3 diff = edgeL - edgeR;
diff /= (float)(emitters.size() + 1);
D3DXVECTOR3 targetPos = edgeR + diff;
for (UINT cnt = 0; cnt < emitters.size(); cnt++)
{
bullets.push_back(new EnemyBullet());
bullets[cnt]->Init(emitters[cnt], targetPos, ENEMYBULLET_REACH_DEFAULT);
targetPos += diff;
}
reachFrame = ENEMYBULLET_REACH_DEFAULT;
active = true;
}
/**************************************
初期化処理
***************************************/
void EnemyBulletModel::Init(std::vector<D3DXVECTOR3> emitters, LineTrailModel target, int duration, const D3DXVECTOR3& scale)
{
cntFrame = 0;
targetLine = target;
collider->SetTrailIndex(target);
bullets.reserve(emitters.size());
//弾の着弾点を計算
target.GetEdgePos(&edgeR, &edgeL);
D3DXVECTOR3 diff = edgeL - edgeR;
diff /= (float)(emitters.size() + 1);
D3DXVECTOR3 targetPos = edgeR + diff;
for (UINT cnt = 0; cnt < emitters.size(); cnt++)
{
bullets.push_back(new EnemyBullet());
bullets[cnt]->Init(emitters[cnt], targetPos, duration, scale);
targetPos += diff;
}
reachFrame = duration;
active = true;
}
/**************************************
終了処理
***************************************/
void EnemyBulletModel::Uninit()
{
collider->active = false;
colliderL->active = false;
colliderR->active = false;
for (auto& bullet : bullets)
{
SAFE_DELETE(bullet);
}
bullets.clear();
active = false;
effect = NULL;
}
/**************************************
更新処理
***************************************/
void EnemyBulletModel::Update()
{
if (!active)
return;
cntFrame++;
//バレットの更新
for (auto& bullet : bullets)
{
bullet->Update();
}
//着弾時刻なら当たり判定をアクティブに
if (cntFrame == reachFrame)
{
//端のボックスコライダーをアクティブに
colliderL->active = true;
colliderR->active = true;
//TrailColliderをアクティブに
collider->active = true;
effect = GameParticleManager::Instance()->SetEnemyBulletEffect(targetLine);
}
//終了判定
if (cntFrame == reachFrame + ENeMYBULLET_EFFECTIVE_FRAME)
{
Uninit();
}
}
/**************************************
描画処理
***************************************/
void EnemyBulletModel::Draw()
{
if (!active)
return;
for (auto& bullet : bullets)
{
bullet->Draw();
}
TrailCollider::DrawCollider(collider);
BoxCollider3D::DrawCollider(colliderL);
BoxCollider3D::DrawCollider(colliderR);
}
/**************************************
非アクティブ処理
***************************************/
void EnemyBulletModel::Disable()
{
for (auto& bullet : bullets)
{
if (!bullet->active)
continue;
GameParticleManager::Instance()->SetEnemyBulletExplosion(&bullet->transform.pos);
bullet->Uninit();
}
if (effect != NULL)
effect->Uninit();
Uninit();
}