-
Notifications
You must be signed in to change notification settings - Fork 0
/
ETERNAL_STRIKER_M5.ino
2518 lines (2506 loc) · 75.3 KB
/
ETERNAL_STRIKER_M5.ino
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
//
//ETERNAL STRIKER Rr M5 V1.6.0
//T.KATAKOTO (TETUBUN-HO) TEAM Redherring(STUDIO Sequence)
//
//18/10/28 Add STICK> 18/11/4 ADD I2C STICK 19/3/25
//19/6/23 NEO PIXEL library change
//20/9/17 SOUND OUT
//20/9/24 Add FACE JOYSTICK
//
//ETERNAL_STRIKER_M5 LICENSE:
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvStartvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//BSD 4-Clause License
//
//Copyright (c) 2020, TETUBUN-HO TEAM Redherring/STUDIO Sequence
//All rights reserved.
//
//Redistribution and use in source and binary forms, with or without
//modification, are permitted provided that the following conditions are met:
//1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//3. All advertising materials mentioning features or use of this software
// must display the following acknowledgement:
// This product includes software developed by the <organization>.
//4. Neither the name of the <organization> nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ''AS IS'' AND ANY
//EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
//WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
//FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
//DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
//OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
//USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^End^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//
#define SDC_SYSTEM_ON
#define NEOPIXEL_ON
//
#define C16(_rr,_gg,_bb) ((ushort)(((_rr & 0xF8) << 8) | ((_gg & 0xFC) << 3) | ((_bb & 0xF8) >> 3)))
#define C8(_rr,_gg,_bb) ((ushort)(((_rr & 0xE0)) | ((_gg & 0xE0) >>3) | (_bb >> 6)))
#define PI 3.141592653589793
//
#include <M5Stack.h>
#ifdef SDC_SYSTEM_ON
#include "M5StackUpdater.h"
#endif
#include "Sprite_t_k_cst.h"
//
#include <Wire.h>
#include "SPIFFS.h"
//
#ifdef NEOPIXEL_ON
#include "NeoPixelBrightnessBus.h"
#define M5STACK_FIRE_NEO_NUM_LEDS 10
#define M5STACK_FIRE_NEO_DATA_PIN 15
NeoPixelBrightnessBus<NeoRgbFeature, Neo800KbpsMethod> strip(M5STACK_FIRE_NEO_NUM_LEDS, M5STACK_FIRE_NEO_DATA_PIN);
#endif
//
#define FACE_JOY_ADDR 0x5e
#define KEYBOARD_I2C_ADDR 0x08
#define KEYBOARD_INT 0x5
//
int sys_ver = 160;
byte NEO_P_MODE = 0;
//
//Stick Read SYSTEM
//
short MIN_XA, MIN_YA, MAX_XA, MAX_YA;
short BASE_XA, BASE_YA, BASE_VEC;
int BASE_XI, BASE_YI;
short READ_PIN_X = 35, READ_PIN_Y = 36; //ANALOG PIN
short DUAL_BUTTON_R_PIN = 26; //ANALOG PIN
short DUAL_BUTTON_B_PIN = 36; //ANALOG PIN
short SB_FLAG, SB_FLAG_R, SB_FLAG_B; //BUTTON State
short DUAL_BUTTON_FLAG;
int SX_AXIS, SY_AXIS; //-64<>64 Value
int AXIS_STUB = 8;
#define JOY_ADDR 0x52
//
#include "Resource.h"
//
TFT_eSprite_CST img = TFT_eSprite_CST(&M5.Lcd);
//
bool started = false, gameover = false;
unsigned long FrameTime = 0;
unsigned long systimer = 0;
byte Sound_mode = 0;
boolean but_A = false, but_B = false, but_TOP = false, but_DOWN = false, but_LEFT = false, but_RIGHT = false; //2018/11/4 STICK Add
boolean S_but_A = false, S_but_B = false, S_but_C = false;
byte CTL_Mode = 0;
int game_speed = 45;// 45msec 22fps
//Decision counter for long press. *game_speed = real time
byte LONG_P_CT = 2; //100ms
int GAME_LEVEL = 0;
//
#define SPF_NOR (0<<1) //8bitSPRITE BITMAP
#define SPF_MSX (1<<1) //1bitSPRITE
#define SPF_LINE (2<<1)
#define SPF_FILL (3<<1)
#define SPF_CHAR (4<<1)
#define SPF_MOD (5<<1)//Scaling and rotation
#define SPF_TRAN (6<<1)//Fake_Translucent
#define SPF_F_TRA (1<<4)
#define SPR_MAX 96
#define SPR_LAYER_MAX 4
#define SPR_SET_MAX 32
//
uint8_t *_sprite_img8;
//
byte spr_f[SPR_MAX], spr_n[SPR_MAX]; //f bit0:run_flag bit1-3:type(0:NORMAL(BITMAP) 1:MSX_SPRITE 2:LINE) bit4:Transparency
short spr_x[SPR_MAX], spr_y[SPR_MAX], spr_p0[SPR_MAX], spr_p1[SPR_MAX], spr_p2[SPR_MAX], spr_p3[SPR_MAX], spr_x2[SPR_MAX], spr_y2[SPR_MAX];
byte spr_nm;
byte spr_lnm[SPR_LAYER_MAX];
byte spr_layer[SPR_LAYER_MAX][SPR_MAX];
//SPRITE
short put_sprite(byte f, byte n, short x, short y, short z = 0, short p0 = 0, short p1 = 0, short x2 = 0, short y2 = 0);
//SPRITE
void get_sprite(short nm, const uint8_t* adr, short w, short h, short w2 = 1, short h2 = 1);
//
const uint8_t* spp_adr[SPR_SET_MAX];
short spp_w[SPR_SET_MAX][2], spp_h[SPR_SET_MAX][2];
//
short obj[32][5];
//
int scene, GS_systimer, GS_mode, stage;
//
void setup() {
// put your setup code here, to run once:
randomSeed(analogRead(0));
M5.begin();
//
//SD_MENU_KICK
#ifdef SDC_SYSTEM_ON
if (digitalRead(BUTTON_A_PIN) == 0) {
Serial.println("Will Load menu binary");
updateFromFS(SD);
ESP.restart();
}
#endif
//M5.Lcd.setRotation(2);
Wire.begin(21, 22, 400000);
SPIFFS.begin();
//
Stick_Init();
//
M5.Lcd.fillScreen(TFT_BLACK);
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
img.setColorDepth(8);
_sprite_img8 = (uint8_t*)img.createSprite(240, 240);
//
#ifdef NEOPIXEL_ON
strip.Begin();
strip.Show();
strip.SetBrightness(64);
#endif
//
init();
//
M5.Lcd.fillScreen(TFT_BLACK);
//2018/10/27 T.K Change
snd_init();
//
delay(100);
}
void init() {
//SET SPRITE IMAGE SET
get_sprite(0, FILE_0, (short)FILE_0_W, (short)FILE_0_H); //MY_SHIP
get_sprite(1, FILE_1, (short)FILE_1_W, (short)FILE_1_H);
get_sprite(2, FILE_2, (short)FILE_2_W, (short)FILE_2_H);
get_sprite(3, FILE_3, (short)FILE_3_W, (short)FILE_3_H);
get_sprite(4, FILE_4, (short)FILE_4_W, (short)FILE_4_H); //ENEMY_BLT
get_sprite(5, FILE_5, (short)FILE_5_W, (short)FILE_5_H);
get_sprite(6, FILE_6, (short)FILE_6_W, (short)FILE_6_H);
get_sprite(7, FILE_7, (short)FILE_7_W, (short)FILE_7_H); //MYSHIP FLASH
get_sprite(8, FILE_8, (short)FILE_8_W, (short)FILE_8_H);
get_sprite(9, FILE_9, (short)FILE_9_W, (short)FILE_9_H);
get_sprite(10, FILE_10, (short)FILE_10_W, (short)FILE_10_H);
get_sprite(11, FILE_11, (short)FILE_11_W, (short)FILE_11_H);
get_sprite(12, FILE_12, (short)FILE_12_W, (short)FILE_12_H);
get_sprite(13, FILE_13, (short)FILE_13_W, (short)FILE_13_H);
get_sprite(14, FILE_14, (short)FILE_14_W, (short)FILE_14_H);
get_sprite(15, FILE_15, (short)FILE_15_W, (short)FILE_15_H);
get_sprite(16, FILE_16, (short)FILE_16_W, (short)FILE_16_H);
get_sprite(17, FILE_17, (short)FILE_17_W, (short)FILE_17_H);
get_sprite(18, FILE_18, (short)FILE_18_W, (short)FILE_18_H);
get_sprite(19, FILE_19, (short)FILE_19_W, (short)FILE_19_H);
get_sprite(20, FILE_20, (short)FILE_20_W, (short)FILE_20_H);
get_sprite(21, FILE_21, (short)FILE_21_W, (short)FILE_21_H);
get_sprite(22, FILE_22, (short)FILE_22_W, (short)FILE_22_H); //ITEM
get_sprite(23, FILE_23, (short)FILE_23_W, (short)FILE_23_H); //MYSHIP FLASH2
get_sprite(24, FILE_24, (short)FILE_24_W, (short)FILE_24_H); //STAGE2 BACK
get_sprite(25, FILE_25, (short)FILE_25_W, (short)FILE_25_H); //STAGE1 BACK
get_sprite(31, FILE_FONT, (short)FILE_FONT_W, (short)FILE_FONT_H); //SPRITE FONT
//GAME SYSTEM INITIALIZE
gameinit();
}
uint32_t spr_wdat[16];
int led_pat[] = {0, 1, 3, 5, 8, 12, 16, 14, 9, 3};
int led_ct = 0, led_r = 255, led_g = 0, led_b = 0;
void loop() {
// put your main code here, to run repeatedly:
FrameTime = millis();
KeyPadLoop();
//
gameloop();
paint();
//M5.Lcd.drawFloat(1000.0f/(millis() -FrameTime), 3, 0, 180, 4);
//
M5.update();
//
Loop_T_ADJ(0);
if (NEO_P_MODE == 0 && led_ct % 2 == 0) {
#ifdef NEOPIXEL_ON
for (uint8_t n = 0; n < M5STACK_FIRE_NEO_NUM_LEDS; n++) {
int s = (int)led_pat[(n + led_ct / 2) % 10];
RgbColor color = RgbColor(led_g * s / 16, led_r * s / 16, led_b * s / 16);
strip.SetPixelColor(n, color);
}
strip.Show();
#endif
//FACE JS
for (int i = 0; i < 4; i++)FACE_Led(i, 0, 0, 0);
if (SX_AXIS < -1 * AXIS_STUB) {
FACE_Led(0, led_r, led_g, led_b);
}
if (SX_AXIS > AXIS_STUB) {
FACE_Led(2, led_r, led_g, led_b);
}
if (SY_AXIS < -1 * AXIS_STUB) {
FACE_Led(3, led_r, led_g, led_b);
}
if (SY_AXIS > AXIS_STUB) {
FACE_Led(1, led_r, led_g, led_b);
}
}
led_ct++;
//
systimer++;
}
//========================================================================
//SPRITE WRAPER
//========================================================================
byte spr_scr_t[] = {1, 1, 2, 1, 1, 1, 2, 1};
byte spr_scr_stx[] = {9, 8, 6, 5, 4, 3, 1, 0};
byte spr_scr_sty[] = {0, 1, 2, 4, 5, 6, 7, 9};
//SPRITE Draw reservation
short put_sprite(byte f, byte n, short x, short y, short z, short p0, short p1, short x2, short y2) {
if (spr_nm >= SPR_MAX || spr_lnm[z] >= SPR_MAX || z >= SPR_LAYER_MAX)return -1;
//Set Parameter to Overall storage
f |= 1;
spr_f[spr_nm] = f; spr_n[spr_nm] = n;
spr_x[spr_nm] = x; spr_y[spr_nm] = y;
spr_p0[spr_nm] = p0; spr_p1[spr_nm] = p1;
spr_x2[spr_nm] = x2; spr_y2[spr_nm] = y2;
//Set Parameter to layer
spr_layer[z][spr_lnm[z]++] = spr_nm;
//
spr_nm++;
//
}
//SPRITE STRING OUT
short put_sprite_str(char * str1, short x, short y, short cl) {
int l = 0;
while (l < 256) {
if (str1[l] == 0)break;
put_sprite(SPF_CHAR, 5, x + 5 + l * 10, y + 8, SPR_LAYER_MAX - 1, cl, str1[l++]);
}
}
//SPRITE STRING OUT CENTER
short put_sprite_str_center(char * str1, short x, short y, short cl) {
int l = 0, l2 = 0;
while (l2 < 256) {
if (str1[l2] == 0)break;
l2++;
}; l2--;
while (l < 256) {
if (str1[l] == 0)break;
put_sprite(SPF_CHAR, 5, x + l * 10 - l2 * 5, y + 8, SPR_LAYER_MAX - 1, cl, str1[l++]);
}
}
//SPRITE Image set settings
void get_sprite(short nm, const uint8_t* adr, short w, short h, short w2, short h2) {
spp_adr[nm] = adr; //const
spp_w[nm][0] = w; spp_h[nm][0] = h;
spp_w[nm][1] = w2; spp_h[nm][1] = h2;
}
//SPRITE drawing
void paint_sprite() {
byte bt_d[4];
//SPRITE SYSTEM
int s_base = 0, nm, sx = 0, sy = 0, c = 0xffffff, n, k, l, crn;
for (int l = 0; l < SPR_LAYER_MAX; l++) {
// M5.Lcd.drawFloat(spr_lnm[l], 3, 0, 160+l*20, 4);
for (int m = 0; m < spr_lnm[l]; m++) {
int i = spr_layer[l][m];
if (spr_f[i] & 1) {
nm = spr_n[i];
sx = spr_x[i]; sy = spr_y[i];
switch ((spr_f[i] & 14)) {
case SPF_NOR:
default:
sx = sx - (spp_w[nm][0] >> 1); sy = sy - (spp_h[nm][0] >> 1);
if ((spr_f[i]&SPF_F_TRA) != 0)
img.pushImage_D8AD(sx, sy, spp_w[nm][0], spp_h[nm][0], spp_adr[nm], SPBB_NOR | SPR_CLIP | SPR_ZERO_T);
else
img.pushImage_D8AD(sx, sy, spp_w[nm][0], spp_h[nm][0], spp_adr[nm], SPBB_NOR | SPR_CLIP);
break;
case SPF_TRAN:
sx = sx - (spp_w[nm][0] >> 1); sy = sy - (spp_h[nm][0] >> 1);
if ((spr_f[i]&SPF_F_TRA) != 0)
img.pushImage_D8AD(sx, sy, spp_w[nm][0], spp_h[nm][0], spp_adr[nm], SPBB_TRA | SPR_CLIP | SPR_ZERO_T);
else
img.pushImage_D8AD(sx, sy, spp_w[nm][0], spp_h[nm][0], spp_adr[nm], SPBB_TRA | SPR_CLIP);
break;
case SPF_MOD://Scaling and rotation
img.pushImage_D8AD(sx, sy, spp_w[nm][0], spp_h[nm][0], spp_adr[nm], SPBB_MOD, 0xffff, spr_p0[i], spr_p1[i]);
break;
case SPF_FILL:
sx = sx - (spr_x2[i] >> 1); sy = sy - (spr_y2[i] >> 1);
img.fillRect(sx, sy, spr_x2[i], spr_y2[i], spr_p0[i]);
break;
case SPF_CHAR:
sx = sx - 5; sy = sy - 8;
if (spr_p1[i] < 0x20 || spr_p1[i] >= 0x80)break;
c = spr_p1[i] - 0x20;
if (spr_p0[i] == 0)
img.pushPartImage_D8(sx, sy, (c & 31) * 10, (c >> 5) * 16, 10, 16, spp_w[31][0], spp_adr[31], SPBB_NOR | SPR_ZERO_T);
else
img.pushPartImage_D8(sx, sy, (c & 31) * 10, (c >> 5) * 16, 10, 16, spp_w[31][0], spp_adr[31], SPBB_NOR | SPR_COLOR | SPR_ZERO_T, spr_p0[i]);
break;
}
};
spr_f[i] &= (~1);
}
spr_lnm[l] = 0;
}
spr_nm = 0;
}
//
//SOUND関係ダミー
//
void snd_init() {
if (Sound_mode == 2)return;
}
//
void snd_play(int nm, const char *filename, float v) {
if (Sound_mode == 2 || (Sound_mode == 1 && nm != 0))return;
}
//
void snd_stop(int nm) {
if (Sound_mode == 2)return;
}
//*****************************
// Stick Read SYSTEM
//*****************************
// Stick_Initialize
void Stick_Init() {
//FACE JS CHEAK
uint8_t x_data_L, x_data_H;
uint8_t y_data_L, y_data_H;
Wire.requestFrom(FACE_JOY_ADDR, 5);
if (Wire.available()) {
y_data_L = Wire.read();
y_data_H = Wire.read();
x_data_L = Wire.read();
x_data_H = Wire.read();
BASE_XI = x_data_H << 8 | x_data_L;
BASE_YI = y_data_H << 8 | y_data_L;
Serial.println(BASE_XI);
Serial.println(BASE_YI);
return;
}
//DUAL BUTTON CHEAK
pinMode(DUAL_BUTTON_R_PIN, INPUT);
pinMode(DUAL_BUTTON_B_PIN, INPUT);
if (digitalRead(DUAL_BUTTON_R_PIN) && digitalRead(DUAL_BUTTON_B_PIN))DUAL_BUTTON_FLAG = -1;
}
//
//Stick Read
//RETURN > int SX_AXIS,SY_AXIS;//-64<>64 Value
//If the pin base voltage is below a certain level, disconnect the system.
//
void Stick_Read() {
int x, y;
uint8_t x_data_L, x_data_H;
uint8_t y_data_L, y_data_H;
//FACE JS
Wire.requestFrom(FACE_JOY_ADDR, 5);
if (Wire.available()) {
y_data_L = Wire.read();
y_data_H = Wire.read();
x_data_L = Wire.read();
x_data_H = Wire.read();
x = x_data_H << 8 | x_data_L;
y = y_data_H << 8 | y_data_L;
// Z(0: released 1: pressed)
SB_FLAG = !Wire.read();
SX_AXIS = (x - BASE_XI) * 68 / (BASE_XI - 180);
SY_AXIS = -1 * (y - BASE_YI) * 68 / (BASE_YI - 180);
//ゼロ点遊び
if (SX_AXIS < 4 && SX_AXIS > -4)SX_AXIS = 0;
if (SY_AXIS < 4 && SY_AXIS > -4)SY_AXIS = 0;
//
if (SX_AXIS < -64)SX_AXIS = -64;
else if (SX_AXIS > 64)SX_AXIS = 64;
if (SY_AXIS < -64)SY_AXIS = -64;
else if (SY_AXIS > 64)SY_AXIS = 64;
return;
}
//I2C JOYPAD DATA READ 2018/11/14 Add
Wire.requestFrom(JOY_ADDR, 3);
if (Wire.available()) {
//BOOSTER 0-255 > -128~127 > -96~95 > HI_CUT > -64~63
x = Wire.read(); y = Wire.read(); SB_FLAG = Wire.read();
if (x + y + SB_FLAG != 0) {
SX_AXIS = (x - 128) * 2 / 3;
if (SX_AXIS < -64)SX_AXIS = -64;
else if (SX_AXIS > 64)SX_AXIS = 64;
SY_AXIS = (127 - y) * 2 / 3;
if (SY_AXIS < -64)SY_AXIS = -64;
else if (SY_AXIS > 64)SY_AXIS = 64;
}
else
{
SX_AXIS = 0;
SY_AXIS = 0;
SB_FLAG = 0;
}
}
//DUAL BUTTON READ
if (DUAL_BUTTON_FLAG != 0) {
pinMode(DUAL_BUTTON_R_PIN, INPUT);
pinMode(DUAL_BUTTON_B_PIN, INPUT);
if (digitalRead(DUAL_BUTTON_R_PIN))
SB_FLAG_R = 0;
else
SB_FLAG_R = -1;
if (digitalRead(DUAL_BUTTON_B_PIN))
SB_FLAG_B = 0;
else
SB_FLAG_B = -1;
}
}
//=======================================================================
//INPUT SYSTEM 2018/10/9 T.K Change
//=======================================================================
//2018/10/9 T.K Change
void ClearKeys() {
but_A = false;
but_B = false;
but_LEFT = false;
but_RIGHT = false;
but_TOP = false;
but_DOWN = false;
S_but_A = false;
S_but_B = false;
S_but_C = false;
}
//========================================================================
//KEY INFO (A=bit3,C=bit2,B=bit4)
//2018/10/9 T.K Replacement
short Key = 0, R_Key = 0, Btn_A_ct = 0, Btn_B_ct = 0, Btn_C_ct = 0;
bool gb_flag=false;
bool KeyPadLoop() {
Stick_Read();
ClearKeys();
//FACE GB
pinMode(KEYBOARD_INT, INPUT_PULLUP);
if(digitalRead(KEYBOARD_INT) == LOW) {
Wire.requestFrom(KEYBOARD_I2C_ADDR, 1); // request 1 byte from keyboard
while (Wire.available()) {
R_Key=Key = ~Wire.read(); // receive a byte as character
if (R_Key&1) {
but_TOP = true;
}
if (R_Key&2) {
but_DOWN = true;
}
gb_flag=true;
}
}
//
if(!gb_flag){
if (M5.BtnA.read()) {
Key |= 4; //Acquire long press.
Btn_A_ct++;
if (Btn_A_ct > LONG_P_CT)Key |= 64;
}
else
{ if ((Key & 4) && !(Key & 64))R_Key |= 4;
Key &= (~4); Key &= (~64); Btn_A_ct = 0;
}
//
if (M5.BtnC.read()) {
Key |= 8; //Acquire long press.
Btn_C_ct++;
if (Btn_C_ct > LONG_P_CT)Key |= 128;
}
else
{ if ((Key & 8) && !(Key & 128))R_Key |= 8;
Key &= (~8); Key &= (~128); Btn_C_ct = 0;
}
//
if (M5.BtnB.read()) {
Key |= 16; //Acquire long press.
Btn_B_ct++;
}
else
{ if (Key & 16) {
if (Btn_B_ct < LONG_P_CT)R_Key |= 16;
else
R_Key |= 32;
}
Key &= (~16); Btn_B_ct = 0;
}
}
//
if ((R_Key & 4) || Key & 64) {
R_Key &= (~4);
but_LEFT = true;
}
if ((R_Key & 8) || Key & 128) {
R_Key &= (~8);
but_RIGHT = true;
}
if ((R_Key & 16)) {
R_Key &= (~16);
but_A = true;
}
if ((R_Key & 32)) {
R_Key &= (~32);
but_B = true;
}
//
if (SX_AXIS < -1 * AXIS_STUB) {
but_LEFT = true;
}
if (SX_AXIS > AXIS_STUB) {
but_RIGHT = true;
}
if (SY_AXIS < -1 * AXIS_STUB) {
but_TOP = true;
}
if (SY_AXIS > AXIS_STUB) {
but_DOWN = true;
}
if (SB_FLAG != 0) {
S_but_A = true;
}
if (SB_FLAG_R != 0) {
S_but_B = true;
}
if (SB_FLAG_B != 0) {
S_but_C = true;
}
//
if (but_LEFT || but_RIGHT || but_TOP || but_DOWN || but_A)return true;
return false;
}
//========================================================================
//NEO PIXEL USE ON/OFF
//========================================================================
void ClearNPX() {
#ifdef NEOPIXEL_ON
if (NEO_P_MODE == 0) {
pinMode(M5STACK_FIRE_NEO_DATA_PIN, OUTPUT);
digitalWrite(M5STACK_FIRE_NEO_DATA_PIN, LOW);
strip.SetBrightness(64);
// strip.clear();
}
RgbColor color = RgbColor(0, 0, 0xff);
for (int i = 0; i < M5STACK_FIRE_NEO_NUM_LEDS; i++)strip.SetPixelColor(i, color);
strip.Show();//Blue light emission to clear
delay(200);
color = RgbColor(0, 0, 0);
for (int i = 0; i < M5STACK_FIRE_NEO_NUM_LEDS; i++)strip.SetPixelColor(i, color);
strip.Show();//Clear
if (NEO_P_MODE == 1) {
strip.SetBrightness(0);
// strip.clear();
digitalWrite(M5STACK_FIRE_NEO_DATA_PIN, LOW);
pinMode(M5STACK_FIRE_NEO_DATA_PIN, INPUT);
}
#endif
}
//
//FACE JS LED
//
void FACE_Led(int indexOfLED, int r, int g, int b) {
Wire.beginTransmission(FACE_JOY_ADDR);
Wire.write(indexOfLED);
Wire.write(r/6);
Wire.write(g/6);
Wire.write(b/6);
Wire.endTransmission();
}
//========================================================================
//GAME_SYSTEM -MIDP BASE-
//From here, the content body.
//========================================================================
#define DISPLAY_WIDTH2 0
#define DISPLAY_HEIGHT2 0
#define DISPLAY_WIDTH3 120
#define DISPLAY_HEIGHT3 120
int GS_key = 0;
int ecount, ect2, emode, stoper;
int r_timer, score, over_f, item, work0, lap;
int o_nm, my_nm, ept, dif, nw_nm , bomb_nm, bomb_ct;
int hi_sc[3];
//
int s_fl, s_f2, se_e0;
//
#define MAX_PAT 24
//
#define MAX_OBJ 64
//
int pt_x[MAX_PAT];
int pt_y[MAX_PAT];
//
byte o_f[MAX_OBJ];
byte o_a[MAX_OBJ];
int o_h[MAX_OBJ];
int o_x[MAX_OBJ];
int o_y[MAX_OBJ];
int o_pt[MAX_OBJ];
int o_ptf[MAX_OBJ];
byte o_hn[MAX_OBJ];
int o_p0[MAX_OBJ];
int o_p1[MAX_OBJ];
int o_p2[MAX_OBJ];
int o_p3[MAX_OBJ];
int o_p4[MAX_OBJ];
int o_p5[MAX_OBJ];
int o_p6[MAX_OBJ];
int o_p7[MAX_OBJ];
//
char str_out[256];
//
uint8_t SaveData[16];
//
int image_sz[] = { 30, 30, 21, 21, 21, 21, 21, 21 , 9, 9, 0, 0, 120, 60, 30, 30,
24, 24 , 21, 21 , 21, 21 , 69, 45 , 60, 30, 60, 30, 10, 18,
18, 20, 18, 18 , 36, 36, 33, 33 , 53, 41, 53, 41 , 120, 120
};
//
int GS_sin[] = {0, 19, 38, 55, 70, 83, 92, 98 , 99, 98, 92, 83, 70, 55, 38, 19, 0, -19, -38, -55, -70, -83, -92, -98, -99, -98, -92, -83, -70, -55, -38, -19, 0, 19, 38, 55, 70, 83, 92, 98, 99, 0};
byte GS_atan[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8, 4, 2, 1, 1, 1, 1, 1, 1, 1, 0, 0,
8, 6, 4, 2, 2, 2, 1, 1, 1, 1, 1, 1,
8, 7, 5, 4, 3, 3, 2, 2, 2, 2, 1, 1,
8, 7, 6, 5, 4, 3, 3, 3, 2, 2, 2, 2,
8, 7, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2,
8, 7, 7, 6, 5, 5, 4, 4, 3, 3, 3, 2,
8, 7, 7, 6, 5, 5, 4, 4, 4, 3, 3, 3,
8, 7, 7, 6, 6, 5, 5, 4, 4, 4, 3, 0,
8, 7, 7, 6, 6, 5, 5, 5, 4, 4, 4, 3,
8, 8, 7, 7, 6, 6, 5, 5, 5, 4, 4, 4,
8, 8, 7, 7, 6, 6, 6, 5, 5, 4, 4, 4
};
//ステージデータ
byte stage_pt[] = {
1, 0, 1, 0 , 1, 0, 1, 1 , 1, 1, 64, 0, 0, 0, //0
2, 0, 3, 0, 4, 0, 5, 64, 0, 0, 0, 96, 0, 0,
2, 0, 0, 3, 0, 0, 2, 0, 0, 3, 64, 0, 0, 0,
8, 8, 8, 8, 8, 64, 0, 0, 0, 0, 0, 0, 0, 0,
8, 8, 8, 8, 0, 0, 8, 8, 8, 64, 0, 0, 0, 0, //4
16, 16, 16, 16, 16, 16, 16, 16, 16, 64, 0, 0, 0, 0,
2, 0, 3, 0, 6, 0, 7, 64, 0, 0, 0, 96, 0, 0,
6, 0, 7, 0, 4, 0, 5, 0, 2, 0, 3, 0, 0, 0,
5, 0, 4, 0, 0, 7, 0, 6, 64, 0, 0, 0, 96, 0, //8
1, 1, 1, 1, 1, 1, 64, 0, 0, 0, 0, 96, 0, 0,
1, 2, 1, 3, 1, 0, 1, 0, 1, 4, 1, 5, 64, 0,
0, 13, 11, 0, 13, 0, 64, 0, 96, 0, 0, 0, 0, 0,
0, 10, 0, 11, 0, 12, 0, 64, 0, 0, 96, 0, 0, 0, //12
0, 12, 0, 11, 0, 10, 0, 64, 0, 0, 96, 0, 0, 0,
0, 13, 0, 64, 0, 0, 96, 0, 0, 0, 0, 0, 0, 0,
14, 14, 14, 0, 14, 14, 14, 64, 0, 0, 0, 0, 0, 0,
14, 14, 14, 14, 14, 64, 0, 0, 0, 0, 0, 0, 0, 0, //16
16, 16, 1, 16, 16, 1, 16, 16, 1, 64, 0, 0, 0, 96,
7, 0, 6, 0, 5, 0, 4, 0, 3, 0, 2, 0, 0, 0,
11, 0, 13, 0, 11, 0, 12, 0, 10, 0, 11, 0, 0, 0,
0, 0, 9, 0, 0, 0, 0, 96, 0, 0, 0, 0, 0, 0, //20
15, 0, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17, 0, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18, 0, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
byte stage_map[] = {
0, 6, 3, 9, 1, 4, 2, 0,//ST1
3, 6, 9, 8, 4, 0, 7, 2,
9, 3, 1, 4, 10, 3, 8, 20,
10, 6, 7, 0, 9, 2, 4, 3,
3, 9, 1, 4, 0, 0, 0, 0,
15, 0, 3, 16, 14, 4, 5, 12, //ST2
16, 4, 0, 13, 3, 15, 14, 21,
16, 3, 5, 3, 11, 17, 5, 14,
15, 0, 22, 5, 3, 16, 14, 5,
15, 16, 17, 4, 0, 0, 0, 0,
0, 1, 2, 3, 4, 5, 6, 7,//ST3
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 0, 20, 23, 21,
};
//
//GAME SYSTEM INITIALIZE
//
void gameinit()
{
for (int i = 0; i < MAX_OBJ; i++) o_f[o_nm] = 0;
Data_Load();
}
//
//GAME SYSTEM MAIN LOOP
//
byte kct = 0;
void gameloop() {
//SCENE PROCESSING
switch (scene)
{
case 0://TITLE
default:
//INITIALIZE
if (GS_systimer == 0) {
Data_Save();
LONG_P_CT = 4; //
led_r = 0; led_g = 0; led_b = 0;
}
//MENU PROCESSING
//GAME LEVEL SELECT
if (but_TOP && kct == 0) {
GAME_LEVEL--; if (GAME_LEVEL < 0)GAME_LEVEL = 0;
kct = 8;
}
if (but_DOWN && kct == 0) {
GAME_LEVEL++; if (GAME_LEVEL > 2)GAME_LEVEL = 2;
kct = 8;
}
//--NO OPTION
//NEO_PIXEL ON/OFF
if (but_LEFT && but_RIGHT && kct == 0) {
NEO_P_MODE++; NEO_P_MODE %= 2;
if(NEO_P_MODE==0)GAME_LEVEL++; GAME_LEVEL %= 3;
ClearNPX();
kct = 8;
}
else
{
//STAGE SELECT
if (but_LEFT && kct == 0) {
stage--; if (stage < 0)stage = 2;
kct = 8;
}
if (but_RIGHT && kct == 0) {
stage++; if (stage > 2)stage = 0;
kct = 8;
}
}
//
if (kct > 0)kct--;
if (but_A || but_B || S_but_A || S_but_B) {
CTL_Mode = 0;
if (S_but_A || S_but_B)CTL_Mode = 1;
R_Key &= (~48);
snd_play(1, "/enter.mp3", 0.2f);
GS_mode = 0;
work0 = 0;
GS_systimer = -1;
scene = 1;
work0 = 0;
r_timer = 3000;
item = 0;
score = 0;
ecount = 0;
lap = 1;
emode = 0;
stoper = 0;
bomb_nm = 0; bomb_ct = 0;
//DLOG=0;
int n;
for (n = 0; n < MAX_OBJ; n++) {
o_f[n] = 0;
}
over_f = 0;
}
//DISPLAY OUT
put_sprite(SPF_FILL, 0, DISPLAY_WIDTH3, DISPLAY_HEIGHT3, 0, 0xffff, 0, 240, 240);
put_sprite(SPF_NOR, 5, DISPLAY_WIDTH3, DISPLAY_HEIGHT2 + 84, 1);
//
put_sprite_str_center("SELECT STAGE", DISPLAY_WIDTH3, DISPLAY_HEIGHT2 + 168, 1);
if (stage == 2)
put_sprite_str_center("ENDLESS STAGE", DISPLAY_WIDTH3, DISPLAY_HEIGHT2 + 188, 2);
else
{
sprintf(str_out, "STAGE %1d", (stage + 1));
put_sprite_str_center(str_out, DISPLAY_WIDTH3, DISPLAY_HEIGHT2 + 188, 2);
}
sprintf(str_out, "HI-SCORE:%5d", hi_sc[stage]);
put_sprite_str(str_out, DISPLAY_WIDTH2 + 3, DISPLAY_HEIGHT2, 1);
//LEVEL
if (GAME_LEVEL == 0)sprintf(str_out, "LV:NOR");
else
if (GAME_LEVEL == 2)sprintf(str_out, "LV:EXT");
else
sprintf(str_out, "LV:HRD");
put_sprite_str(str_out, DISPLAY_WIDTH3 + 5+10*5 , DISPLAY_HEIGHT2, C8(192, 48, 0));
//M5S Ver SP_STATUS
if (NEO_P_MODE == 0)sprintf(str_out, "NPX:ON");
else
sprintf(str_out, "NPX:OFF");
put_sprite_str(str_out, DISPLAY_WIDTH2 + 3 , DISPLAY_HEIGHT2 + 222, C8(0, 24, 240));
sprintf(str_out, "Version:%3dNS", sys_ver);
put_sprite_str(str_out, DISPLAY_WIDTH3 + 5 - 18, DISPLAY_HEIGHT2 + 222, C8(0, 24, 240));
break;
case 1://GAME MAIN
if (GS_systimer == 0) {
LONG_P_CT = 2; //
if (Get_OBJ((byte)0, (byte)0) != 65535) {
o_pt[o_nm] = 0;
o_x[o_nm] = 0;
o_y[o_nm] = 0;
o_p3[o_nm] = 0;
if (stage == 0)o_p4[o_nm] = 0;
if (stage == 1)o_p4[o_nm] = 40;
if (stage == 2)o_p4[o_nm] = 80;
o_p5[o_nm] = 0;
o_p6[o_nm] = 0;
o_p7[o_nm] = 0;
}
#ifdef FIRE_MODE
if (stage == 2)snd_play(0, "/bgm002.mp3", 0.3f);
else if (stage == 1)snd_play(0, "/bgm003.mp3", 0.3f);
else
snd_play(0, "/bgm001.mp3", 0.3f);
#else
if (stage == 2)snd_play(0, "/bgm002.mp3", 0.3f);
else if (stage == 1)snd_play(0, "/bgm001.mp3", 0.3f);
else
snd_play(0, "/bgm001.mp3", 0.3f);
#endif
};
//DISPLAY OUT
if (stage != 2)sprintf(str_out, "R_T:%4d", r_timer);
else
sprintf(str_out, " NAP:%2d", ept);
put_sprite_str(str_out, DISPLAY_WIDTH3 + 35, DISPLAY_HEIGHT2, 0);
sprintf(str_out, "LIFE:");
for (int i = 0; i < o_h[my_nm]; i++)strcat(str_out, "@");
//sprintf(str_out,"LIFE:%2d",o_h[my_nm]);
put_sprite_str(str_out, DISPLAY_WIDTH2 + 3, DISPLAY_HEIGHT2, 0);
sprintf(str_out, "ENE:%3d%%", bomb_nm * 100 / 180);
short p = C8(255, 0, 0);
if (bomb_nm >= 180)p = C8(0, 255, 255);
else if (bomb_nm >= 120)p = C8(0, 255, 0);
else if (bomb_nm >= 60)p = C8(255, 255, 0);
put_sprite_str(str_out, DISPLAY_WIDTH2 + 3, DISPLAY_HEIGHT2 + 16, p);
if (item % 3 == 1)sprintf(str_out, "POW:%1d >", o_p1[my_nm]);
else if (item % 3 == 2)sprintf(str_out, "POW:%1d >>", o_p1[my_nm]);
else
sprintf(str_out, "POW:%1d >>>", o_p1[my_nm]);
put_sprite_str(str_out, DISPLAY_WIDTH2 + 3, DISPLAY_HEIGHT2 + 222, 0);
sprintf(str_out, "SCORE:%5d", score);
put_sprite_str(str_out, DISPLAY_WIDTH3 + 5, DISPLAY_HEIGHT2 + 222, 0);
//
if (over_f == 1) {
sprintf(str_out, "GAME OVER");
put_sprite_str_center(str_out, DISPLAY_WIDTH3, DISPLAY_HEIGHT2 + 92, 0xe0);
}
else if (over_f == 2) {
sprintf(str_out, "TIME OVER");
put_sprite_str_center(str_out, DISPLAY_WIDTH3, DISPLAY_HEIGHT2 + 92, 0xfc);
}
//
if (DUAL_BUTTON_FLAG != 0 && S_but_C);
else
Run_OBJ();
break;
}
GS_systimer++;
}
//========================================================================
//DATA SAVE/LOAD >SPIFFS
//========================================================================
void Data_Save() {
//encode
for (int i = 0; i < 3; i++) {
SaveData[3 + (i << 2)] = (hi_sc[i] >> 24) & 0xff;
SaveData[2 + (i << 2)] = (hi_sc[i] >> 16) & 0xff;
SaveData[1 + (i << 2)] = (hi_sc[i] >> 8) & 0xff;
SaveData[0 + (i << 2)] = (hi_sc[i] & 0xff);
}
//
File f = SPIFFS.open("/SS_ESRr_M5.data", "w");
if (f) {
f.write(SaveData, sizeof(SaveData));
f.close();
}
else
f.close();
}
void Data_Load() {
//
File f = SPIFFS.open("/SS_ESRr_M5.data", "r");
if (f && !f.isDirectory()) {
f.read(SaveData, sizeof(SaveData));
f.close();
//decode
for (int i = 0; i < 3; i++)
hi_sc[i] = SaveData[0 + (i << 2)] | (SaveData[1 + (i << 2)] << 8) | (SaveData[2 + (i << 2)] << 16) | (SaveData[3 + (i << 2)] << 24);
//
}
else
f.close();
//
}
//========================================================================
//SYSTEM OTHERS
//========================================================================
void Loop_T_ADJ(byte m) { //Speed adjustment
while (-1) {
if (FrameTime + game_speed < millis())break;
delay(1);
}
}
//get next INT_Random
int Next_I_Random() {
return (random(0xffff) - 0x8000);
}
//
// Draw GAME Graphics
//
void paint() {
int i;
switch (scene)
{
case 1:
for (i = MAX_OBJ - 1; i >= 0; i--) {
if (o_f[i] == 0 || o_pt[i] == 0)continue;
if (o_ptf[i] == 0) {
put_sprite(SPF_NOR | SPF_F_TRA, o_pt[i] - 1, DISPLAY_WIDTH3 + o_x[i] / 50, DISPLAY_HEIGHT3 + o_y[i] / 50, 1);
continue;
}
else if (o_ptf[i] == 1) {
put_sprite(SPF_NOR, o_pt[i] - 1, DISPLAY_WIDTH3 + o_x[i] / 50, DISPLAY_HEIGHT3 + o_y[i] / 50, 0);
continue;
}
else if (o_ptf[i] == 2) {
put_sprite(SPF_MOD, o_pt[i] - 1, DISPLAY_WIDTH3 + o_x[i] / 50, DISPLAY_HEIGHT3 + o_y[i] / 50, 1, ((o_p2[i] + 16) & 31) * 36000 / 32, 10000);
continue;
}
else if (o_ptf[i] == 3) {
put_sprite(SPF_TRAN, o_pt[i] - 1, DISPLAY_WIDTH3 + o_x[i] / 50, DISPLAY_HEIGHT3 + o_y[i] / 50, 1);
continue;
}
}
break;
}
//Sprite Draw
paint_sprite();
// //STAB Clear
// img.fillRect(0,0,40,240,0);img.fillRect(280,0,40,240,0);
//FLASH
img.pushSprite(40, 0);
}
int Get_OBJ(byte f, byte a) {
int i;
f++;
for (i = 0; i < MAX_OBJ; i++) {
if (o_f[i] == 0) {
o_f[i] = f;
o_a[i] = a;
o_hn[i] = 0;
o_p0[i] = 0;
o_ptf[i] = 0;
break;
}
}
if (i == MAX_OBJ)i = 65535;
else
o_nm = i;
return i;
}
int Get_OBJ2(byte f, byte a) {
int i;
f++;
for (i = MAX_OBJ - 1; i >= 0; i--) {
if (o_f[i] == 0) {
o_f[i] = f;
o_a[i] = a;
o_hn[i] = 0;
o_p0[i] = 0;
o_ptf[i] = 0;