-
Notifications
You must be signed in to change notification settings - Fork 0
/
bar_battle.cpp
290 lines (233 loc) · 9.42 KB
/
bar_battle.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
//******************************************************************************
//
// タイトル: バトルモードのUI表示処理
// プログラム名: bar_battle.cpp
// 作成者: HAL東京ゲーム学科 劉南宏
//
//******************************************************************************
/*******************************************************************************
* インクルードファイル
*******************************************************************************/
#include "bar_battle.h"
//*****************************************************************************
// マクロ定義
//*****************************************************************************
#define NUM_VERTEX (4)
#define NUM_POLYGON (2)
#define MAX_BAR_ICON (15)
#define POLYGON_TEXTURENAME_BAR_P1 "data/TEXTURE/BAR/1P.png"
#define POLYGON_TEXTURENAME_BAR_P2 "data/TEXTURE/BAR/2P.png"
#define POLYGON_TEXTURENAME_BAR_P3 "data/TEXTURE/BAR/3P.png"
#define POLYGON_TEXTURENAME_BAR_P4 "data/TEXTURE/BAR/4P.png"
#define POLYGON_TEXTURENAME_BAR_WIN "data/TEXTURE/BAR/WIN.png"
#define POLYGON_TEXTURENAME_BAR_DEATH "data/TEXTURE/BAR/DEATH.png"
#define POLYGON_TEXTURENAME_BAR_KILL "data/TEXTURE/BAR/KILL.png"
/*******************************************************************************
* 構造体定義
*******************************************************************************/
/*******************************************************************************
* プロトタイプ宣言
*******************************************************************************/
HRESULT MakeVertexBarBattle(LPDIRECT3DDEVICE9 pDevice);
/*******************************************************************************
* グローバル変数
*******************************************************************************/
LPDIRECT3DVERTEXBUFFER9 g_pVtxBufferBarBattle = NULL;
LPDIRECT3DTEXTURE9 g_pTextureBarBattle[MAX_BAR_ICON] = {NULL};
BAR_ICON_BATTLE g_barIcon[MAX_BAR_ICON];
/*******************************************************************************
関数名: HRESULT InitBG(void)
引数: なし
戻り値: HRESUL : 初期化結果 正常終了:S_OK
説明: 背景の初期化処理
*******************************************************************************/
HRESULT InitBarBattle(void)
{
LPDIRECT3DDEVICE9 pDevice = GetDevice();
//kill
g_barIcon[6].pos = D3DXVECTOR3( 10, 20, 0.0f);
g_barIcon[6].size = D3DXVECTOR3( 150, 70, 0.0f);
g_barIcon[6].col = D3DCOLOR_RGBA(30,225,180,255);
{
//p1
g_barIcon[0].pos = D3DXVECTOR3( 160, 25, 0.0f);
g_barIcon[0].size = D3DXVECTOR3( 50, 25, 0.0f);
g_barIcon[0].col = D3DCOLOR_RGBA(255,0,0,255); //red
//p2
g_barIcon[1].pos = D3DXVECTOR3( 270, 25, 0.0f);
g_barIcon[1].size = D3DXVECTOR3( 50, 25, 0.0f);
g_barIcon[1].col = D3DCOLOR_RGBA(255,255,0,255); //yellow
//p3
g_barIcon[2].pos = D3DXVECTOR3( 160, 65, 0.0f);
g_barIcon[2].size = D3DXVECTOR3( 50, 25, 0.0f);
g_barIcon[2].col = D3DCOLOR_RGBA(0,255,0,255); //green
//p4
g_barIcon[3].pos = D3DXVECTOR3( 270, 65, 0.0f);
g_barIcon[3].size = D3DXVECTOR3( 50, 25, 0.0f);
g_barIcon[3].col = D3DCOLOR_RGBA(0,0,255,255); //blue
}
//death
g_barIcon[5].pos = D3DXVECTOR3( 380, 20, 0.0f);
g_barIcon[5].size = D3DXVECTOR3( 150, 70, 0.0f);
g_barIcon[5].col = D3DCOLOR_RGBA(30,225,180,255);
{
//p1
g_barIcon[7].pos = D3DXVECTOR3( 530, 25, 0.0f);
g_barIcon[7].size = D3DXVECTOR3( 50, 25, 0.0f);
g_barIcon[7].col = D3DCOLOR_RGBA(255,0,0,255);
//p2
g_barIcon[8].pos = D3DXVECTOR3( 640, 25, 0.0f);
g_barIcon[8].size = D3DXVECTOR3( 50, 25, 0.0f);
g_barIcon[8].col = D3DCOLOR_RGBA(255,255,0,255);
//p3
g_barIcon[9].pos = D3DXVECTOR3( 530, 65, 0.0f);
g_barIcon[9].size = D3DXVECTOR3( 50, 25, 0.0f);
g_barIcon[9].col = D3DCOLOR_RGBA(0,255,0,255);
//p4
g_barIcon[10].pos = D3DXVECTOR3( 640, 65, 0.0f);
g_barIcon[10].size = D3DXVECTOR3( 50, 25, 0.0f);
g_barIcon[10].col = D3DCOLOR_RGBA(0,0,255,255);
}
//win
g_barIcon[4].pos = D3DXVECTOR3( 800, 20, 0.0f);
g_barIcon[4].size = D3DXVECTOR3( 150, 70, 0.0f);
g_barIcon[4].col = D3DCOLOR_RGBA(30,225,180,255);
{
//p1
g_barIcon[11].pos = D3DXVECTOR3( 960, 25, 0.0f);
g_barIcon[11].size = D3DXVECTOR3( 50, 25, 0.0f);
g_barIcon[11].col = D3DCOLOR_RGBA(255,0,0,255);
//p2
g_barIcon[12].pos = D3DXVECTOR3( 1100, 25, 0.0f);
g_barIcon[12].size = D3DXVECTOR3( 50, 25, 0.0f);
g_barIcon[12].col = D3DCOLOR_RGBA(255,255,0,255);
//p3
g_barIcon[13].pos = D3DXVECTOR3( 960, 65, 0.0f);
g_barIcon[13].size = D3DXVECTOR3( 50, 25, 0.0f);
g_barIcon[13].col = D3DCOLOR_RGBA(0,255,0,255);
//p4
g_barIcon[14].pos = D3DXVECTOR3( 1100, 65, 0.0f);
g_barIcon[14].size = D3DXVECTOR3( 50, 25, 0.0f);
g_barIcon[14].col = D3DCOLOR_RGBA(0,0,255,255);
}
//頂点情報の作成
if(FAILED(MakeVertexBarBattle(pDevice)))
{
return E_FAIL;
}
//テクスチャの読み込み
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_BAR_P1, &g_pTextureBarBattle[0]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_BAR_P2, &g_pTextureBarBattle[1]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_BAR_P3, &g_pTextureBarBattle[2]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_BAR_P4, &g_pTextureBarBattle[3]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_BAR_WIN, &g_pTextureBarBattle[4]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_BAR_DEATH, &g_pTextureBarBattle[5]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_BAR_KILL, &g_pTextureBarBattle[6]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_BAR_P1, &g_pTextureBarBattle[7]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_BAR_P2, &g_pTextureBarBattle[8]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_BAR_P3, &g_pTextureBarBattle[9]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_BAR_P4, &g_pTextureBarBattle[10]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_BAR_P1, &g_pTextureBarBattle[11]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_BAR_P2, &g_pTextureBarBattle[12]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_BAR_P3, &g_pTextureBarBattle[13]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_BAR_P4, &g_pTextureBarBattle[14]);
return S_OK;
}
/*******************************************************************************
関数名: void DrawBG(void)
引数: なし
戻り値: なし
説明: 背景のポリゴンの描画関数
*******************************************************************************/
void DrawBarBattle(void)
{
LPDIRECT3DDEVICE9 pDevice = GetDevice();
//頂点バッファをデバイスのデータストリームにバインド
pDevice->SetStreamSource(0, g_pVtxBufferBarBattle, 0, sizeof(VERTEX_2D));
//頂点フォーマットの設定
pDevice->SetFVF(FVF_VERTEX_2D);
for(int nCntIcon = 0; nCntIcon < MAX_BAR_ICON; nCntIcon++)
{
//テクスチャの設定
pDevice->SetTexture(0, g_pTextureBarBattle[nCntIcon]);
//ポリゴンの描画
pDevice->DrawPrimitive(
D3DPT_TRIANGLESTRIP, //プリミティブの種類
nCntIcon*4, //ロードする最初の頂点インデックス
NUM_POLYGON //ポリゴンの数
);
}
}
/*******************************************************************************
関数名: void UninitBG(void)
引数: なし
戻り値: なし
説明: 背景のポリゴンの開放関数
*******************************************************************************/
void UninitBarBattle(void)
{
for(int nCntIcon = 0; nCntIcon < MAX_BAR_ICON; nCntIcon++)
{
if(g_pTextureBarBattle[nCntIcon] != NULL)
{
g_pTextureBarBattle[nCntIcon]->Release();
g_pTextureBarBattle[nCntIcon] = NULL;
}
}
if(g_pVtxBufferBarBattle != NULL)
{
g_pVtxBufferBarBattle->Release();
g_pVtxBufferBarBattle = NULL;
}
}
/*******************************************************************************
関数名: HRESULT MakeVertexPolygon(LPDIRECT3DDEVICE9 pDevice)
引数: LPDIRECT3DDEVICE9 pDevice : Deviceオブジェクト
戻り値: HRESUL : 初期化結果 正常終了:S_OK
説明: 背景のポリゴンの頂点情報の作成関数
*******************************************************************************/
HRESULT MakeVertexBarBattle(LPDIRECT3DDEVICE9 pDevice)
{
if(FAILED(pDevice->CreateVertexBuffer(
sizeof(VERTEX_2D)*NUM_VERTEX*MAX_BAR_ICON, //頂点データのバッファサイズ
D3DUSAGE_WRITEONLY,
FVF_VERTEX_2D, //頂点フォーマット
D3DPOOL_MANAGED,
&g_pVtxBufferBarBattle, //頂点バッファインターフェースのポインタ
NULL)))
{
return E_FAIL;
}
//頂点バッファの中身を埋める
VERTEX_2D *pVtx;
//頂点データの範囲をロックし、頂点バッファへのポインタを取得
g_pVtxBufferBarBattle->Lock( 0, 0, (void**)&pVtx, 0);
for(int nCntIcon = 0; nCntIcon < MAX_BAR_ICON; nCntIcon++,pVtx+=4)
{
//頂点座標の設定
pVtx[0].pos = D3DXVECTOR3( g_barIcon[nCntIcon].pos.x, g_barIcon[nCntIcon].pos.y, 0.0f);
pVtx[1].pos = D3DXVECTOR3(g_barIcon[nCntIcon].pos.x + g_barIcon[nCntIcon].size.x, g_barIcon[nCntIcon].pos.y, 0.0f);
pVtx[2].pos = D3DXVECTOR3(g_barIcon[nCntIcon].pos.x, g_barIcon[nCntIcon].pos.y + g_barIcon[nCntIcon].size.y, 0.0f);
pVtx[3].pos = D3DXVECTOR3(g_barIcon[nCntIcon].pos.x + g_barIcon[nCntIcon].size.x, g_barIcon[nCntIcon].pos.y + g_barIcon[nCntIcon].size.y, 0.0f);
//rhw
pVtx[0].rhw = 1.0f;
pVtx[1].rhw = 1.0f;
pVtx[2].rhw = 1.0f;
pVtx[3].rhw = 1.0f;
//color
pVtx[0].col = g_barIcon[nCntIcon].col;
pVtx[1].col = g_barIcon[nCntIcon].col;
pVtx[2].col = g_barIcon[nCntIcon].col;
pVtx[3].col = g_barIcon[nCntIcon].col;
//テクスチャ座標指定
pVtx[0].tex = D3DXVECTOR2(0.0F, 0.0F);
pVtx[1].tex = D3DXVECTOR2(1.0F, 0.0F);
pVtx[2].tex = D3DXVECTOR2(0.0F, 1.0F);
pVtx[3].tex = D3DXVECTOR2(1.0F, 1.0F);
}
g_pVtxBufferBarBattle->Unlock();
return S_OK;
}
void UpdateBarBattle(void)
{
}