-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
2245 lines (2031 loc) · 46.8 KB
/
Main.cpp
File metadata and controls
2245 lines (2031 loc) · 46.8 KB
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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*======================================================================
Project Name : BUG FIRE!
File Name : Main.cpp
Creation Date : Oct/15/2021
Copyright © 2021,2022 shg-eo as SAKUMA, Shigeo. All rights reserved.
======================================================================*/
#include <Windows.h>
# include <Siv3D.hpp> // OpenSiv3D v0.6.2
// global variable.
// configuration, high score, global status.
struct Global
{
int players = 3; //conf
int bugs = 8; //conf
int highscore = 0; // high-score
boolean ingame = false; // global status;
Stopwatch stopwatch; //
boolean enableSound = false; //conf
boolean NODEAD = false; //conf
} global;
// 迷路のサイズ WxH
#define CWIDTH 33
#define CHEIGHT 33
// キャラクターの縦横サイズ(正方形)
#define SPSIZE 60
// stopper, bug sleeping time
constexpr int sleeptime = 350;
constexpr int stoppertime = 200;
// 何フレーム書いたら、timeを1減らすのか?
// 1フレームの目安は、 0.033秒。1秒ならば 30
constexpr int timedown = 512;
// enable/disable debug console
constexpr auto DEBUG = false;
constexpr auto DEBUG2 = false;
constexpr auto DEBUG3 = false;
constexpr auto DEBUG4 = false;
//#define _DEBUG_
//#define _DEBUG2_
//#define _DEBUG3_
//#define _DEBUG4_
//#define _NODEAD_
// mapping character num, mask bit.
constexpr auto PATH = 0;
/// @brief 方向抽出用 bit
constexpr auto DIRMASK = 7; // 方向抽出用
/// @brief 3/4には、CMASKのみを書く。*PATHには付けない*
// 10FEDCBA9876543210
constexpr auto CMASK = 0b000000000000010000; // 左上以外でPATH以外にはこのbitを付ける。not used.
constexpr auto CDMASK =~0b000000000000011111; // char抽出用のマスク not(31)
constexpr auto WALL = 0b000000000000100000; // 32;
constexpr auto STOPPER = 0b000000000001000000; // 64;
constexpr auto MAN = 0b000000000010000000; // 128;
constexpr auto BUG = 0b000000000100000000; // 256;
constexpr auto EATMAN = 0b000000001000000000; // 512;
constexpr auto EATBUG = 0b000000010000000000; // 1024;
constexpr auto HUMMAN = 0b000000100000000000; // 2048;
constexpr auto HUMBUG = 0b000001000000000000; // 4096;
constexpr auto SLPBUG = 0b000010000000000000; // 8192;
constexpr auto NHMMAN = 0b000100000000000000; // 16384;
constexpr auto NHUMER = 0b001000000000000000; // 32768;
// 0: no (path)
// 32: Wall2 (見えない壁)
// 2: Stopper
// 4,5,6,7,8: Man (Stop, U, D, R, L)
// 9,10,11,12: Bug (U,D,R,L)
// 13,14,15,16: Man with Hammer
// 17,18,19,20: Hammer
// direction of bugs and man.
constexpr auto DIRSTAY = 0;
constexpr auto DIRSTOP = 0;
constexpr auto DIRUP = 1;
constexpr auto DIRDOWN = 2;
constexpr auto DIRRIGHT = 3;
constexpr auto DIRLEFT = 4;
class Maze {
public:
const int width = CWIDTH, height = CHEIGHT;
int maze[CWIDTH][CHEIGHT];
Maze()
{
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
maze[i][j] = 0;
}
}
}
// 迷路の作成
//
int Generate()
{
int level = 0;
// 外周
for (int i = 0; i < width; i++)
for (int j = 0; j < height; j++)
if ((i == 0) || (j == 0) || (i == (width - 1)) || (j == (height - 1)))
{
maze[i][j] = WALL;
}
else
{
maze[i][j] = PATH;
}
// 棒を立て、倒す
std::random_device rnd;
for (int x = 2; x < width - 1; x += 2)
{
for (int y = 2; y < height - 1; y += 2)
{
maze[x][y] = WALL; // 棒を立てる
// 倒せるまで繰り返す
int direction = rnd() % 4;
while (true)
{
// 1/4 で壁を止める
if ((rnd() % 4) == 0)
{
level += 1;
break;
}
// 1/2 で前と同じ方向
if ((rnd() % 2) == 0)
{
level += 1;
// 1行目のみ上に倒せる
if (y == 2)
direction = rnd() % 4;
else
direction = rnd() % 3;
}
else
{
// same direction.
}
// 棒を倒す方向を決める
int wallX = x;
int wallY = y;
switch (direction)
{
case 0: // 右
wallX++;
break;
case 1: // 下
wallY++;
break;
case 2: // 左
wallX--;
break;
case 3: // 上
wallY--;
break;
}
// 壁じゃない場合のみ倒して終了
if (maze[wallX][wallY] != WALL)
{
maze[wallX][wallY] = WALL;
break;
}
}
}
}
// special 出入口の前の壁を開けておく
maze[(width - 1) / 2][1] = PATH; // Exit -1
maze[(width - 1) / 2][height - 2] = PATH; // Enter -1
maze[(width - 1) / 2][height - 1] = 3;// Enter
// level は 150 ぐらい。大きいほど単純化するから、
// 100 - lebel /3
return (100 - (level / 3));
}
};
// ゲーム中 の共有データ
struct GameData
{
int bugs; // number of bugs
int score; // score;
int men; // number of men
int screen; // 面数
int time;
Maze maze;
int mazelevel;
double spawnTime; // 1/Framerate;
int eaten;
};
using App = SceneManager<String, GameData>;
class GameSound {
const Audio walk{ Audio::Stream, Resource(U"Sounds/Walk.mp3"), Loop::No };
const Audio eaten{ Audio::Stream, Resource(U"Sounds/Eaten.mp3"), Loop::No };
const Audio exit{ Audio::Stream, Resource(U"Sounds/Exit.mp3"), Loop::No };
const Audio hammerBug{ Audio::Stream, Resource(U"Sounds/HammerBug.mp3"), Loop::No };
const Audio hammerNo{ Audio::Stream, Resource(U"Sounds/HammerNo.mp3"), Loop::No };
public:
boolean enableSound;
GameSound()
{
enableSound = global.enableSound;
}
void playWalk()
{
if (enableSound)
{
walk.playOneShot();
return;
}
;
}
void playHammerMan()
{
if (enableSound)
{
hammerBug.playOneShot();
return;
}
;
}
void playHammerNo()
{
if (enableSound)
{
hammerNo.playOneShot();
return;
}
;
}
void playEaten()
{
if (enableSound)
{
eaten.playOneShot();
return;
}
;
}
void playExit()
{
if (enableSound)
{
exit.playOneShot();
return;
}
;
}
};
//
/// opening demo..
class Title : public App::Scene
{
private:
int waitframecount;
enum showorder : int
{
normal = 0,
typing = 1, // 1文字ずつ表示
waittyping = 3,
};
typedef struct {
showorder o;
s3d::String m;
} demos;
demos demomessage[5] = {
{normal, U" Ok"},
{typing, U" mon"},
{typing, U" *L"},
{waittyping, U" *GE3CC"},
{typing, U" "},
};
template <typename T, std::size_t N>
inline std::size_t sizeOfArray(const T(&)[N])
{
return N;
}
double spawntyping= 0.2; // frames;
double spawnwaittyping = 1;
double spawnnormal = 0.01;
int x = 0, l = 0, meslines;
double spawntime, accumlator;
int maxlen;
public:
// コンストラクタ(必ず実装)
Title(const InitData& init)
: IScene{ init }
{
meslines = (int)sizeOfArray(demomessage);
l = 0;
spawntime = spawntyping;
accumlator = 0;
maxlen = 0;
for (int i = 0; i < meslines; i++) {
maxlen += (int)demomessage[i].m.size();
}
}
// 更新関数(オプション)
void update() override
{
if (x != 0) {
if (spawntime == spawnwaittyping)
{
spawntime = spawntyping;
}
}
accumlator += Scene::DeltaTime();
if (accumlator >= spawntime)
{
accumlator -= spawntime;
// go ahead;
x++;
if (x > demomessage[l].m.size())
{
x = 0;
l++;
switch (demomessage[l].o)
{
case waittyping:
spawntime = spawnwaittyping;
break;
case typing:
spawntime = spawntyping;
break;
case normal:
spawntime = spawnnormal;
break;
}
}
}
if (l >= meslines) {
l = meslines-1;
// next schene;
changeScene(U"Title2", 0s);
}
}
// 描画関数(オプション)
void draw() const override
{
for (int yy = 0; yy <= l; yy++)
{
String m = demomessage[yy].m;
if (yy == l )
{
if (demomessage[yy].o != normal)
{
int t = m.size();
for (int xx = 0; xx < (t - x - 1); xx++)
{
m.pop_back();
}
}
}
FontAsset(U"PC8001")(m).draw(20, yy * 24 + 24, Palette::White);
}
}
};
// Title Scene, Key bindings.
class Title2 : public App::Scene
{
private:
int state = 0;
int counts;
double framerate = 0;
Array <s3d::String> showingmessage = {
U"",
U" ****** BUG FIRE ******",
U"",
U" キー ノ セツメイ",
U"",
U" [8]",
U" ↑ ",
U" [X]・・・・・ストッハ゜ー",
U" [4]← →[6]",
U" <SHIFT>・・ハンマー",
U" ↓ ",
U" [2]",
U"",
U"オト ヲ ケシマスカ? (y/n)",
};
int mState = 0;
boolean showinstruction = false;
public:
int SoundState = -1; // 1:EnableSound, 0:Mute Sound
Title2(const InitData& init)
: IScene{ init }
{
SoundState = -1;
counts = 0;
framerate = 0;
}
~Title2()
{
// 計測したframerateを設定
//getData().spawnTime = framerate * 2.05;
getData().spawnTime = framerate * 6;
}
void draw() const override
{
int ly = 0, lx = 20;
for (int i = 0; i < showingmessage.size(); i++)
{
s3d::String m = showingmessage[i];
FontAsset(U"PC8001")(m).draw(lx, ly, Palette::Lightgreen);
ly += 24;
}
}
void update() override
{
// Title でframerateを計測して、ゲーム開始時(Titleのデコンストラクタ)に6倍で設定する。
// 極端に遅い場合の対策だけど、極端に速い場合の対策はしていない
// 60Hzほぼ専用
//
if (counts < 100)
{
counts += 1;
double t = Scene::DeltaTime();
framerate = (framerate * counts + t) / (counts + 1);
}
boolean yes, no;
yes = KeyY.down();
no = KeyN.down();
switch (mState)
{
case 0: // Asking Sound;
if (yes || no)
{
mState = 1;
showingmessage << U"";
showingmessage << U" セツメイ カ゛ イリマスカ(y/n)";
if (yes)
{
global.enableSound = false;
}
if (no)
{
global.enableSound = true;
}
break;
}
break;
case 1: // waiting relase key.
if ((KeyY.pressed() == false)
&& (KeyN.pressed() == false))
{
mState = 2;
}
break;
case 2:
if (yes || no) {
mState = 3;
if (yes)
{
showinstruction = true;
}
if (no)
{
showinstruction = false;
}
}
break;
case 3:
if ((KeyY.pressed() == false)
&& (KeyN.pressed() == false))
{
mState = 4;
}
break;
case 4:
if (showinstruction) {
changeScene(U"Instruction", 0s);
}
else
{
changeScene(U"InitGame", 0s);
}
break;
default:
break;
}
}
};
class Instruction :public App::Scene
{
public:
const s3d::String message[19] =
{
U" ",
U" ",
U" <ケ゛ーム ノ セツメイ>",
U"ケ゛ーム < B U G F I R E > ノ セツメイ ヲ イタシ",
U"マス。",
U" ",
U"アナタ ハ セイケ゛ンシ゛カンナイ ニ メイロ ヲ タ゛ッシュツ シナケ",
U"レハ゛ ナリマセン。",
U" ",
U"シカシ ソノタメニハ メイロ ノ ナカ ヲ ハシリマワル ALIEN =",
U" <BUG> ヲ スヘ゛テ ヤッツケネハ゛ ナリマセン。",
U" ",
U"ハ゛ク゛ ハ アナタ ノ オイタ {STOPPER} ニアタルト",
U"シハ゛ラク ウコ゛カナク ナリマス。",
U" ",
U"ソコヲ ハンマー テ゛ タタキツフ゛シテ クタ゛サイ。",
U" ",
U" ",
U"ワカリマシタカ? (y/n)■",
};
Instruction(const InitData& init)
: IScene{ init }
{
}
~Instruction()
{
}
void update() override
{
boolean yes, no;
yes = KeyY.up();
no = KeyN.up();
if (yes)
{
// changeScene(U"Inform");
changeScene(U"InitGame");
}
}
void draw() const override
{
int ly = 12, lx = 3;
//const Font font{22, U"Font/DotGothic16-Regular.ttf"};
//const Font font{22};
//font(U"SCORE").draw(300, 300);
for (s3d::String m : message)
{
// font(U"SCORE").draw(300, 300);
FontAsset(U"PC8001")(m).draw(lx, ly, Palette::Lightgreen);
ly += 24;
}
}
};
class Mstring
{
public:
#include <format>
/// @brief S 数値から、全角文字にする。マイナスには未対応
/// @param m: 数値、digit:けたすう
/// @return
static String itoz(int m, int digit = 0, String sup = U"0")
{
String a;
uint32 t;
String s;
a = U"{}"_fmt(m);
for (int i = 0; i < a.length(); i++)
{
t = a[i];
if (t == 0x0030) s += U"0"; // 0x30 ==='0'
if (t == 0x0031) s += U"1";
if (t == 0x0032) s += U"2";
if (t == 0x0033) s += U"3";
if (t == 0x0034) s += U"4";
if (t == 0x0035) s += U"5";
if (t == 0x0036) s += U"6";
if (t == 0x0037) s += U"7";
if (t == 0x0038) s += U"8";
if (t == 0x0039) s += U"9";
if (t == 0x002d) s += U"-";
if (t == 0x002b) s += U"+";
if (t == 0x002e) s += U".";
}
if (digit > 0)
{
for (int i = 0; i < digit - a.length(); i++)
{
s = sup + s;
}
}
return s;
}
// static String zupper(String s)
// {
// const String ZAU = U"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// const String HAL = U"abcdefghijklmnopqrstuvwxyz";
// const String ZD = U"0123456789.-+";
// const String HD = U"0123456789.-+";
// const String ZK = U"!@#$%^&*()_+|-=\[]{};’\:”,./<>?";
// const String HK = U"!@#$%^&*()_+|-=\\[]{};':\",./<>?";
// }
};
//GameOver
class GameOver :public App::Scene
{
public:
String message[21] =
{
U"",
U" ***** G A M E O V E R *****",
U"",
U"",
U"",
U"",
U"",
U" アナタ ノ スコア ハ {} テン テ゛シタ。"_fmt(Mstring::itoz(getData().score,6)),
U"",
U" ",
U"",
U"",
U" アナタ ノ タッシタ メンスウ ハ {} テ゛シタ。"_fmt(Mstring::itoz(getData().screen,2)),
U"",
U"",
U" オツカレサマ テ゛シタ。",
U"",
U"",
U" by Y.OGI (1980.12.23)",
U"",
U" REPLAY ( スヘ゜ース ハ゛ー )",
};
GameOver(const InitData& init)
: IScene{ init }
{
if (getData().score > global.highscore)
{
global.highscore = getData().score;
message[9] = U" *(コレ ハ ハイスコア テ゛ス。)*";
}
else
{
}
}
~GameOver()
{
}
void update() override
{
boolean space;
space = KeySpace.up();
if (space)
{
// changeScene(U"Inform");
changeScene(U"InitGame");
}
}
void draw() const override
{
int ly = 12, lx = 3;
for (s3d::String m : message)
{
// font(U"SCORE").draw(300, 300);
FontAsset(U"PC8001")(m).draw(lx, ly, Palette::Lightgreen);
ly += 24;
}
}
};
// ゲーム開始
class InitGame : public App::Scene
{
public:
InitGame(const InitData& init)
: IScene{ init }
{
global.stopwatch.start();
getData().score = 0;
getData().men = global.players;
getData().screen = 0;
};
~InitGame()
{
#ifdef _DEBUG_
if (DEBUG) Print << global.stopwatch.ms() << U"msec";
#endif
}
void update() override
{
#ifdef _DEBUG_
if (DEBUG) Print << U"Scene: InitGame";
#endif
changeScene(U"InitScreen", 0s);
}
void draw() const override
{
}
};
// 新しい面開始
class InitScreen : public App::Scene
{
public:
InitScreen(const InitData& init)
: IScene{ init }
{
#ifdef _DEBUG_
if (DEBUG) Print << U"Scene: InitScreen";
#endif
//面数の更新
getData().screen += 1;
//BUG数の更新
getData().bugs = global.bugs;
getData().time = 99;
//迷路の初期化
getData().mazelevel = getData().maze.Generate();
global.ingame = false;
}
~InitScreen()
{
#ifdef _DEBUG_
if (DEBUG) Print << global.stopwatch.ms() << U"msec";
#endif
}
void update() override
{
changeScene(U"StartGame", 0s);
}
void draw() const override
{
}
};
// 面開始
class StartGame : public App::Scene
{
public:
s3d::String message[8];
double ti;
StartGame(const InitData& init)
: IScene{ init }
{
ti = 0;
#ifdef _DEBUG_
if (DEBUG) Print << U"StartGame:";
#endif
// 中間報告の表示
message[0] = U" チュウカンホウコク";
message[1] = U" タ゛イ {} メン"_fmt(Mstring::itoz(getData().screen, 2));
message[2] = U" メイロ ノ レヘ゛ル {}"_fmt(Mstring::itoz(getData().mazelevel, 2));
message[3] = U" モチシ゛カン {}"_fmt(Mstring::itoz(getData().time, 2));
message[4] = U" フ゜レイヤー ニンス゛ウ {}"_fmt(Mstring::itoz(getData().men));
message[5] = U" SCORE {}"_fmt(Mstring::itoz(getData().score, 6));
message[6] = U" HIGH SCORE {}"_fmt(Mstring::itoz(global.highscore, 6));
message[7] = U" F I G H T !!!!!!!";
}
~StartGame()
{
#ifdef _DEBUG_
if (DEBUG) Print << global.stopwatch.ms() << U"msec";
#endif
}
void update() override
{
// 数秒待つ
double d = Scene::DeltaTime();
ti = ti + d;
// 次(10秒後)
if (ti >= 3) changeScene(U"Game", 0);
}
void draw() const override
{
int x = 24, y = 24;
for (int i = 0; i < 8; i++)
{
FontAsset(U"PC8001")(message[i]).draw(x, y, Palette::White);
y += 48;
}
}
};
class Map4draw
{
public:
int map[CWIDTH][CHEIGHT + 1];
int width;
int height;
void init(Maze maze)
{
height = CHEIGHT + 1;
width = CWIDTH;
for (int xx = 0; xx < CWIDTH; xx++)
{
for (int yy = 0; yy < CHEIGHT; yy++)
{
map[xx][yy] = maze.maze[xx][yy]; // 左上
}
}
//最下行
for (int i = 0; i < width; i++)
{
map[i][height - 1] = WALL;
}
height = CHEIGHT + 1;
width = CWIDTH;
}
};
class Game :public App::Scene
{
public:
#ifdef _DEBUG4_
const Font Debugfont{ FontMethod::SDF, 12, Typeface::Bold };
const Vec2 shadowOffset{ 4,4 };
const ColorF shadowColor{ 0.0,0.5 };
#endif
double time;
//int map[CWIDTH * 2][CHEIGHT * 2]; // mapping
Map4draw drawmap; // classに変更
GameSound Sound;
/// @brief PlayerState
enum Playerstate
{
NORMAL, DEAD, HUMMER, NOHUMMER, EXIT, PAUSE,
};
Playerstate playerstate,prevstate;
boolean pause = false;
class Vector
{
public:
int x, y, dx, dy;
Vector()
{
x = y = dx = dy = 0;
}
Vector next(int dir, int xx = 0, int yy = 0)
{
Vector ret;
switch (dir)
{
case DIRSTAY:
break;
case DIRUP:
x = 0; dx = 0;
y = -1; dy = -1;
break;
case DIRDOWN:
x = 0; dx = 0;
y = 1; dy = 1;
break;
case DIRRIGHT:
x = 1; dx = 1;
y = 0; dy = 0;
break;
case DIRLEFT:
x = -1; dx = -1;
y = 0; dy = 0;
break;
default:
break;
}
ret.x = xx + dx;
ret.y = yy + dy;
return ret;
}
Vector prev(int dir, int xx = 0, int yy = 0)
{
Vector ret;
switch (dir)
{
case DIRSTAY:
break;
case DIRUP:
y = 1; dy = 1;
break;
case DIRDOWN:
y = -1; dy = -1;
break;
case DIRRIGHT:
x = -1; dx = -1;
break;
case DIRLEFT:
x = 1; dx = 1;
break;
default:
break;
}
ret.x = xx + dx;
ret.y = yy + dy;
return ret;
}
};
class Char
{
public:
int x, y;
int character; //bug, stopperとか
boolean live; // 存在するかどうか(bugはデフォルトでt, stopperはf)
Char()
{ // 引数なしのコンストラクタを必ず作成すること。
x = -1; // -1 : not on screen;
y = -1;
live = true;
}
Char(boolean l)
{
x = -1; // -1 : not on screen;
y = -1;
live = l;
}
~Char()
{
}
void draw(Map4draw& drawmap, int dir = 0) // mapに描画
{
if (drawmap.map[x][y] != 0)
{
#ifdef _DEBUG_
if (DEBUG) s3d::Console << U"Draw not 0" << U" X" << x << U" Y" << y
<< U", ch:" << drawmap.map[x][y];
#endif
}
// 実際の画面への描写時は左上の情報だけで描画させるため、
// 左上以外は、bitを立てる。
drawmap.map[x][y] = character + dir;
}
void erase(Map4draw& drawmap) // mapに描画
{
drawmap.map[x][y] = 0;
}