-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.cpp
332 lines (265 loc) · 10.4 KB
/
message.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
//******************************************************************************
//
// タイトル: メッセージ表示処理
// プログラム名: message.cpp
// 作成者: HAL東京ゲーム学科 劉南宏
//
//******************************************************************************
/*******************************************************************************
* インクルードファイル
*******************************************************************************/
#include "message.h"
//*****************************************************************************
// マクロ定義
//*****************************************************************************
#define NUM_VERTEX (4)
#define NUM_POLYGON (2)
#define MAX_MSG (13)
#define POLYGON_POS_X (625)
#define POLYGON_POS_Y (375)
#define POLYGON_TEXTURENAME_MSG_0 "data/TEXTURE/MSG/GAME_OVER.png"
#define POLYGON_TEXTURENAME_MSG_1 "data/TEXTURE/MSG/STAGE_CLEAR.png"
#define POLYGON_TEXTURENAME_MSG_2 "data/TEXTURE/MSG/RANK.png"
#define POLYGON_TEXTURENAME_MSG_3 "data/TEXTURE/MSG/PAUSE.png"
#define POLYGON_TEXTURENAME_MSG_4 "data/TEXTURE/MSG/TIME_UP.png"
#define POLYGON_TEXTURENAME_MSG_5 "data/TEXTURE/MSG/GAME_SET.png"
#define POLYGON_TEXTURENAME_MSG_6 "data/TEXTURE/MSG/DRAW.png"
#define POLYGON_TEXTURENAME_MSG_7 "data/TEXTURE/MSG/WIN.png"
#define POLYGON_TEXTURENAME_MSG_8 "data/TEXTURE/MSG/1P.png"
#define POLYGON_TEXTURENAME_MSG_9 "data/TEXTURE/MSG/2P.png"
#define POLYGON_TEXTURENAME_MSG_10 "data/TEXTURE/MSG/3P.png"
#define POLYGON_TEXTURENAME_MSG_11 "data/TEXTURE/MSG/4P.png"
#define POLYGON_TEXTURENAME_MSG_12 "data/TEXTURE/MSG/RESULT.png"
/*******************************************************************************
* 構造体定義
*******************************************************************************/
/*******************************************************************************
* プロトタイプ宣言
*******************************************************************************/
HRESULT MakeVertexMessage(LPDIRECT3DDEVICE9 pDevice);
void SetColorMessage(int nMenuIdx, int R, int G, int B, int A);
/*******************************************************************************
* グローバル変数
*******************************************************************************/
LPDIRECT3DVERTEXBUFFER9 g_pVtxBufferMessage = NULL;
LPDIRECT3DTEXTURE9 g_pTextureMessage[MAX_MSG] = {NULL};
MESSAGE g_msg[MAX_MSG];
/*******************************************************************************
関数名: HRESULT InitBG(void)
引数: なし
戻り値: HRESUL : 初期化結果 正常終了:S_OK
説明: 背景の初期化処理
*******************************************************************************/
HRESULT InitMessage(void)
{
LPDIRECT3DDEVICE9 pDevice = GetDevice();
for(int nCntMsg = 0; nCntMsg < MAX_MSG; nCntMsg++)
{
g_msg[nCntMsg].bUse = false;
}
//GAME_OVER
g_msg[0].pos = D3DXVECTOR3( POLYGON_POS_X, POLYGON_POS_Y, 0.0f);
g_msg[0].size = D3DXVECTOR3( 900, 100, 0.0f);
g_msg[0].col = D3DCOLOR_RGBA(255,255,0,255);
//STAGE_CLEAR
g_msg[1].pos = D3DXVECTOR3( POLYGON_POS_X, POLYGON_POS_Y, 0.0f);
g_msg[1].size = D3DXVECTOR3( 800, 100, 0.0f);
g_msg[1].col = D3DCOLOR_RGBA(255,255,0,255);
//RANK
g_msg[2].pos = D3DXVECTOR3( POLYGON_POS_X, 100, 0.0f);
g_msg[2].size = D3DXVECTOR3( 400, 100, 0.0f);
//g_msg[2].col = D3DCOLOR_RGBA(255,0,0,255);
g_msg[2].col = D3DCOLOR_RGBA(30,225,180,255);
//PAUSE
g_msg[3].pos = D3DXVECTOR3( POLYGON_POS_X, POLYGON_POS_Y, 0.0f);
g_msg[3].size = D3DXVECTOR3( 500, 100, 0.0f);
g_msg[3].col = D3DCOLOR_RGBA(255,255,0,255);
//TIME_UP
g_msg[4].pos = D3DXVECTOR3( POLYGON_POS_X, POLYGON_POS_Y, 0.0f);
g_msg[4].size = D3DXVECTOR3( 700, 100, 0.0f);
g_msg[4].col = D3DCOLOR_RGBA(255,255,0,255);
//GAME_SET
g_msg[5].pos = D3DXVECTOR3( POLYGON_POS_X, POLYGON_POS_Y + 100, 0.0f);
g_msg[5].size = D3DXVECTOR3( 800, 100, 0.0f);
g_msg[5].col = D3DCOLOR_RGBA(255,255,0,255);
//DRAW
g_msg[6].pos = D3DXVECTOR3( POLYGON_POS_X, POLYGON_POS_Y, 0.0f);
g_msg[6].size = D3DXVECTOR3( 400, 100, 0.0f);
g_msg[6].col = D3DCOLOR_RGBA(255,255,0,255);
//WIN
g_msg[7].pos = D3DXVECTOR3( POLYGON_POS_X + 150, POLYGON_POS_Y, 0.0f);
g_msg[7].size = D3DXVECTOR3( 300, 100, 0.0f);
g_msg[7].col = D3DCOLOR_RGBA(255,255,0,255);
//1P
g_msg[8].pos = D3DXVECTOR3( POLYGON_POS_X - 150, POLYGON_POS_Y, 0.0f);
g_msg[8].size = D3DXVECTOR3( 300, 100, 0.0f);
g_msg[8].col = D3DCOLOR_RGBA(255,0,0,255); //red
//2P
g_msg[9].pos = D3DXVECTOR3( POLYGON_POS_X - 150, POLYGON_POS_Y, 0.0f);
g_msg[9].size = D3DXVECTOR3( 300, 100, 0.0f);
g_msg[9].col = D3DCOLOR_RGBA(255,255,0,255); //yellow
//3P
g_msg[10].pos = D3DXVECTOR3( POLYGON_POS_X - 150, POLYGON_POS_Y, 0.0f);
g_msg[10].size = D3DXVECTOR3( 300, 100, 0.0f);
g_msg[10].col = D3DCOLOR_RGBA(0,255,0,255); //green
//4P
g_msg[11].pos = D3DXVECTOR3( POLYGON_POS_X - 150, POLYGON_POS_Y, 0.0f);
g_msg[11].size = D3DXVECTOR3( 300, 100, 0.0f);
g_msg[11].col = D3DCOLOR_RGBA(0,0,255,255); //blue
//RESULT
g_msg[12].pos = D3DXVECTOR3( POLYGON_POS_X, 100, 0.0f);
g_msg[12].size = D3DXVECTOR3( 500, 100, 0.0f);
//g_msg[12].col = D3DCOLOR_RGBA(255,0,0,255);
g_msg[12].col = D3DCOLOR_RGBA(30,225,180,255);
//頂点情報の作成
if(FAILED(MakeVertexMessage(pDevice)))
{
return E_FAIL;
}
//テクスチャの読み込み
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_MSG_0, &g_pTextureMessage[0]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_MSG_1, &g_pTextureMessage[1]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_MSG_2, &g_pTextureMessage[2]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_MSG_3, &g_pTextureMessage[3]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_MSG_4, &g_pTextureMessage[4]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_MSG_5, &g_pTextureMessage[5]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_MSG_6, &g_pTextureMessage[6]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_MSG_7, &g_pTextureMessage[7]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_MSG_8, &g_pTextureMessage[8]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_MSG_9, &g_pTextureMessage[9]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_MSG_10, &g_pTextureMessage[10]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_MSG_11, &g_pTextureMessage[11]);
D3DXCreateTextureFromFile( pDevice, POLYGON_TEXTURENAME_MSG_12, &g_pTextureMessage[12]);
return S_OK;
}
/*******************************************************************************
関数名: void DrawBG(void)
引数: なし
戻り値: なし
説明: 背景のポリゴンの描画関数
*******************************************************************************/
void DrawMessage(void)
{
LPDIRECT3DDEVICE9 pDevice = GetDevice();
//頂点バッファをデバイスのデータストリームにバインド
pDevice->SetStreamSource(0, g_pVtxBufferMessage, 0, sizeof(VERTEX_2D));
//頂点フォーマットの設定
pDevice->SetFVF(FVF_VERTEX_2D);
for(int nCntMsg = 0; nCntMsg < MAX_MSG; nCntMsg++)
{
if(g_msg[nCntMsg].bUse)
{
//テクスチャの設定
pDevice->SetTexture(0, g_pTextureMessage[nCntMsg]);
//ポリゴンの描画
pDevice->DrawPrimitive(
D3DPT_TRIANGLESTRIP, //プリミティブの種類
nCntMsg*4, //ロードする最初の頂点インデックス
NUM_POLYGON //ポリゴンの数
);
}
}
}
/*******************************************************************************
関数名: void UninitBG(void)
引数: なし
戻り値: なし
説明: 背景のポリゴンの開放関数
*******************************************************************************/
void UninitMessage(void)
{
for(int nCntMsg = 0; nCntMsg < MAX_MSG; nCntMsg++)
{
if(g_pTextureMessage[nCntMsg] != NULL)
{
g_pTextureMessage[nCntMsg]->Release();
g_pTextureMessage[nCntMsg] = NULL;
}
}
if(g_pVtxBufferMessage != NULL)
{
g_pVtxBufferMessage->Release();
g_pVtxBufferMessage = NULL;
}
}
/*******************************************************************************
関数名: HRESULT MakeVertexPolygon(LPDIRECT3DDEVICE9 pDevice)
引数: LPDIRECT3DDEVICE9 pDevice : Deviceオブジェクト
戻り値: HRESUL : 初期化結果 正常終了:S_OK
説明: 背景のポリゴンの頂点情報の作成関数
*******************************************************************************/
HRESULT MakeVertexMessage(LPDIRECT3DDEVICE9 pDevice)
{
if(FAILED(pDevice->CreateVertexBuffer(
sizeof(VERTEX_2D)*NUM_VERTEX*MAX_MSG, //頂点データのバッファサイズ
D3DUSAGE_WRITEONLY,
FVF_VERTEX_2D, //頂点フォーマット
D3DPOOL_MANAGED,
&g_pVtxBufferMessage, //頂点バッファインターフェースのポインタ
NULL)))
{
return E_FAIL;
}
//頂点バッファの中身を埋める
VERTEX_2D *pVtx;
//頂点データの範囲をロックし、頂点バッファへのポインタを取得
g_pVtxBufferMessage->Lock( 0, 0, (void**)&pVtx, 0);
for(int nCntMsg = 0; nCntMsg < MAX_MSG; nCntMsg++,pVtx+=4)
{
//頂点座標の設定
pVtx[0].pos = D3DXVECTOR3(g_msg[nCntMsg].pos.x - (g_msg[nCntMsg].size.x/2), g_msg[nCntMsg].pos.y - (g_msg[nCntMsg].size.y/2), 0.0f);
pVtx[1].pos = D3DXVECTOR3(g_msg[nCntMsg].pos.x + (g_msg[nCntMsg].size.x/2), g_msg[nCntMsg].pos.y - (g_msg[nCntMsg].size.y/2), 0.0f);
pVtx[2].pos = D3DXVECTOR3(g_msg[nCntMsg].pos.x - (g_msg[nCntMsg].size.x/2), g_msg[nCntMsg].pos.y + (g_msg[nCntMsg].size.y/2), 0.0f);
pVtx[3].pos = D3DXVECTOR3(g_msg[nCntMsg].pos.x + (g_msg[nCntMsg].size.x/2), g_msg[nCntMsg].pos.y + (g_msg[nCntMsg].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_msg[nCntMsg].col;
pVtx[1].col = g_msg[nCntMsg].col;
pVtx[2].col = g_msg[nCntMsg].col;
pVtx[3].col = g_msg[nCntMsg].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_pVtxBufferMessage->Unlock();
return S_OK;
}
void UpdateMessage(void)
{
}
void SetColorMessage(int nMenuIdx, int R, int G, int B, int A)
{
//頂点バッファの中身を埋める
VERTEX_2D *pVtx;
// 頂点データの範囲をロックし、頂点バッファへのポインタを取得
g_pVtxBufferMessage->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_pVtxBufferMessage->Unlock();
}
void SetMessage(int nMsgIdx)
{
g_msg[nMsgIdx].bUse = true;
}
void ClearMessage(int nMsgIdx)
{
g_msg[nMsgIdx].bUse = false;
}
void ClearMessage(void)
{
for(int nCntMsg = 0; nCntMsg < MAX_MSG; nCntMsg++)
{
g_msg[nCntMsg].bUse = false;
}
}