-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbattle.cpp
503 lines (391 loc) · 11.1 KB
/
battle.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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
/*******************************************************************************
* タイトル: Battleプログラム
* プログラム名: battle.cpp
* 作成者: GP11A132 21 Daya Juang Mahaputra
*******************************************************************************/
/*******************************************************************************
* インクルードファイル
*******************************************************************************/
#include "main.h"
#include "battle.h"
#include "battleUI.h"
#include "bg.h"
#include "damage.h"
#include "player.h"
#include "battleCursor.h"
#include "effect.h"
#include "bg.h"
#include "layer.h"
#include "bubble.h"
#include "limitBar.h"
#include "battleLog.h"
#include "actionBar.h"
#include "tutorial.h"
#include "sound.h"
/*******************************************************************************
* マクロ定義
*******************************************************************************/
/*******************************************************************************
* 構造体定義
*******************************************************************************/
/*******************************************************************************
* プロトタイプ宣言(こんな関数を用意してありますよ宣言/関数の説明書)
*******************************************************************************/
/*******************************************************************************
* グローバル変数
*******************************************************************************/
BATTLE g_BPlayer; // バトル用のプレイヤーワーク
BATTLE g_BEnemy; // バトル用のエネミーワーク
// 必要なオブジェクトのアドレスを取得
DAMAGE *damageScore = GetDamageAddress();
BATTLECURSOR *cursor = GetBattleCursor();
PLAYER *player = GetPlayer();
ENEMY *enemy = GetEnemy();
BG *bg = GetBG();
LAYER *layer = GetLayer();
static BOOL enemy_turn;
static int waitTurn;
static int playerOdd = 0;
static BOOL firstTime = TRUE;
// バトルの初期化処理
void InitBattle(void)
{
}
// バトルの終了処理
void UninitBattle(void)
{
}
// バトルの更新処理
void UpdateBattle(void)
{
TUTORIAL *tutorial = GetTutorial();
if (player[0].battleReady) // まだバトル中かどうか
{
if (firstTime)
{
firstTime = FALSE;
ShowTutorial(BATTLE_TUTORIAL1, BATTLE_TUTORIAL);
}
else if(!tutorial->use)
{
if (g_BPlayer.stop == FALSE && g_BPlayer.hp > 0 && g_BEnemy.hp > 0)
{
g_BPlayer.action += (0.1f * g_BPlayer.speed);
if (g_BPlayer.action >= ACTION_BAR_MAX - 3.0f)
{
g_BPlayer.action = ACTION_BAR_MAX - 3.0f;
cursor->canDoAction = TRUE;
}
else
{
cursor->canDoAction = FALSE;
}
}
if (g_BEnemy.stop == FALSE && g_BPlayer.hp > 0 && g_BEnemy.hp > 0)
{
g_BEnemy.action += (0.1f * g_BEnemy.speed);
}
if (g_BEnemy.action >= ACTION_BAR_MAX - 3.0f)
{
g_BEnemy.action = ACTION_BAR_MAX - 3.0f;
cursor->canDoAction = FALSE;
enemy_turn = TRUE;
}
else
{
enemy_turn = FALSE;
}
if (g_BEnemy.canDoAction && enemy_turn) // エネミーのターンなら
{
EnemyAttack();
waitTurn = 0;
}
}
}
#ifdef _DEBUG
// デバッグ表示
PrintDebugProc("PlayerAction:%f EnemyAction:%f \n", g_BPlayer.action, g_BEnemy.action);
#endif
}
// バトル描画処理
void DrawBattle(void)
{
}
// バトルする前に必要なデータを取得変数・準備
void SetBattle(int enemyNo)
{
BG *bg = GetBG();
// バトルプレイヤーのデータを登録
g_BPlayer.pos = player[0].battlePos - bg->pos;
g_BPlayer.hp = player[0].hp;
g_BPlayer.hp_max = player[0].maxHP;
g_BPlayer.mp = player[0].mp;
g_BPlayer.mp_max = player[0].maxMP;
g_BPlayer.atk = player[0].atkMin;
g_BPlayer.atk_max = player[0].atkMax;
g_BPlayer.use = player[0].use;
g_BPlayer.h = player[0].h;
g_BPlayer.w = player[0].w;
g_BPlayer.speed = player[0].speed;
g_BPlayer.action = player[0].actionTime;
g_BPlayer.roll = 0;
// バトルエネミーのデータを登録
g_BEnemy.pos = enemy[enemyNo].pos - bg->pos;
g_BEnemy.hp = enemy[enemyNo].hp;
g_BEnemy.hp_max = enemy[enemyNo].maxHP;
g_BEnemy.mp = enemy[enemyNo].mp;
g_BEnemy.mp_max = enemy[enemyNo].maxMP;
g_BEnemy.atk = enemy[enemyNo].atkMin;
g_BEnemy.atk_max = enemy[enemyNo].atkMax;
g_BEnemy.use = enemy[enemyNo].use;
g_BEnemy.exp = enemy[enemyNo].exp;
g_BEnemy.h = enemy[enemyNo].h;
g_BEnemy.w = enemy[enemyNo].w;
g_BEnemy.speed = enemy[enemyNo].speed;
g_BEnemy.action = enemy[enemyNo].action;
g_BEnemy.roll = 0;
g_BEnemy.canDoAction = TRUE;
g_BEnemy.stop = FALSE;
g_BPlayer.stop = FALSE;
g_BEnemy.enemyIndex = enemyNo;
waitTurn = 0; // ターンを待つ時間
}
// プレイヤーの攻撃関数
void PlayerAttack(void)
{
PLAYER *player = GetPlayer();
g_BPlayer.action = 0.0f;
g_BEnemy.stop = TRUE;
g_BPlayer.stop = TRUE;
g_BEnemy.canDoAction = FALSE;
cursor->canDoAction = FALSE;
cursor->posIndex = 0;
// 攻撃は当たるかどうか判断
g_BPlayer.roll = (1 + rand() % 6) + playerOdd;
g_BEnemy.roll = (1 + rand() % 6);
if (g_BPlayer.roll >= g_BEnemy.roll)
{
g_BPlayer.damage = g_BPlayer.atk + rand() % (g_BPlayer.atk_max - g_BPlayer.atk); // ダメージを取得
playerOdd = 0;
}
else
{
g_BPlayer.damage = 0;
playerOdd++;
}
// ダメージ表示を設定
SetDamage(g_BPlayer.damage);
SetDamageDigit(g_BPlayer.damage);
SetDamagePosition(g_BEnemy.pos);
// プレイヤーの攻撃アニメーション
player->idle = FALSE;
player->action = PLAYER_ATTACK;
SetBubble(g_BPlayer.pos, 0);
bg->r = bg->g = bg->b = layer->r = layer->g = layer->b = 0.2f;
g_BEnemy.hp -= g_BPlayer.damage; // エネミーがダメージを受ける
AddLimitBar(8); // プレイヤーのLIMITが8上がる
PlaySound(SOUND_LABEL_SE_swing);
}
// エネミーの攻撃
void EnemyAttack(void)
{
EFFECT *effect = GetEffect();
g_BEnemy.action = 0.0f;
g_BPlayer.stop = TRUE;
g_BEnemy.stop = TRUE;
cursor->canDoAction = FALSE;
// 攻撃は当たるかどうか判断
g_BPlayer.roll = (1 + rand() % 6);
g_BEnemy.roll = (1 + rand() % 6);
if (g_BEnemy.roll >= g_BPlayer.roll)
g_BEnemy.damage = g_BEnemy.atk + rand() % (g_BEnemy.atk_max - g_BEnemy.atk); // ダメージを取得
else
g_BEnemy.damage = 0;
// ダメージ表示を設定
SetDamage(g_BEnemy.damage);
SetDamageDigit(g_BEnemy.damage);
SetDamagePosition(g_BPlayer.pos);
SetBubble(g_BEnemy.pos, 0);
bg->r = bg->g = bg->b = layer->r = layer->g = layer->b = 0.2f;
// エフェクトを設定
SetEffect(g_BPlayer.pos, ENEMY_ATTACK_EFFECT);
ShowDamage();
g_BPlayer.hp -= g_BEnemy.damage; // プレイヤーがダメージを受ける
AddLimitBar(4); // プレイヤーのLIMITが4上がる
}
void PlayerLimitBreak(void)
{
PLAYER *player = GetPlayer();
g_BPlayer.action = 0.0f;
g_BEnemy.stop = TRUE;
g_BPlayer.stop = TRUE;
cursor->canDoAction = FALSE;
cursor->posIndex = 0;
int baseDamage = 50*player->level; // ベースダメージ
player->limitBreak = 0;
// ダメージを取得
g_BPlayer.damage = g_BPlayer.atk + rand() % (g_BPlayer.atk_max - g_BPlayer.atk) + baseDamage;
// ダメージ表示を設定
SetDamage(g_BPlayer.damage);
SetDamageDigit(g_BPlayer.damage);
SetDamagePosition(g_BEnemy.pos);
// プレイヤーのアニメーション
player->idle = FALSE;
player->action = PLAYER_LIMIT_BREAK;
bg->r = bg->g = bg->b = layer->r = layer->g = layer->b = 0.2f;
g_BEnemy.hp -= g_BPlayer.damage;
}
// プレイヤーの火球の技
void FireBall(void)
{
PLAYER *player = GetPlayer();
g_BPlayer.action = 0.0f;
g_BEnemy.stop = TRUE;
g_BPlayer.stop = TRUE;
cursor->canDoAction = FALSE;
cursor->posIndex = 0;
int mpNeeded = 6; // 必要なMP
int baseDamage = 10; // ベースダメージ
// ダメージを取得
g_BPlayer.damage = g_BPlayer.atk + rand() % (g_BPlayer.atk_max - g_BPlayer.atk) + baseDamage;
g_BPlayer.mp -= mpNeeded;
// ダメージ表示を設定
SetDamage(g_BPlayer.damage);
SetDamageDigit(g_BPlayer.damage);
SetDamagePosition(g_BEnemy.pos);
SetBubble(g_BPlayer.pos, 1);
// プレイヤーのアニメーション
player->idle = FALSE;
player->action = PLAYER_CAST_FIREBALL;
bg->r = bg->g = bg->b = layer->r = layer->g = layer->b = 0.2f;
g_BEnemy.hp -= g_BPlayer.damage;
AddLimitBar(8);
}
// プレイヤーのキュア技
void Cure(void)
{
PLAYER *player = GetPlayer();
g_BPlayer.action = 0.0f;
g_BEnemy.stop = TRUE;
g_BPlayer.stop = TRUE;
cursor->canDoAction = FALSE;
cursor->posIndex = 0;
int mpNeeded = 10;
int baseDamage = 15;
g_BPlayer.damage = g_BPlayer.atk + rand() % (g_BPlayer.atk_max - g_BPlayer.atk) + baseDamage;
g_BPlayer.mp -= mpNeeded;
// ダメージ表示を設定
SetDamage(g_BPlayer.damage);
SetDamageDigit(g_BPlayer.damage);
SetDamagePosition(g_BPlayer.pos);
SetBubble(g_BPlayer.pos, 2);
// プレイヤーの攻撃アニメーション
player->idle = FALSE;
player->action = PLAYER_CAST_HEAL;
bg->r = bg->g = bg->b = layer->r = layer->g = layer->b = 0.2f;
g_BPlayer.hp += g_BPlayer.damage;
if (g_BPlayer.hp > g_BPlayer.hp_max)
g_BPlayer.hp = g_BPlayer.hp_max;
AddLimitBar(8);
}
// プレイヤーの逃げる関数
void EscapeCheck(void)
{
int chance = 50; // 逃げるの確率
int flee = rand() % 100;
g_BEnemy.stop = g_BPlayer.stop = TRUE;
cursor->canDoAction = FALSE;
// 逃げられますか
if (flee > chance)
{
// YESだったら、バトルが終わる
ShowBattleLog(ESSCAPE_SUCCESS);
}
else
{
// NO だったら、エネミーのターンになる
ShowBattleLog(ESCAPE_FAIL);
}
}
void Escape(int isSuccess)
{
BATTLEUI *battleUI = GetBattleUI();
g_BPlayer.action = 0.0f;
if (isSuccess == ESSCAPE_SUCCESS)
{
player->hp = g_BPlayer.hp;
player->mp = g_BPlayer.mp;
enemy[g_BEnemy.enemyIndex].hp = 0;
enemy[g_BEnemy.enemyIndex].mode = ENEMY_MODE_PATROL;
battleUI->use = FALSE;
BattleEnd();
}
else
{
g_BEnemy.stop = FALSE;
g_BPlayer.stop = FALSE;
}
}
// 技を使う前にプレイヤーのMPをチェック
BOOL CheckMP(int mpToCheck)
{
if (g_BPlayer.mp >= mpToCheck)
{
return TRUE; // 足りる
}
return FALSE; // 足りない
}
// バトルのチェック関数
void CheckBattleResult(void)
{
BATTLEUI *battleUI = GetBattleUI();
// バトルが終わるかどうか
if (g_BPlayer.hp <= 0)
{
battleUI->use = FALSE;
g_BPlayer.hp = 0;
player->hp = g_BPlayer.hp;
return;
}
else if (g_BEnemy.hp <= 0)
{
battleUI->use = FALSE;
StopSound();
PlaySound(SOUND_LABEL_SE_victory);
// プレイヤーのHPとMP戻す
player->hp = g_BPlayer.hp;
player->mp = g_BPlayer.mp;
player->currentExp += g_BEnemy.exp;
player->currentExp += g_BEnemy.exp;
if (player->currentExp >= player->expToNextLevel)
{
LevelUp();
}
enemy[g_BEnemy.enemyIndex].hp = 0;
enemy[g_BEnemy.enemyIndex].mode = ENEMY_MODE_PATROL;
ShowBattleLog(ENEMY_KILLED);
return;
}
g_BEnemy.canDoAction = TRUE;
}
void BattleEnd(void)
{
BATTLEUI *battleUI = GetBattleUI();
player->mode = PLAYER_MODE_EXPLORE;
player->idle = TRUE;
player->battleReady = FALSE;
player->texNo = 0;
StopSound();
if(bg->texNo == FOREST)
PlaySound(SOUND_LABEL_BGM_forest);
else
PlaySound(SOUND_LABEL_BGM_dungeon);
}
BATTLE *GetBattlePlayer(void)
{
return &g_BPlayer;
}
BATTLE *GetBattleEnemy(void)
{
return &g_BEnemy;
}