-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cpp
473 lines (403 loc) · 12.6 KB
/
Player.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
#include "../headers/Player.h"
Player::Player()
{
// 画像・フォントハンドル
background_handle = LoadGraph("images/Back_Cyber_1920.jpg");
index_font = CreateFontToHandle("ニコ角", 25, 1, DX_FONTTYPE_ANTIALIASING);
figure_font = CreateFontToHandle("ニコ角", 40, 1, DX_FONTTYPE_ANTIALIASING);
// 各種サウンド
sound.add("move", "sounds/カーソル移動2.mp3");
sound.add("rotate", "sounds/決定、ボタン押下35.mp3");
sound.add("hold", "sounds/決定、ボタン押下40.mp3");
sound.add("drop", "sounds/カーソル移動7.mp3");
sound.add("levelup", "sounds/魔王魂 効果音 ワンポイント11.mp3");
sound.changeAllSoundVolume(70);
sound.changeVolume("rotate", 60);
// 座標
x = 380, y = 50;
gnrt_mx = FIELD_SIDE_X / 2, gnrt_my = 4;
pre_mino_coordx = gnrt_mx;
pre_mino_coordy = gnrt_my;
// スコア・難易度
level = 1;
score = 0;
ren_num = 0;
drop_speed = 60;
// オートリピート
t = -1;
lockdown_count = 0;
autorepeat_count = 0;
isautorepeat = false;
// mino生成
new_gnrt_mino = 0;
isbottom = false;
can_generate = false;
can_transcribe = false;
can_incrrow = false;
// ライン削除
erase_linenum = 0;
sum_linenum = 0;
levelup_count = 0;
// ホールド
hold_mino_num = -1;
hold_enable = true;
field = new Field(x, y - BLOCK_SIZE * 5);
mino = new Mino(field);
ghost_mino = new Mino(field);
hold_mino = new StaticMino(x - STATIC_BLOCK_SIZE * 4, y + STATIC_BLOCK_SIZE * 1.5 + 10);
for (int i = 0; i < NEXT_REFER_SIZE; i++) {
next_mino[i] = new StaticMino(x + FIELD_SIDE_X * BLOCK_SIZE + 70, y + i * STATIC_BLOCK_SIZE * 2.8 + 35);
}
}
Player::Player(int x, int y)
{
// 画像・フォントハンドル
background_handle = LoadGraph("images/Back_Cyber_1920.jpg");
index_font = CreateFontToHandle("ニコ角", 25, 1, DX_FONTTYPE_ANTIALIASING);
figure_font = CreateFontToHandle("ニコ角", 40, 1, DX_FONTTYPE_ANTIALIASING);
// 各種サウンド
sound.add("move", "sounds/カーソル移動2.mp3");
sound.add("rotate", "sounds/決定、ボタン押下35.mp3");
sound.add("hold", "sounds/決定、ボタン押下40.mp3");
sound.add("drop", "sounds/カーソル移動7.mp3");
sound.add("levelup", "sounds/魔王魂 効果音 ワンポイント11.mp3");
sound.changeAllSoundVolume(70);
sound.changeVolume("rotate", 60);
// 座標
this->x = x, this->y = y;
gnrt_mx = FIELD_SIDE_X / 2, gnrt_my = 4;
pre_mino_coordx = gnrt_mx;
pre_mino_coordy = gnrt_my;
// スコア・難易度
level = 1;
score = 0;
ren_num = 0;
drop_speed = 60;
// オートリピート
t = -1;
lockdown_count = 0;
autorepeat_count = 0;
isautorepeat = false;
// mino生成
new_gnrt_mino = 0;
isbottom = false;
can_generate = false;
can_transcribe = false;
can_incrrow = false;
// ライン削除
erase_linenum = 0;
sum_linenum = 0;
levelup_count = 0;
// ホールド
hold_mino_num = -1;
hold_enable = true;
field = new Field(x, y - BLOCK_SIZE * 5);
mino = new Mino(field);
ghost_mino = new Mino(field);
hold_mino = new StaticMino(x - STATIC_BLOCK_SIZE * 4, y + STATIC_BLOCK_SIZE * 1.5 + 10);
for (int i = 0; i < NEXT_REFER_SIZE; i++) {
next_mino[i] = new StaticMino(x + FIELD_SIDE_X * BLOCK_SIZE + 70, y + i * STATIC_BLOCK_SIZE * 2.8 + 35);
}
}
void Player::initialize()
{
// 主要クラス
mino->initialize();
field->InitField();
row.initialize();
ghost_mino->initialize();
hold_mino->initialize();
for (int i = 0; i < NEXT_REFER_SIZE; i++) {
next_mino[i]->initialize();
}
// 難易度
level = 1;
score = 0;
ren_num = 0;
drop_speed = 60;
// オートリピート
t = -1;
lockdown_count = 0;
autorepeat_count = 0;
isautorepeat = false;
// mino生成
new_gnrt_mino = 0;
isbottom = false;
can_generate = false;
can_transcribe = false;
can_incrrow = false;
// ライン消去
erase_linenum = 0;
sum_linenum = 0;
levelup_count = 0;
// ホールド
hold_mino_num = -1;
hold_enable = true;
}
void Player::startProcess()
{
mino->generateMinoWithPos(row.getMinoNum(0), gnrt_mx, gnrt_my);
row.increase();
}
void Player::update()
{
installMino();
controlMino();
dropMino();
holdMino();
makeGhost();
setNext();
t++;
}
void Player::controlMino()
{
//左右移動操作
//PAD PAD_LEFT
if (Key[KEY_INPUT_A] >= 1) {
if (mino->getMinoCoordX() != pre_mino_coordx && mino->getMinoCoordY() != pre_mino_coordy)
lockdown_count = 0;
if (autorepeat_count == 0) {
if (!mino->collisionField(-1, 0)) {
mino->moveMino(-1, 0);
sound.play("move", DX_PLAYTYPE_BACK);
}
autorepeat_count++;
}
else if (isautorepeat && t % 3 == 0) {
if (!mino->collisionField(-1, 0)) {
mino->moveMino(-1, 0);
sound.play("move", DX_PLAYTYPE_BACK);
}
}
else if (autorepeat_count == 9) {
isautorepeat = true;
}
else {
autorepeat_count++;
}
}
//PAD PAD_RIGHT
if (Key[KEY_INPUT_D] >= 1) {
if(mino->getMinoCoordX() != pre_mino_coordx && mino->getMinoCoordY() != pre_mino_coordy)
lockdown_count = 0;
if (autorepeat_count == 0) {
if (!mino->collisionField(1, 0)) {
mino->moveMino(1, 0);
sound.play("move", DX_PLAYTYPE_BACK);
}
autorepeat_count++;
}
else if (isautorepeat && t % 3 == 0) {
if (!mino->collisionField(1, 0)) {
mino->moveMino(1, 0);
sound.play("move", DX_PLAYTYPE_BACK);
}
}
else if (autorepeat_count == 9) {
isautorepeat = true;
}
else {
autorepeat_count++;
}
}
//回転操作(SRS付き)
//PAD PAD_4
if (Key[KEY_INPUT_L] == 1)
{
mino->rotateMinoWithCollision(true);
sound.play("rotate", DX_PLAYTYPE_BACK);
lockdown_count = 0;
}
//PAD PAD_3
if (Key[KEY_INPUT_K] == 1)
{
mino->rotateMinoWithCollision(false);
sound.play("rotate", DX_PLAYTYPE_BACK);
lockdown_count = 0;
}
if (!CheckHitKeyAll(DX_CHECKINPUT_KEY)) {
autorepeat_count = 0;
isautorepeat = false;
}
}
void Player::dropMino()
{
//PAD PAD_UP
if (Key[KEY_INPUT_W] == 1) { //ハードドロップ
mino->dropToMaxBottom();
new_gnrt_mino = row.getMinoNum(0);
can_generate = true;
can_transcribe = true;
can_incrrow = true;
hold_enable = true;
}//PAD PAD_DOWN
else if (Key[KEY_INPUT_S] >= 1 && t % 3 == 0) { //ソフトドロップ
if (!mino->collisionField(0, 1)) {
mino->moveMino(0, 1);
sound.play("move", DX_PLAYTYPE_BACK);
}
else {
isbottom = true;
}
}
else if (t % drop_speed == 0) { //ナチュラルドロップ
if (!mino->collisionField(0, 1)) {
mino->moveMino(0, 1);
isbottom = false;
}
else {
isbottom = true;
pre_mino_coordx = mino->getMinoCoordX();
pre_mino_coordy = mino->getMinoCoordY();
}
}
if (isbottom) {
if (lockdown_count == 30) {
new_gnrt_mino = row.getMinoNum(0);
can_generate = true;
can_transcribe = true;
can_incrrow = true;
hold_enable = true;
lockdown_count = 0;
isbottom = false;
}
else if (!mino->collisionField(0, 1)) {
can_generate = false;
can_transcribe = false;
can_incrrow = false;
lockdown_count = 0;
isbottom = false;
}
else {
lockdown_count++;
}
}
}
void Player::holdMino()
{
//PAD Key[PAD_5] == 1 || Key[PAD_7] == 1
if (Key[KEY_INPUT_SPACE] && hold_enable) {
sound.play("hold", DX_PLAYTYPE_BACK);
if (hold_mino_num == -1) {
hold_mino_num = mino->getMinoNum();
hold_mino->generateMino(hold_mino_num);
new_gnrt_mino = row.getMinoNum(0);
can_generate = true;
can_transcribe = false;
can_incrrow = true;
}
else {
int tmp_mino_num = hold_mino_num;
hold_mino_num = mino->getMinoNum();
hold_mino->generateMino(hold_mino_num);
new_gnrt_mino = tmp_mino_num;
can_generate = true;
can_transcribe = false;
can_incrrow = false;
}
hold_enable = false;
}
}
void Player::makeGhost()
{
*ghost_mino = *mino;
ghost_mino->dropToMaxBottom();
}
void Player::setNext()
{
for (int i = 0; i < NEXT_REFER_SIZE; i++) {
next_mino[i]->generateMino(row.getMinoNum(i));
}
}
int Player::calcScore(int _level, int _drop_speed)
{
int _score = 0;
int tmp_erase_linenum = erase_linenum;
erase_linenum = field->LineEraseAndShift();
if (tmp_erase_linenum != 0 && erase_linenum != 0)
ren_num++;
int drop_score = (20 * _drop_speed / 60 - t / 60);
int line_score = _level * 100 * erase_linenum;
_score = (drop_score + line_score) * (ren_num + 1);
return _score;
}
void Player::levelControl()
{
int tmp_level = level;
sum_linenum += erase_linenum;
level = sum_linenum / 10 + 1;
if (level != tmp_level) {
sound.play("levelup", DX_PLAYTYPE_BACK);
if (drop_speed != 1) {
drop_speed /= 1.5;
}
}
}
void Player::installMino()
{
if (can_generate){
if (can_transcribe) {
sound.play("drop", DX_PLAYTYPE_BACK);
mino->transcribeMinoToField();
}
mino->generateMinoWithPos(new_gnrt_mino, gnrt_mx, gnrt_my);
if(can_incrrow)row.increase();
score += calcScore(level, drop_speed);
levelControl();
erase_linenum = 0;
can_generate = false;
can_transcribe = false;
can_incrrow = false;
t = 0;
}
}
int Player::judgeGameResult()
{
if (field->containMino(gnrt_mx, gnrt_my) || field->containMino(gnrt_mx + 1, gnrt_my)) {
return -1;
}
else if (sum_linenum >= max_linenum) {
return 1;
}
return 0;
}
void Player::draw()
{
DrawGraph(0, 0, background_handle, TRUE);
int drx = x - STATIC_BLOCK_SIZE * 5, dry = y;
DrawRoundRect(drx, dry, drx + STATIC_BLOCK_SIZE * 5 + 10, dry + STATIC_BLOCK_SIZE * 4 + 10, 10, 10, GetColor(0, 0, 0), TRUE);
drx = x + FIELD_SIDE_X * BLOCK_SIZE + 50, dry = y;
DrawRoundRect(drx, dry, drx + STATIC_BLOCK_SIZE * 5 + 10, dry + STATIC_BLOCK_SIZE * 6 * 3, 10, 10, GetColor(0, 0, 0), TRUE);
field->drawField();
ghost_mino->draw(false);
mino->draw(true);
if(hold_enable)
hold_mino->draw(true);
else
hold_mino->draw(true, 100);
for (int i = 0; i < NEXT_REFER_SIZE; i++) {
next_mino[i]->draw(true);
}
DrawStringToHandle(x - STATIC_BLOCK_SIZE * 5 + 5, y + 5, "HOLD", GetColor(255, 255, 255), index_font);
DrawStringToHandle(x + FIELD_SIDE_X * BLOCK_SIZE + 50 + 5, y + 5, "NEXT", GetColor(255, 255, 255), index_font);
DrawStringToHandle(x + FIELD_SIDE_X * BLOCK_SIZE + 50, y + STATIC_BLOCK_SIZE * 6 * 3, "SCORE", GetColor(255, 255, 255), index_font);
DrawFormatStringToHandle(x + FIELD_SIDE_X * BLOCK_SIZE + 70, y + STATIC_BLOCK_SIZE * 6 * 3 + 20, GetColor(255, 255, 255), figure_font, "%d", score);
DrawStringToHandle(x + FIELD_SIDE_X * BLOCK_SIZE + 50, y + STATIC_BLOCK_SIZE * 6 * 3 + 60, "HIGH SCORE", GetColor(255, 255, 255), index_font);
//DrawFormatStringToHandle(x + FIELD_SIDE_X * BLOCK_SIZE + 70, y + STATIC_BLOCK_SIZE * 6 * 3 + 80, GetColor(255, 255, 255), figure_font, "%d", highscore);
DrawStringToHandle(x + FIELD_SIDE_X * BLOCK_SIZE + 50, y + STATIC_BLOCK_SIZE * 6 * 3 + 120, "LEVEL", GetColor(255, 255, 255), index_font);
DrawFormatStringToHandle(x + FIELD_SIDE_X * BLOCK_SIZE + 70, y + STATIC_BLOCK_SIZE * 6 * 3 + 140, GetColor(255, 255, 255), figure_font, "%d", level);
DrawStringToHandle(x + FIELD_SIDE_X * BLOCK_SIZE + 50, y + STATIC_BLOCK_SIZE * 6 * 3 + 180, "LINES", GetColor(255, 255, 255), index_font);
DrawFormatStringToHandle(x + FIELD_SIDE_X * BLOCK_SIZE + 70, y + STATIC_BLOCK_SIZE * 6 * 3 + 200, GetColor(255, 255, 255), figure_font, "%d", sum_linenum);
}
void Player::finalize()
{
delete(mino);
delete(field);
delete(ghost_mino);
delete(hold_mino);
InitFontToHandle();
sound.finalize();
for (int i = 0; i < NEXT_REFER_SIZE; i++) {
delete(next_mino[i]);
}
}