forked from YutaTachibana0310/SankouGoudou2019Summer
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnemyBullet.cpp
112 lines (91 loc) · 2.39 KB
/
EnemyBullet.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
//=====================================
//
//エネミーバレット処理[EnemyBullet.cpp]
//Author:GP12A332 21 立花雄太
//
//=====================================
#include "EnemyBullet.h"
#include "Framework\ResourceManager.h"
#include "camera.h"
#include "GameParticleManager.h"
#include "EnemyBulletTrail.h"
/**************************************
マクロ定義
***************************************/
#define ENEMYBULLET_INIT_SPEED (5.5f)
/**************************************
コンストラクタ
***************************************/
EnemyBullet::EnemyBullet()
{
ResourceManager::Instance()->GetPolygon(RESOURCE_ENEMYBULLET_TAG, polygon);
active = false;
}
/**************************************
デストラクタ
***************************************/
EnemyBullet::~EnemyBullet()
{
polygon = NULL;
}
/**************************************
初期化処理
***************************************/
void EnemyBullet::Init(D3DXVECTOR3 setPos, D3DXVECTOR3 target, int reachFrame, const D3DXVECTOR3& scale)
{
active = true;
targetPos = target;
cntFrame = reachFrame;
transform.pos = setPos;
transform.scale = scale;
velocity.x = RandomRangef(-1.0f, 1.0f);
velocity.y = RandomRangef(-1.0f, 1.0f);
velocity.z = 1.0f;
D3DXVec3Normalize(&velocity, &velocity);
velocity *= ENEMYBULLET_INIT_SPEED;
BaseEmitter* emitter = GameParticleManager::Instance()->SetEnemyBulletTrail(&transform.pos);
if (emitter != NULL)
trail = static_cast<EnemyBulletTrailEmitter*>(emitter);
}
/**************************************
終了処理
***************************************/
void EnemyBullet::Uninit()
{
active = false;
if (trail != NULL)
{
trail->active = false;
trail = NULL;
}
}
/**************************************
更新処理
***************************************/
void EnemyBullet::Update()
{
if (!active)
return;
transform.Rotate(0.0f, 0.0f, 5.0f);
D3DXVECTOR3 diff = targetPos - transform.pos;
D3DXVECTOR3 acceleration = (diff - velocity * (float)cntFrame) * 2.0f / (float)(cntFrame * cntFrame);
cntFrame--;
velocity += acceleration;
transform.pos += velocity;
if (trail != NULL)
trail->transform.pos = transform.pos;
if (cntFrame < 0)
Uninit();
}
/**************************************
描画処理
***************************************/
void EnemyBullet::Draw()
{
LPDIRECT3DDEVICE9 pDevice = GetDevice();
D3DXMATRIX mtxWorld, mtxInvView;
//ワールド変換
transform.SetWorldInvView();
//描画
polygon->Draw();
}