-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbattleCursor.cpp
400 lines (337 loc) · 9.84 KB
/
battleCursor.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
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
393
394
395
396
397
398
399
400
//=============================================================================
//
// WM画面処理 [battleCursor.cpp]
// Author : GP11A132 21 DAYA MAHAPUTRA
//
//=============================================================================
#include "battleCursor.h"
#include "main.h"
#include "sprite.h"
#include "player.h"
#include "battleUI.h"
#include "input.h"
#include "battle.h"
#include "damage.h"
#include "limitBar.h"
#include "battleLog.h"
#include "tutorial.h"
#include "sound.h"
//*****************************************************************************
// マクロ定義
//*****************************************************************************
#define TEXTURE_MAX (1) // テクスチャの数
//*****************************************************************************
// プロトタイプ宣言
//*****************************************************************************
//*****************************************************************************
// グローバル変数
//*****************************************************************************
static ID3D11Buffer *g_VertexBuffer = NULL; // 頂点情報
static ID3D11ShaderResourceView *g_Texture[TEXTURE_MAX] = { NULL }; // テクスチャ情報
static char *g_TexturName[TEXTURE_MAX] = {
"data/TEXTURE/cursor.png"
};
static BOOL g_Load = FALSE; // 初期化を行ったかのフラグ
static BATTLECURSOR g_Cursor;
// 初期化処理
//=============================================================================
HRESULT InitBattleCursor(void)
{
ID3D11Device *pDevice = GetDevice();
BATTLEUI *battleUI = GetBattleUI();
//テクスチャ生成
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);
g_Cursor.w = 50;
g_Cursor.h = 50;
g_Cursor.texNo = 0;
g_Cursor.posIndex = 0;
g_Cursor.mode = MENU_SELECT;
g_Cursor.canDoAction = TRUE;
g_Cursor.pos[0] = D3DXVECTOR3(battleUI->pos.x - 30.0f, 390.0f, 0.0f);
g_Cursor.pos[1] = D3DXVECTOR3(battleUI->pos.x - 30.0f, 435.0f, 0.0f);
g_Cursor.pos[2] = D3DXVECTOR3(battleUI->pos.x - 30.0f, 480.0f, 0.0f);
g_Cursor.powerUpPos[0] = D3DXVECTOR3(battleUI->pos.x - 30.0f, 290.0f, 0.0f);
g_Cursor.powerUpPos[1] = D3DXVECTOR3(battleUI->pos.x - 30.0f, 310.0f, 0.0f);
g_Cursor.powerUpPos[2] = D3DXVECTOR3(battleUI->pos.x - 30.0f, 333.0f, 0.0f);
g_Cursor.powerUpPos[3] = D3DXVECTOR3(battleUI->pos.x - 30.0f, 355.0f, 0.0f);
g_Load = TRUE; // データの初期化を行った
return S_OK;
}
//=============================================================================
// 終了処理
//=============================================================================
void UninitBattleCursor(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 UpdateBattleCursor(void)
{
PLAYER *player = GetPlayer();
BATTLEUI *battleUI = GetBattleUI();
TUTORIAL *tutorial = GetTutorial();
if (tutorial->use)
g_Cursor.canDoAction = FALSE;
if (battleUI->use && g_Cursor.canDoAction)
{
if (g_Cursor.mode == MENU_SELECT)
{
g_Cursor.pos[0] = D3DXVECTOR3(battleUI->pos.x - 30.0f, 390.0f, 0.0f);
g_Cursor.pos[1] = D3DXVECTOR3(battleUI->pos.x - 30.0f, 435.0f, 0.0f);
g_Cursor.pos[2] = D3DXVECTOR3(battleUI->pos.x - 30.0f, 480.0f, 0.0f);
if (GetKeyboardTrigger(DIK_X))
{
if (player->limitBreak >= WIDTH_MAX)
{
PlaySound(SOUND_LABEL_SE_click);
// LimitBreakを使う
PlayerLimitBreak();
}
}
if (GetKeyboardTrigger(DIK_UP))
{
PlaySound(SOUND_LABEL_SE_click);
g_Cursor.posIndex = (g_Cursor.posIndex - 1) % 3;
if (g_Cursor.posIndex < 0)
g_Cursor.posIndex = CURSOR_MAX_POSITION - 1;
}
else if (GetKeyboardTrigger(DIK_DOWN))
{
PlaySound(SOUND_LABEL_SE_click);
g_Cursor.posIndex = (g_Cursor.posIndex + 1) % CURSOR_MAX_POSITION;
}
if (GetKeyboardTrigger(DIK_RETURN))
{// Enter押したら
PlaySound(SOUND_LABEL_SE_click);
if (battleUI->texNo == BATTLE_UI)
{
switch (g_Cursor.posIndex)
{
case 0:
g_Cursor.mode = ATTACK_ENEMY;
SelectTargetEnemy();
break;
case 1:
g_Cursor.posIndex = 0;
ShowBattleUI(MAGIC_UI);
break;
case 2:
EscapeCheck();
g_Cursor.posIndex = 0;
break;
default:
break;
}
}
else
{
switch (g_Cursor.posIndex)
{
case 0:
if (CheckMP(6))
{
g_Cursor.mode = USE_FIREBALL;
SelectTargetEnemy();
}
break;
case 1:
if (CheckMP(10))
{
g_Cursor.mode = HEAL_ALLY;
g_Cursor.posIndex = 0;
SelectAlly();
}
break;
case 2:
g_Cursor.posIndex = 0;
ShowBattleUI(BATTLE_UI);
break;
default:
break;
}
}
}
}
else if(g_Cursor.mode == ATTACK_ENEMY)
{
if (GetKeyboardTrigger(DIK_RETURN))
{// Enter押したら
PlaySound(SOUND_LABEL_SE_click);
PlayerAttack();
g_Cursor.mode = MENU_SELECT;
}
else if (GetKeyboardTrigger(DIK_BACKSPACE))
{
PlaySound(SOUND_LABEL_SE_click);
g_Cursor.mode = MENU_SELECT;
}
}
else if (g_Cursor.mode == USE_FIREBALL)
{
if (GetKeyboardTrigger(DIK_RETURN))
{
PlaySound(SOUND_LABEL_SE_click);
// ファイヤーボールを使います
FireBall();
ShowBattleUI(BATTLE_UI);
g_Cursor.mode = MENU_SELECT;
}
else if (GetKeyboardTrigger(DIK_BACKSPACE))
{
PlaySound(SOUND_LABEL_SE_click);
ShowBattleUI(BATTLE_UI);
g_Cursor.mode = MENU_SELECT;
}
}
else if (g_Cursor.mode == HEAL_ALLY)
{
if (GetKeyboardTrigger(DIK_RETURN))
{
PlaySound(SOUND_LABEL_SE_click);
// キュアを使います
Cure();
ShowBattleUI(BATTLE_UI);
g_Cursor.mode = MENU_SELECT;
}
else if (GetKeyboardTrigger(DIK_BACKSPACE))
{
g_Cursor.mode = MENU_SELECT;
}
}
else if (g_Cursor.mode == POWERUP_SELECT)
{
g_Cursor.powerUpPos[0] = D3DXVECTOR3(battleUI->pos.x - 30.0f, 290.0f, 0.0f);
g_Cursor.powerUpPos[1] = D3DXVECTOR3(battleUI->pos.x - 30.0f, 310.0f, 0.0f);
g_Cursor.powerUpPos[2] = D3DXVECTOR3(battleUI->pos.x - 30.0f, 333.0f, 0.0f);
g_Cursor.powerUpPos[3] = D3DXVECTOR3(battleUI->pos.x - 30.0f, 355.0f, 0.0f);
if (GetKeyboardTrigger(DIK_UP))
{
PlaySound(SOUND_LABEL_SE_click);
g_Cursor.posIndex = (g_Cursor.posIndex - 1) % 4;
if (g_Cursor.posIndex < 0)
g_Cursor.posIndex = POWER_UP_MAX_POSITION - 1;
}
else if (GetKeyboardTrigger(DIK_DOWN))
{
PlaySound(SOUND_LABEL_SE_click);
g_Cursor.posIndex = (g_Cursor.posIndex + 1) % POWER_UP_MAX_POSITION;
}
if (GetKeyboardTrigger(DIK_RETURN))
{
PlaySound(SOUND_LABEL_SE_click);
battleUI->use = FALSE;
switch (g_Cursor.posIndex)
{
case HP_UP:
ShowBattleLog(MAX_HP_UP_LOG);
player->maxHP += 3;
break;
case MP_UP:
ShowBattleLog(MAX_MP_UP_LOG);
player->maxMP += 3;
break;
case ATK_UP:
ShowBattleLog(DAMAGE_UP_LOG);
player->atkPower += 2;
break;
case RECOVERALL:
ShowBattleLog(RECOVER_LOG);
player->hp = player->maxHP;
player->mp = player->maxMP;
break;
default:
break;
}
}
}
}
}
//=============================================================================
// 描画処理
//=============================================================================
void DrawBattleCursor(void)
{
BATTLEUI *battleUI = GetBattleUI();
if(battleUI->use && g_Cursor.canDoAction)
{
// 頂点バッファ設定
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 = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
SetMaterial(material);
// WMの背景を描画
{
// テクスチャ設定
GetDeviceContext()->PSSetShaderResources(0, 1, &g_Texture[g_Cursor.texNo]);
float px = g_Cursor.pos[g_Cursor.posIndex].x;
float py = g_Cursor.pos[g_Cursor.posIndex].y;
if (g_Cursor.mode == POWERUP_SELECT)
{
px = g_Cursor.powerUpPos[g_Cursor.posIndex].x;
py = g_Cursor.powerUpPos[g_Cursor.posIndex].y;
}
// 1枚のポリゴンの頂点とテクスチャ座標を設定
SetSpriteLTColor(g_VertexBuffer,
px, py, g_Cursor.w, g_Cursor.h,
0.0f, 0.0f, 1.0f, 1.0f,
D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f));
// ポリゴン描画
GetDeviceContext()->Draw(4, 0);
}
}
}
void SelectTargetEnemy(void)
{
BATTLE *battleEnemy = GetBattleEnemy();
g_Cursor.pos[0] = D3DXVECTOR3(battleEnemy->pos.x - 50.0f, battleEnemy->pos.y - 20.0f, 0.0f);
}
void SelectAlly(void)
{
BATTLE *battlePlayer = GetBattlePlayer();
g_Cursor.pos[0] = D3DXVECTOR3(battlePlayer->pos.x - 50.0f, battlePlayer->pos.y - 20.0f, 0.0f);
}
BATTLECURSOR *GetBattleCursor(void)
{
return &g_Cursor;
}