Repository navigation
Expand file tree
/
Copy pathgameRound.cpp
More file actions
397 lines (300 loc) · 8.8 KB
/
Copy pathgameRound.cpp
File metadata and controls
397 lines (300 loc) · 8.8 KB
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#include "gameRound.h"
#include "input.h"
#include "fade.h"
#include "player.h"
//*****************************************************************************
// マクロ定義
//*****************************************************************************
#define PLAYER_WINMAX (3) //3勝取ったらGAMEOVER
#define ScoreBG_WIDTH (1024)
#define ScoreBG_HEIGHT (768)
#define ScoreMESSAGE_WIDTH (960) //RoundMessage画面のサイズ
#define ScoreMESSAGE_HEIGHT (640)
#define TEXTURE_MAX (8) // テクスチャの数
#define PLAYER1_POSX (350)
#define PLAYER1_POSY (200)
#define PLAYER_ICON_WIDTH (80)
#define PLAYER_ICON_HEIGHT (40)
#define TROPHY_WIDTH (40)
#define TROPHY_HEIGHT (40)
#define PLAYER_SPACING (80)
#define TROPHY_SPACING (100)
#define confirm_WIDTH (200)
#define confirm_HEIGHT (100)
//*****************************************************************************
// プロトタイプ宣言
//*****************************************************************************
//*****************************************************************************
// グローバル変数
//*****************************************************************************
static ID3D11Buffer* g_VertexBuffer = NULL; // 頂点情報
static ID3D11ShaderResourceView* g_Texture[TEXTURE_MAX] = { NULL }; // テクスチャ情報
static char* g_TexturName[TEXTURE_MAX] = {
"data/BG/BG4.png",
"data/UI/board.png",
"data/UI/P1icon.png",
"data/UI/P2icon.png",
"data/SOZAI/trophy.png",
"data/SOZAI/trophy_black.png",
"data/UI/confirm.png",
};
int RoundNow = 1; //今のRound数
float ScoreDisplayTime; //ENTER KEY出るまでの時間
//int Player1Wins; //P1勝利回数
//int Player2Wins; //P2勝利回数
//const int MAX_ROUNDS = 9; //最大Round数
//const int WIN_THRESHOLD = 5; //5勝取ったら、GAMEOVER
static BOOL g_Load = FALSE;
HRESULT InitScore(void)
{
ID3D11Device* pDevice = GetDevice();
//テクスチャ生成
for (int i = 0; i < TEXTURE_MAX; i++)
{
g_Texture[i] = NULL;
D3DX11CreateShaderResourceViewFromFile(GetDevice(),
g_TexturName[i],
NULL,
NULL,
&g_Texture[i],
NULL);
}
// 頂点バッファ生成
D3D11_BUFFER_DESC bd;
ZeroMemory(&bd, sizeof(bd));
bd.Usage = D3D11_USAGE_DYNAMIC;
bd.ByteWidth = sizeof(VERTEX_3D) * 4;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
GetDevice()->CreateBuffer(&bd, NULL, &g_VertexBuffer);
// 変数の初期化
ScoreDisplayTime = 60.0f; //ENTER KEY出るまで1秒
// BGM再生
g_Load = TRUE;
return S_OK;
}
void UninitScore(void)
{
if (g_Load == FALSE) return;
if (g_VertexBuffer)
{
g_VertexBuffer->Release();
g_VertexBuffer = NULL;
}
for (int i = 0; i < TEXTURE_MAX; i++)
{
if (g_Texture[i])
{
g_Texture[i]->Release();
g_Texture[i] = NULL;
}
}
g_Load = FALSE;
}
void updateScore()
{
PLAYER* player = GetPlayer();
if (ScoreDisplayTime > 0)
{
ScoreDisplayTime--;
}
else if (ScoreDisplayTime <= 0)
{
ScoreDisplayTime = 0;
//Display完了
if (GetKeyboardTrigger(DIK_RETURN))
{// Enter押したら、ステージを切り替える
//引き分けだったらRoundNow変更しない
if (isDraw)
{
RoundNow--;
isDraw = FALSE;
}
SetFade(FADE_OUT, MODE_GAME);
RoundNow++;
}
// ゲームパッドで入力処理
else if (IsButtonTriggered(0, BUTTON_START))
{
if (isDraw)
{
RoundNow--;
isDraw = FALSE;
}
SetFade(FADE_OUT, MODE_GAME);
RoundNow++;
}
else if (IsButtonTriggered(0, BUTTON_B))
{
if (isDraw)
{
RoundNow--;
isDraw = FALSE;
}
SetFade(FADE_OUT, MODE_GAME);
RoundNow++;
}
}
}
void DrawScore()
{
// 頂点バッファ設定
UINT stride = sizeof(VERTEX_3D);
UINT offset = 0;
GetDeviceContext()->IASetVertexBuffers(0, 1, &g_VertexBuffer, &stride, &offset);
// マトリクス設定
SetWorldViewProjection2D();
// プリミティブトポロジ設定
GetDeviceContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
// マテリアル設定
MATERIAL material;
ZeroMemory(&material, sizeof(material));
material.Diffuse = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
SetMaterial(material);
//Socre背景
{
// テクスチャ設定
GetDeviceContext()->PSSetShaderResources(0, 1, &g_Texture[0]);
float px = (float)0;
float py = (float)0;
float pw = (float)ScoreBG_WIDTH;
float ph = (float)ScoreBG_HEIGHT;
// 1枚のポリゴンの頂点とテクスチャ座標を設定
SetSpriteLTColor(g_VertexBuffer,
px, py, pw, ph,
0.0f, 0.0f, 1.0f, 1.0f,
XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f));
// ポリゴン描画
GetDeviceContext()->Draw(4, 0);
}
//SocreMessage背景表示
{
// テクスチャ設定
GetDeviceContext()->PSSetShaderResources(0, 1, &g_Texture[1]);
float px = (float)(ScoreBG_WIDTH - ScoreMESSAGE_WIDTH) / 2;
float py = (float)(ScoreBG_HEIGHT - ScoreMESSAGE_HEIGHT) / 2;
float pw = (float)ScoreMESSAGE_WIDTH;
float ph = (float)ScoreMESSAGE_HEIGHT;
// 1枚のポリゴンの頂点とテクスチャ座標を設定
SetSpriteLTColor(g_VertexBuffer,
px, py, pw, ph,
0.0f, 0.0f, 1.0f, 1.0f,
XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f));
// ポリゴン描画
GetDeviceContext()->Draw(4, 0);
}
{
PLAYER* player = GetPlayer();
{
//P1
// テクスチャ設定
GetDeviceContext()->PSSetShaderResources(0, 1, &g_Texture[2]);
float px = (float)PLAYER1_POSX;
float py = (float)PLAYER1_POSY;
float pw = (float)PLAYER_ICON_WIDTH;
float ph = (float)PLAYER_ICON_HEIGHT;
// 1枚のポリゴンの頂点とテクスチャ座標を設定
SetSpriteLTColor(g_VertexBuffer,
px, py, pw, ph,
0.0f, 0.0f, 1.0f, 1.0f,
XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f));
// ポリゴン描画
GetDeviceContext()->Draw(4, 0);
for (int i = 0; i < PLAYER_WINMAX; i++)
{
if (i < player[0].wins)
{
// テクスチャ設定
GetDeviceContext()->PSSetShaderResources(0, 1, &g_Texture[4]);
float px = (float)PLAYER1_POSX + (i + 1) * TROPHY_SPACING;
float py = (float)PLAYER1_POSY;
float pw = (float)TROPHY_WIDTH;
float ph = (float)TROPHY_HEIGHT;
// 1枚のポリゴンの頂点とテクスチャ座標を設定
SetSpriteLTColor(g_VertexBuffer,
px, py, pw, ph,
0.0f, 0.0f, 1.0f, 1.0f,
XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f));
// ポリゴン描画
GetDeviceContext()->Draw(4, 0);
}
else
{
// テクスチャ設定
GetDeviceContext()->PSSetShaderResources(0, 1, &g_Texture[5]);
float px = (float)PLAYER1_POSX + (i + 1) * TROPHY_SPACING;
float py = (float)PLAYER1_POSY;
float pw = (float)TROPHY_WIDTH;
float ph = (float)TROPHY_HEIGHT;
// 1枚のポリゴンの頂点とテクスチャ座標を設定
SetSpriteLTColor(g_VertexBuffer,
px, py, pw, ph,
0.0f, 0.0f, 1.0f, 1.0f,
XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f));
// ポリゴン描画
GetDeviceContext()->Draw(4, 0);
}
}
}
{
//P2
// テクスチャ設定
GetDeviceContext()->PSSetShaderResources(0, 1, &g_Texture[3]);
float px = (float)PLAYER1_POSX;
float py = (float)PLAYER1_POSY + PLAYER_SPACING;
float pw = (float)PLAYER_ICON_WIDTH;
float ph = (float)PLAYER_ICON_HEIGHT;
// 1枚のポリゴンの頂点とテクスチャ座標を設定
SetSpriteLTColor(g_VertexBuffer,
px, py, pw, ph,
0.0f, 0.0f, 1.0f, 1.0f,
XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f));
// ポリゴン描画
GetDeviceContext()->Draw(4, 0);
for (int i = 0; i < PLAYER_WINMAX; i++)
{
if (i < player[1].wins)
{
// テクスチャ設定
GetDeviceContext()->PSSetShaderResources(0, 1, &g_Texture[4]);
float px = (float)PLAYER1_POSX + (i + 1) * TROPHY_SPACING;
float py = (float)PLAYER1_POSY + PLAYER_SPACING;
float pw = (float)TROPHY_WIDTH;
float ph = (float)TROPHY_HEIGHT;
// 1枚のポリゴンの頂点とテクスチャ座標を設定
SetSpriteLTColor(g_VertexBuffer,
px, py, pw, ph,
0.0f, 0.0f, 1.0f, 1.0f,
XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f));
// ポリゴン描画
GetDeviceContext()->Draw(4, 0);
}
else
{
// テクスチャ設定
GetDeviceContext()->PSSetShaderResources(0, 1, &g_Texture[5]);
float px = (float)PLAYER1_POSX + (i + 1) * TROPHY_SPACING;
float py = (float)PLAYER1_POSY + PLAYER_SPACING;
float pw = (float)TROPHY_WIDTH;
float ph = (float)TROPHY_HEIGHT;
// 1枚のポリゴンの頂点とテクスチャ座標を設定
SetSpriteLTColor(g_VertexBuffer,
px, py, pw, ph,
0.0f, 0.0f, 1.0f, 1.0f,
XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f));
// ポリゴン描画
GetDeviceContext()->Draw(4, 0);
}
}
}
}
// Confirm buttonを描画
{
// テクスチャ設定
GetDeviceContext()->PSSetShaderResources(0, 1, &g_Texture[6]);
// 1枚のポリゴンの頂点とテクスチャ座標を設定
SetSprite(g_VertexBuffer, SCREEN_WIDTH - confirm_WIDTH, SCREEN_HEIGHT - confirm_HEIGHT / 2, confirm_WIDTH, confirm_HEIGHT, 0.0f, 0.0f, 1.0f, 1.0f);
// ポリゴン描画
GetDeviceContext()->Draw(4, 0);
}
}