-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApple.cpp
369 lines (313 loc) · 9.13 KB
/
Apple.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
/************************************************
* りんごの処理プログラム
* 制作:豊元、新里
************************************************/
#include "DxLib.h"
#include "resourceLoad.h"
#include "Apple.h"
#include "player.h"
#include<string>
/************************************************
* 変数の宣言
************************************************/
int gFPSCount = 0;
using std::string;
using std::to_string;
int AppleBlinkFlg;
/************************************************
* 初期化
************************************************/
void Apple::AppleInit()
{
for (int i = 0; i < APPLE_MAX; i++) {
gApple[i].flg = FALSE;
gApple[i].img = 0;
gApple[i].x = 0;
gApple[i].y = 0;
gApple[i].w = 0;
gApple[i].h = 0;
gApple[i].speed = 0;
gApple[i].point = 0;
}
}
/************************************************
* りんごのカウント、スコア
************************************************/
void AppleCount::AppleMainInit(int RACount, int BACount, int GACount, int PACount, int Score)
{
gRACount = RACount;
gBACount = BACount;
gGACount = GACount;
gPACount = PACount;
gScore = Score;
}
/************************************************
* リンゴ落下処理
************************************************/
void Apple::FallApple()
{
for (int i = 0; i < APPLE_MAX; i++) {
if (gApple[i].flg == TRUE) {
//リンゴの表示
DrawRotaGraph((int)gApple[i].x, (int)gApple[i].y, 0.19, 0, gApple[i].img, TRUE);
//真っすぐ下に移動
gApple[i].y += gApple[i].speed;
//りんごの座標が1000になったらりんごをけす
if (gApple[i].y > 1000 + gApple[i].h) {
gApple[i].flg = FALSE;
}
}
}
if ((gFPSCount++) % 25 == 0) {//25フレームごとに生成されるりんごの数をチェック
CreateApple();
HitBox();
}
}
/************************************************
* リンゴ生成&確率
************************************************/
int Apple::CreateApple()
{
//りんご確率
int AppleImg = Image::GetImages(IMG_APPLE, 0);
gP = GetRand(99);//100%
if (gP < 59) {
AppleImg = Image::GetImages(IMG_APPLE, REDAPPLE); //赤リンゴ
}
else if (gP >= 60 && gP < 84) {
AppleImg = Image::GetImages(IMG_APPLE, BLUEAPPLE); //青リンゴ
}
else if (gP >= 85 && gP < 94) {
AppleImg = Image::GetImages(IMG_APPLE, GOLDAPPLE); //金リンゴ
}
else if (gP >= 95 && gP < 99) {
AppleImg = Image::GetImages(IMG_APPLE, POISONAPPLE); //毒リンゴ
}
for (int i = 0; i < APPLE_MAX; i++) {
if (gApple[i].flg == FALSE) {
gApple[i].img = AppleImg; //リンゴの画像
gApple[i].x = 70 + (GetRand(6) * 130); //りんごのレーン決定
gApple[i].y = -50; //リンゴの初期Y座標
AppleSpeed(i); //リンゴの速度6
gApple[i].flg = TRUE;
//成功
return TRUE;
}
}
//失敗
return FALSE;
}
/************************************************
* リンゴの速度
************************************************/
void Apple::AppleSpeed(int i)
{
if (gApple[i].img == Image::GetImages(IMG_APPLE, REDAPPLE)) {
gApple[i].speed = 1;//赤リンゴ
}
else if (gApple[i].img == Image::GetImages(IMG_APPLE, BLUEAPPLE)) {
gApple[i].speed = 2;//青リンゴ
}
else if (gApple[i].img == Image::GetImages(IMG_APPLE, GOLDAPPLE)) {
gApple[i].speed = 3.5;//金リンゴ
}
else if (gApple[i].img == Image::GetImages(IMG_APPLE, POISONAPPLE)) {
gApple[i].speed = 0.5;//毒リンゴ
}
}
/************************************************
* りんごの当たり判定
************************************************/
int Apple::HitBox()
{
double sx1[10];
double sy1[10];
double sx2[10];
double sy2[10];
for (int i = 0; i < 10; i++) {
if (gApple[i].flg == TRUE) {
sx1[i] = gApple[i].x - 31; //左上 X
sy1[i] = gApple[i].y - 60; //左上 Y
sx2[i] = gApple[i].x + 31; //右下 X
sy2[i] = gApple[i].y + 60; //右下 Y
}
}
for (int i = 0; i < APPLE_MAX; i++) {
if (gApple[i].flg == TRUE) {
for (int j = 0; j < APPLE_MAX; j++) {
if (sx1[i] == sx1[j] && sx2[j] == sx2[i] && sy1[i] < sy1[j] && sy1[j] < sy2[i]) {
if (gApple[i].img == gApple[j].img) {
gApple[i].flg = FALSE; //削除
}
}
}
}
}
return 0;
}
/******************************************************
* プレイヤーの当たり判定&プレイヤーとりんごの接触処理
******************************************************/
int Apple::HitBoxPlayer() {
double sx1[10];
double sy1[10];
double sx2[10];
double sy2[10];
for (int i = 0; i < 10; i++) {
if (gApple[i].img == Image::GetImages(IMG_APPLE, POISONAPPLE)) {//毒りんごの当たり判定
if (gApple[i].flg == TRUE) {
sx1[i] = gApple[i].x - 40; //左上 X
sy1[i] = gApple[i].y - 37; //左上 Y
sx2[i] = gApple[i].x + 40; //右下 X
sy2[i] = gApple[i].y + 37; //右下 Y
}
}
else { //毒りんご以外の当たり判定
if (gApple[i].flg == TRUE) {
sx1[i] = gApple[i].x - 46; //左上 X
sy1[i] = gApple[i].y - 43; //左上 Y
sx2[i] = gApple[i].x + 46; //右下 X
sy2[i] = gApple[i].y + 43; //右下 Y
}
}
}
if (GetBlinkFlg() == 0) { //点滅中は当たらないように
for (int i = 0; i < 10; i++) {
if (gApple[i].flg == TRUE) {
if (px1 < sx2[i] && sx1[i] < px2 && py1 < sy2[i] && sy1[i] < py2) {
if (gApple[i].img == Image::GetImages(IMG_APPLE, POISONAPPLE)) {
//player.SetPlayerBlinkFlg(1);
SetBlinkFlg(1);
}
gApple[i].flg = FALSE; //削除
ApplePoint(i);//スコア処理
}
}
}
}
//プレイヤーとりんごが接触したらりんごが消える
for (int i = 0; i < 10; i++) {
if (gApple[i].flg == TRUE) {
if (px1 < sx2[i] && sx1[i] < px2 && py1 < sy2[i] && sy1[i] < py2) {
if (gApple[i].img == Image::GetImages(IMG_APPLE,POISONAPPLE)) {
SetBlinkFlg(1);
}
}
}
}
std::string str1 = std::to_string(AppleCount::ReturnRA());
std::string str2 = std::to_string(AppleCount::ReturnBL());
std::string str3 = std::to_string(AppleCount::ReturnGL());
DrawStringToHandle(1020, 400, str1.c_str(), 0x000000, Font::GetFonts(FONT_1_64), 0xffffff);
DrawStringToHandle(1120, 400, str2.c_str(), 0x000000, Font::GetFonts(FONT_1_64), 0xffffff);
DrawStringToHandle(1225, 400, str3.c_str(), 0x000000, Font::GetFonts(FONT_1_64), 0xffffff);
return 0;
}
/************************************************
* りんごのスコア処理
************************************************/
void Apple::ApplePoint(int i)
{
if (gApple[i].img == Image::GetImages(IMG_APPLE, REDAPPLE)) {//赤りんご
AppleCount::SetScore(100);
AppleCount::SetRA(1);
PlaySoundMem(Sound::GetSounds(SND_SE_APPLE), DX_PLAYTYPE_BACK, TRUE);
}
if (gApple[i].img == Image::GetImages(IMG_APPLE, BLUEAPPLE)) {//青りんご
AppleCount::SetScore(200);
AppleCount::SetBL(1);
PlaySoundMem(Sound::GetSounds(SND_SE_APPLE), DX_PLAYTYPE_BACK, TRUE);
}
if (gApple[i].img == Image::GetImages(IMG_APPLE, GOLDAPPLE)) {//金りんご
AppleCount::SetScore(500);
AppleCount::SetGL(1);
PlaySoundMem(Sound::GetSounds(SND_SE_APPLE), DX_PLAYTYPE_BACK, TRUE);
}
if (gApple[i].img == Image::GetImages(IMG_APPLE, POISONAPPLE)) {//毒りんご
AppleCount::SetScore(-750);
AppleCount::SetPO(1);
if (AppleCount::ReturnScore() < 0) {
AppleCount::ZeroScore();
}
PlaySoundMem(Sound::GetSounds(SND_SE_POISON), DX_PLAYTYPE_BACK, TRUE);
}
}
/************************************************
* その他関数
************************************************/
int Apple::ReturnAppleX(int num) {
return (int)gApple[num].x;
}
int Apple::ReturnAppleY(int num) {
return (int)gApple[num].y;
}
int Apple::ReturnAppleImg(int num) {
return gApple[num].img;
}
int Apple::ReturnAppleFlg(int num) {
return gApple[num].flg;
}
void Apple::GetPlayerX(int xPos) {
px1 = xPos - 30;
px2 = xPos + 30;
}
void Apple::GetPlayerY(int yPos) {
py1 = yPos - 90;
py2 = yPos + 120;
}
int Apple::GetBlinkFlg() {
return AppleBlinkFlg;
}
int Apple::SetBlinkFlg(int flg) {
AppleBlinkFlg = flg;
return AppleBlinkFlg;
}
void Apple::DrawPause() {
std::string str1 = std::to_string(AppleCount::ReturnRA());
std::string str2 = std::to_string(AppleCount::ReturnBL());
std::string str3 = std::to_string(AppleCount::ReturnGL());
DrawStringToHandle(1020, 400, str1.c_str(), 0x000000, Font::GetFonts(FONT_1_64), 0xffffff);
DrawStringToHandle(1120, 400, str2.c_str(), 0x000000, Font::GetFonts(FONT_1_64), 0xffffff);
DrawStringToHandle(1225, 400, str3.c_str(), 0x000000, Font::GetFonts(FONT_1_64), 0xffffff);
}
/************************************************
* AppleCountClass
************************************************/
int AppleCount::gRACount = 0;
int AppleCount::gBACount = 0;
int AppleCount::gGACount = 0;
int AppleCount::gPACount = 0;
int AppleCount::gScore = 0;
int AppleCount::ReturnRA() {
return gRACount;
}
int AppleCount::ReturnBL() {
return gBACount;
}
int AppleCount::ReturnGL() {
return gGACount;
}
int AppleCount::ReturnPO() {
return gPACount;
}
int AppleCount::ReturnScore() {
return (int)gScore;
}
void AppleCount::SetRA(int num) {
gRACount += num;
}
void AppleCount::SetBL(int num) {
gBACount += num;
}
void AppleCount::SetGL(int num) {
gGACount += num;
}
void AppleCount::SetPO(int num) {
gPACount += num;
}
void AppleCount::SetScore(int num) {
gScore += num;
}
void AppleCount::ZeroScore() {
gScore = 0;
}