Repository navigation
Expand file tree
/
Copy pathlimit.cpp
More file actions
343 lines (247 loc) · 7.06 KB
/
Copy pathlimit.cpp
File metadata and controls
343 lines (247 loc) · 7.06 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
#include "limit.h"
#include "player.h"
#include "collision.h"
#include "sound.h"
//*****************************************************************************
// マクロ定義
//*****************************************************************************
#define SCREEN_WIDTH (1024) // (SCREEN_WIDTH) // 背景サイズ
#define SCREEN_HEIGHT (768) // (SCREEN_HEIGHT) //
#define LIMIT_WIDTH (544) // limitの幅
#define LIMIT_HEIGHT (900) // limitの高さ
#define TEXTURE_MAX (5) // テクスチャの数
#define LIMIT_MOVE_RANGE_Y (16.0f) //Limit上下移動範囲
#define LimitStartTime (31) //Limit開始までの秒数
#define TimerWidth (32)
#define TimerHeight (32)
#define TimerPosX ((SCREEN_WIDTH-TimerWidth)/2)
#define TimerPosY (32)
//*****************************************************************************
// グローバル変数
//*****************************************************************************
static ID3D11Buffer* g_VertexBuffer = NULL; // 頂点情報
static ID3D11ShaderResourceView* g_Texture[TEXTURE_MAX] = { NULL }; // テクスチャ情報
static char* g_TexturName[TEXTURE_MAX] = {
"data/SOZAI/mist_left.png",
"data/SOZAI/mist_right.png",
"data/UI/number.png",
"data/UI/timerboard.png",
};
static BOOL g_Load = FALSE; // 初期化を行ったかのフラグ
static LIMITWALL g_limit[LIMIT_MAX];
static TIME g_time;
//=============================================================================
// 初期化処理
//=============================================================================
HRESULT InitLimit()
{
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);
//Limit初期化
for (int i = 0; i < LIMIT_MAX; i++)
{
g_limit[i].use = FALSE;
g_limit[i].w = LIMIT_WIDTH;
g_limit[i].h = LIMIT_HEIGHT;
g_limit[i].speed = 0.2f;
g_limit[i].pos.y = g_limit[i].h / 2;
g_limit[i].moveTime = 0;
}
g_limit[0].pos.x = -g_limit[0].w / 2;//left
g_limit[1].pos.x = SCREEN_WIDTH + g_limit[1].w / 2;//right
//Timer初期化
g_time.realTime = LimitStartTime * 60;
g_Load = TRUE;
return S_OK;
}
void UninitLimit()
{
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 UpdateLimit()
{
//Timer
if (g_time.realTime > 0)
{
g_time.realTime--;
}
else
{
g_time.realTime = 0;
}
g_time.second = g_time.realTime / 60;
//Limit移動
if (g_limit[0].use)
{
g_limit[0].pos.x += g_limit[0].speed;
}
if (g_limit[1].use)
{
g_limit[1].pos.x -= g_limit[1].speed;
}
for (int i = 0; i < LIMIT_MAX; i++)
{
if (g_time.second <= 0 && !g_limit[i].use)
{
g_limit[i].use = TRUE;
//sound
}
if (g_limit[i].use)
{
//上下移動
g_limit[i].moveTime += 0.05f;
g_limit[i].pos.y = (SCREEN_HEIGHT / 2) + sin(g_limit[i].moveTime) * LIMIT_MOVE_RANGE_Y;
}
}
//Playerに当たり判定
{
PLAYER* player = GetPlayer();
for (int i = 0; i < LIMIT_MAX; i++)
{
for (int j = 0; j < PLAYER_MAX; j++)
{
if (CollisionBB(g_limit[i].pos, g_limit[i].w - 32.0f, g_limit[i].h, player[j].pos, player[j].w - 8.0f, player[j].h) && player[j].alive)
{
player[j].alive = FALSE;
//sound
PlaySound(SOUND_LABEL_SE_player_die);
}
}
}
}
}
void DrawLimit()
{
// 頂点バッファ設定
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);
//TimerBoard
{
// テクスチャ設定
GetDeviceContext()->PSSetShaderResources(0, 1, &g_Texture[3]);
float px = (float)TimerPosX + TimerWidth / 2;
float py = (float)TimerPosY;
float pw = (float)TimerWidth * 2.5f;
float ph = (float)TimerHeight * 2.5f;
float tw = 1.0f;
float th = 1.0f;
float tx = 0;
float ty = 0;
// 1枚のポリゴンの頂点とテクスチャ座標を設定
SetSpriteColor(g_VertexBuffer, px, py, pw, ph, tx, ty, tw, th,
XMFLOAT4(1.0f, 1.0f, 1.0f, 0.5f));
// ポリゴン描画
GetDeviceContext()->Draw(4, 0);
}
//Timer描画
{
// テクスチャ設定
GetDeviceContext()->PSSetShaderResources(0, 1, &g_Texture[2]);
// 桁数分処理する
int number = g_time.second;
//2桁数
for (int i = 0; i < 2; i++)
{
// 今回表示する桁の数字
float x = (float)(number % 10);
// タイマーの位置やテクスチャー座標を反映
float px = (float)TimerPosX - (float)TimerWidth * i + (float)TimerWidth; // タイマーの表示位置X
float py = (float)TimerPosY; // タイマーの表示位置Y
float pw = (float)TimerWidth; // タイマーの表示幅
float ph = (float)TimerHeight; // タイマーの表示高さ
float tw = 1.0f / 10; // テクスチャの幅
float th = 1.0f; // テクスチャの高さ
float tx = x * tw; // テクスチャの左上X座標
float ty = 0.0f; // テクスチャの左上Y座標
// 1枚のポリゴンの頂点とテクスチャ座標を設定
SetSpriteColor(g_VertexBuffer, px, py, pw, ph, tx, ty, tw, th,
XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f));
// ポリゴン描画
GetDeviceContext()->Draw(4, 0);
// 次の桁へ
number /= 10;
}
}
//Limit描画
//左
{
// テクスチャ設定
GetDeviceContext()->PSSetShaderResources(0, 1, &g_Texture[0]);
float px = g_limit[0].pos.x;
float py = g_limit[0].pos.y;
float pw = g_limit[0].w;
float ph = g_limit[0].h;
float tw = 1.0f;
float th = 1.0f;
float tx = 0.0f;
float ty = 0.0f;
// 1枚のポリゴンの頂点とテクスチャ座標を設定
SetSpriteColor(g_VertexBuffer, px, py, pw, ph, tx, ty, tw, th,
XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f));
// ポリゴン描画
GetDeviceContext()->Draw(4, 0);
}
//右
{
// テクスチャ設定
GetDeviceContext()->PSSetShaderResources(0, 1, &g_Texture[1]);
float px = g_limit[1].pos.x;
float py = g_limit[1].pos.y;
float pw = g_limit[1].w;
float ph = g_limit[1].h;
float tw = 1.0f;
float th = 1.0f;
float tx = 0.0f;
float ty = 0.0f;
// 1枚のポリゴンの頂点とテクスチャ座標を設定
SetSpriteColor(g_VertexBuffer, px, py, pw, ph, tx, ty, tw, th,
XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f));
// ポリゴン描画
GetDeviceContext()->Draw(4, 0);
}
}