-
Notifications
You must be signed in to change notification settings - Fork 0
/
title_menu.cpp
318 lines (249 loc) · 9.97 KB
/
title_menu.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
//******************************************************************************
//
// タイトル: タイトルのメニュー処理
// プログラム名: title_menu.cpp
// 作成者: HAL東京ゲーム学科 劉南宏
//
//******************************************************************************
/*******************************************************************************
* インクルードファイル
*******************************************************************************/
#include "title_menu.h"
#include "input.h"
#include "sound.h"
//*****************************************************************************
// マクロ定義
//*****************************************************************************
#define NUM_VERTEX (4)
#define NUM_POLYGON (2)
#define MAX_TITLE_MENU (3)
#define POLYGON_SIZE_X (300)//ポリゴンのSIZE X
#define POLYGON_SIZE_Y (80)//ポリゴンのSIZE Y
#define POLYGON_TEXTURENAME_TITLE_MENU_0 "data/TEXTURE/TITLE/menu_COOPERATE.png"
#define POLYGON_TEXTURENAME_TITLE_MENU_1 "data/TEXTURE/TITLE/menu_BATTLE.png"
#define POLYGON_TEXTURENAME_TITLE_MENU_2 "data/TEXTURE/TITLE/menu_RANK.png"
//#define POLYGON_TEXTURENAME_TITLE_MENU_3 "data/TEXTURE/TITLE/menu_stageEditor.png"
//#define POLYGON_TEXTURENAME_TITLE_MENU_4 "data/TEXTURE/TITLE/menu_ranking.png"
/*******************************************************************************
* 構造体定義
*******************************************************************************/
/*******************************************************************************
* プロトタイプ宣言
*******************************************************************************/
HRESULT MakeVertexTitleMenu(LPDIRECT3DDEVICE9 pDevice);
void SetColorTitleMenu(int nMenuIdx, int R, int G, int B, int A);
void SetVertexTitleMenu(int nMenuIdx);
/*******************************************************************************
* グローバル変数
*******************************************************************************/
LPDIRECT3DVERTEXBUFFER9 g_pVtxBufferTitleMenu = NULL;
LPDIRECT3DTEXTURE9 g_pTextureTitleMenu[MAX_TITLE_MENU] = {NULL};
TITLE_MENU g_titleMenu[MAX_TITLE_MENU];
int g_menu;
float g_angle;
/*******************************************************************************
関数名: HRESULT InitBG(void)
引数: なし
戻り値: HRESUL : 初期化結果 正常終了:S_OK
説明: 背景の初期化処理
*******************************************************************************/
HRESULT InitTitleMenu(void)
{
LPDIRECT3DDEVICE9 pDevice = GetDevice();
g_menu = 0;
g_angle = 0;
//menu_cooperate
g_titleMenu[0].pos = D3DXVECTOR3( 625, 450, 0.0f);
g_titleMenu[0].size = D3DXVECTOR3( POLYGON_SIZE_X, POLYGON_SIZE_Y, 0.0f);
g_titleMenu[0].col = D3DCOLOR_RGBA(255,255,0,255);
//menu_battle
g_titleMenu[1].pos = D3DXVECTOR3( 625, 550, 0.0f);
g_titleMenu[1].size = D3DXVECTOR3( POLYGON_SIZE_X, POLYGON_SIZE_Y, 0.0f);
g_titleMenu[1].col = D3DCOLOR_RGBA(255,255,255,255);
//menu_rank
g_titleMenu[2].pos = D3DXVECTOR3( 625, 650, 0.0f);
g_titleMenu[2].size = D3DXVECTOR3( POLYGON_SIZE_X, POLYGON_SIZE_Y, 0.0f);
g_titleMenu[2].col = D3DCOLOR_RGBA(255,255,255,255);
////stage editor
//g_titleMenu[3].pos = D3DXVECTOR3( 625, 600, 0.0f);
//g_titleMenu[3].size = D3DXVECTOR3( 200, 45, 0.0f);
//g_titleMenu[3].col = D3DCOLOR_RGBA(255,255,255,255);
////exit
//g_titleMenu[4].pos = D3DXVECTOR3( 625, 650, 0.0f);
//g_titleMenu[4].size = D3DXVECTOR3( 200, 45, 0.0f);
//g_titleMenu[4].col = D3DCOLOR_RGBA(255,255,255,255);
//頂点情報の作成
if(FAILED(MakeVertexTitleMenu(pDevice)))
{
return E_FAIL;
}
//テクスチャの読み込み
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_TITLE_MENU_0, &g_pTextureTitleMenu[0]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_TITLE_MENU_1, &g_pTextureTitleMenu[1]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_TITLE_MENU_2, &g_pTextureTitleMenu[2]);
//D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_TITLE_MENU_3, &g_pTextureTitleMenu[3]);
//D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_TITLE_MENU_4, &g_pTextureTitleMenu[4]);
return S_OK;
}
/*******************************************************************************
関数名: void DrawBG(void)
引数: なし
戻り値: なし
説明: 背景のポリゴンの描画関数
*******************************************************************************/
void DrawTitleMenu(void)
{
LPDIRECT3DDEVICE9 pDevice = GetDevice();
//頂点バッファをデバイスのデータストリームにバインド
pDevice->SetStreamSource(0, g_pVtxBufferTitleMenu, 0, sizeof(VERTEX_2D));
//頂点フォーマットの設定
pDevice->SetFVF(FVF_VERTEX_2D);
for(int nCntIcon = 0; nCntIcon < MAX_TITLE_MENU; nCntIcon++)
{
//テクスチャの設定
pDevice->SetTexture(0, g_pTextureTitleMenu[nCntIcon]);
//ポリゴンの描画
pDevice->DrawPrimitive(
D3DPT_TRIANGLESTRIP, //プリミティブの種類
nCntIcon*4, //ロードする最初の頂点インデックス
NUM_POLYGON //ポリゴンの数
);
}
}
/*******************************************************************************
関数名: void UninitBG(void)
引数: なし
戻り値: なし
説明: 背景のポリゴンの開放関数
*******************************************************************************/
void UninitTitleMenu(void)
{
for(int nCntIcon = 0; nCntIcon < MAX_TITLE_MENU; nCntIcon++)
{
if(g_pTextureTitleMenu[nCntIcon] != NULL)
{
g_pTextureTitleMenu[nCntIcon]->Release();
g_pTextureTitleMenu[nCntIcon] = NULL;
}
}
if(g_pVtxBufferTitleMenu != NULL)
{
g_pVtxBufferTitleMenu->Release();
g_pVtxBufferTitleMenu = NULL;
}
}
/*******************************************************************************
関数名: HRESULT MakeVertexPolygon(LPDIRECT3DDEVICE9 pDevice)
引数: LPDIRECT3DDEVICE9 pDevice : Deviceオブジェクト
戻り値: HRESUL : 初期化結果 正常終了:S_OK
説明: 背景のポリゴンの頂点情報の作成関数
*******************************************************************************/
HRESULT MakeVertexTitleMenu(LPDIRECT3DDEVICE9 pDevice)
{
if(FAILED(pDevice->CreateVertexBuffer(
sizeof(VERTEX_2D)*NUM_VERTEX*MAX_TITLE_MENU, //頂点データのバッファサイズ
D3DUSAGE_WRITEONLY,
FVF_VERTEX_2D, //頂点フォーマット
D3DPOOL_MANAGED,
&g_pVtxBufferTitleMenu, //頂点バッファインターフェースのポインタ
NULL)))
{
return E_FAIL;
}
//頂点バッファの中身を埋める
VERTEX_2D *pVtx;
//頂点データの範囲をロックし、頂点バッファへのポインタを取得
g_pVtxBufferTitleMenu->Lock( 0, 0, (void**)&pVtx, 0);
for(int nCntIcon = 0; nCntIcon < MAX_TITLE_MENU; nCntIcon++,pVtx+=4)
{
//頂点座標の設定
pVtx[0].pos = D3DXVECTOR3(g_titleMenu[nCntIcon].pos.x - (g_titleMenu[nCntIcon].size.x/2), g_titleMenu[nCntIcon].pos.y - (g_titleMenu[nCntIcon].size.y/2), 0.0f);
pVtx[1].pos = D3DXVECTOR3(g_titleMenu[nCntIcon].pos.x + (g_titleMenu[nCntIcon].size.x/2), g_titleMenu[nCntIcon].pos.y - (g_titleMenu[nCntIcon].size.y/2), 0.0f);
pVtx[2].pos = D3DXVECTOR3(g_titleMenu[nCntIcon].pos.x - (g_titleMenu[nCntIcon].size.x/2), g_titleMenu[nCntIcon].pos.y + (g_titleMenu[nCntIcon].size.y/2), 0.0f);
pVtx[3].pos = D3DXVECTOR3(g_titleMenu[nCntIcon].pos.x + (g_titleMenu[nCntIcon].size.x/2), g_titleMenu[nCntIcon].pos.y + (g_titleMenu[nCntIcon].size.y/2), 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_titleMenu[nCntIcon].col;
pVtx[1].col = g_titleMenu[nCntIcon].col;
pVtx[2].col = g_titleMenu[nCntIcon].col;
pVtx[3].col = g_titleMenu[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_pVtxBufferTitleMenu->Unlock();
return S_OK;
}
void UpdateTitleMenu(void)
{
if(GetKeyboardTrigger(DIK_DOWN) || GetGamePadTrigger( 0, BUTTON_DOWN) )
{
SetColorTitleMenu( g_menu, 255, 255, 255, 255);
g_titleMenu[g_menu].size = D3DXVECTOR3( POLYGON_SIZE_X, POLYGON_SIZE_Y, 0.0f);
SetVertexTitleMenu(g_menu);
g_angle = 0;
g_menu++;
if(g_menu == MAX_TITLE_MENU) g_menu = 0;
//SE
SetSE(SOUND_LABEL_SE_SELECT);
}
if(GetKeyboardTrigger(DIK_UP) || GetGamePadTrigger( 0, BUTTON_UP) )
{
SetColorTitleMenu( g_menu, 255, 255, 255, 255);
g_titleMenu[g_menu].size = D3DXVECTOR3( POLYGON_SIZE_X, POLYGON_SIZE_Y, 0.0f);
SetVertexTitleMenu(g_menu);
g_angle = 0;
g_menu--;
if(g_menu == -1) g_menu = MAX_TITLE_MENU - 1;
//SE
SetSE(SOUND_LABEL_SE_SELECT);
}
//change color
SetColorTitleMenu( g_menu, 255, 255, 0, 255);
//change size
g_titleMenu[g_menu].size.x += sin(g_angle);
g_titleMenu[g_menu].size.y += sin(g_angle);
g_angle += 0.1f;
if(g_angle >= 6.28) g_angle = 0;
SetVertexTitleMenu(g_menu);
}
void SetColorTitleMenu(int nMenuIdx, int R, int G, int B, int A)
{
//頂点バッファの中身を埋める
VERTEX_2D *pVtx;
// 頂点データの範囲をロックし、頂点バッファへのポインタを取得
g_pVtxBufferTitleMenu->Lock(0, 0, (void**)&pVtx, 0);
pVtx += nMenuIdx * NUM_VERTEX;
//color
pVtx[0].col = D3DCOLOR_RGBA(R,G,B,A);
pVtx[1].col = D3DCOLOR_RGBA(R,G,B,A);
pVtx[2].col = D3DCOLOR_RGBA(R,G,B,A);
pVtx[3].col = D3DCOLOR_RGBA(R,G,B,A);
// 頂点データをアンロックする
g_pVtxBufferTitleMenu->Unlock();
}
void SetVertexTitleMenu(int nMenuIdx)
{
//頂点バッファの中身を埋める
VERTEX_2D *pVtx;
//頂点データの範囲をロックし、頂点バッファへのポインタを取得
g_pVtxBufferTitleMenu->Lock( 0, 0, (void**)&pVtx, 0);
pVtx += nMenuIdx * NUM_VERTEX;
//頂点座標の設定
pVtx[0].pos = D3DXVECTOR3(g_titleMenu[nMenuIdx].pos.x - (g_titleMenu[nMenuIdx].size.x/2), g_titleMenu[nMenuIdx].pos.y - (g_titleMenu[nMenuIdx].size.y/2), 0.0f);
pVtx[1].pos = D3DXVECTOR3(g_titleMenu[nMenuIdx].pos.x + (g_titleMenu[nMenuIdx].size.x/2), g_titleMenu[nMenuIdx].pos.y - (g_titleMenu[nMenuIdx].size.y/2), 0.0f);
pVtx[2].pos = D3DXVECTOR3(g_titleMenu[nMenuIdx].pos.x - (g_titleMenu[nMenuIdx].size.x/2), g_titleMenu[nMenuIdx].pos.y + (g_titleMenu[nMenuIdx].size.y/2), 0.0f);
pVtx[3].pos = D3DXVECTOR3(g_titleMenu[nMenuIdx].pos.x + (g_titleMenu[nMenuIdx].size.x/2), g_titleMenu[nMenuIdx].pos.y + (g_titleMenu[nMenuIdx].size.y/2), 0.0f);
// 頂点データをアンロックする
g_pVtxBufferTitleMenu->Unlock();
}
int GetTitleMenu(void)
{
return g_menu;
}