-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBattle.cpp
188 lines (155 loc) · 3.72 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
#include "Battle.h"
#include <DxLib.h>
#include "Keyboard.h"
#include "Chara.h"
#include "Player.h"
#include "BalletMgr.h"
#include "EnemyMgr.h"
#include "SceneManager.h"
#include "Other.h"
int image_bg_ba;
int image_end;
int image_clear;
int player_imageSize;
int ballet_imageSize;
int enemy_imageSize;
Player *player;
BalletMgr *balletMgr;
EnemyMgr *enemyMgr;
eName is_Insted[BALLET_MAX];
Enemy **enemyobj;
Ballet **balletobj;
int p_width, p_height;
int e_width, e_height;
int b_width, b_height;
int fontHandle_Battle;
double limit;
int score;
void Battle_init()
{
image_bg_ba = LoadGraph("画像/背景.png");
image_end = LoadGraph("画像/終了.png");
image_clear = LoadGraph("画像/クリア.png");
player = new Player;
balletMgr = new BalletMgr;
enemyMgr = new EnemyMgr;
enemyobj = enemyMgr->Get_enemychild();
balletobj = balletMgr->Get_balletchild();
GetGraphSize(*(player->Get_ptrimageHandle()), &p_width, &p_height);
GetGraphSize(*(enemyMgr->Get_ptrimageHandle()), &e_width, &e_height);
GetGraphSize(*(balletMgr->Get_ptrimageHandle()), &b_width, &b_height);
fontHandle_Battle = CreateFontToHandle(NULL, 64, 7, DX_FONTTYPE_ANTIALIASING_EDGE_4X4);
limit = TIMELIMIT;
score = 0;
}
void Battle_Update() {
limit -= Timecount_return();
balletMgr->Update();
enemyMgr->Update();
if (!player->Death_is_true())
{
player->Update();
}
Collision();
if (Get_key(KEY_INPUT_ESCAPE) == 1) {
SceneChange(Title);
}
if (Get_key(KEY_INPUT_RETURN) == 2 && limit < 0)
{
SceneChange(Title);
}
}
void Battle_Draw()
{
DrawGraph(0, 0, image_bg_ba, true);
if (limit >= 0) {
balletMgr->Draw();
enemyMgr->Draw();
DrawFormatStringFToHandle(0, 0, GetColor(255, 255, 255), fontHandle_Battle, "%.2f", limit / 1000);
}
else
{
DrawGraph(0, 0, image_clear, true);
}
if (!player->Death_is_true())
{
player->Draw();
}
else
{
DrawGraph(0, 0, image_end, true);
}
DrawFormatStringFToHandle(SET_SCREENSIZE_X * 0.867, 0, GetColor(255, 255, 255), fontHandle_Battle, "%5d", score);
}
void Battle_End()
{
DeleteGraph(image_bg_ba);
DeleteGraph(image_end);
DeleteGraph(image_clear);
delete balletMgr;
delete enemyMgr;
delete player;
DeleteFontToHandle(fontHandle_Battle);
}
void Ballet_Inst(const VECTOR &pos_battlefunc, const eName &name_battlefunc)
{
balletMgr->Instance_Ballet(pos_battlefunc, name_battlefunc);
}
VECTOR Playerpos_return()
{
return player->Get_pos();
}
void Collision()
{
for (int i = 0; i < BALLET_MAX; i++)
{
if (balletobj[i] != NULL)
{
switch (balletobj[i]->Get_isInsted())
{
case eEnemy: {
if (Collision_child(player->Get_pos(), balletobj[i]->Get_pos(NULL), p_width, b_width, p_height, b_height))
{
player->Damage();
balletobj[i]->Damage();
}
}
break;
case ePlayer: {
for (int j = 0; j < ENEMY_MAX; j++)
{
if (enemyobj[j] != NULL) {
if (Collision_child(enemyobj[j]->Get_pos(), balletobj[i]->Get_pos(NULL), e_width, b_width, e_height, b_height))
{
enemyobj[j]->Damage();
balletobj[i]->Damage();
Score_Plus();
}
}
}
}
break;
default:
break;
}
}
}
}
bool Collision_child(const VECTOR &pos1, const VECTOR &pos2, const int &pos1_width, const int &pos2_width, const int &pos1_height, const int &pos2_height)
{
if (((pos2.x < pos1.x && pos1.x < pos2.x + pos2_width)
|| (pos1.x < pos2.x && pos2.x < pos1.x + pos1_width))
&& ((pos2.y < pos1.y && pos1.y < pos2.y + pos2_height)
|| (pos1.y < pos2.y && pos2.y < pos1.y + pos1_height)))
{
return true;
}
else
{
return false;
}
}
void Score_Plus()
{
score += 100;
}