forked from zeropolis79/PETSCIIRobots-SDL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpetrobots.cpp
5892 lines (5589 loc) · 185 KB
/
petrobots.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
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
/**
* PETSCII Robots (Portable version)
* by David Murray 2020
* ported by Vesa Halttunen 2021-2022
*/
#if defined(_AMIGA)
#include "PlatformAmiga.h"
#elif defined(_PSP)
#include "PlatformPSP.h"
#else
#include "PlatformVita.h"
#endif
#include "petrobots.h"
// MAP FILES CONSIST OF EVERYTHING FROM THIS POINT ON
uint8_t MAP_DATA[8960];
// END OF MAP FILE
uint8_t* DESTRUCT_PATH; // Destruct path array (256 bytes)
uint8_t* TILE_ATTRIB; // Tile attrib array (256 bytes)
#ifndef PLATFORM_SPRITE_SUPPORT
uint8_t* TILE_DATA_TL; // Tile character top-left (256 bytes)
uint8_t* TILE_DATA_TM; // Tile character top-middle (256 bytes)
uint8_t* TILE_DATA_TR; // Tile character top-right (256 bytes)
uint8_t* TILE_DATA_ML; // Tile character middle-left (256 bytes)
uint8_t* TILE_DATA_MM; // Tile character middle-middle (256 bytes)
uint8_t* TILE_DATA_MR; // Tile character middle-right (256 bytes)
uint8_t* TILE_DATA_BL; // Tile character bottom-left (256 bytes)
uint8_t* TILE_DATA_BM; // Tile character bottom-middle (256 bytes)
uint8_t* TILE_DATA_BR; // Tile character bottom-right (256 bytes)
#endif
// These arrays can go anywhere in RAM
uint8_t UNIT_TIMER_A[64]; // Primary timer for units (64 bytes)
uint8_t UNIT_TIMER_B[64]; // Secondary timer for units (64 bytes)
uint8_t UNIT_TILE[32]; // Current tile assigned to unit (32 bytes)
uint8_t UNIT_DIRECTION[32]; // Movement direction of unit (32 bytes)
uint8_t EXP_BUFFER[16]; // Explosion Buffer (16 bytes)
uint8_t MAP_PRECALC[MAP_WINDOW_SIZE]; // Stores pre-calculated objects for map window (77 bytes)
uint8_t MAP_PRECALC_DIRECTION[MAP_WINDOW_SIZE]; // Stores pre-calculated object directions for map window (77 bytes)
uint8_t MAP_PRECALC_TYPE[MAP_WINDOW_SIZE]; // Stores pre-calculated object types for map window (77 bytes)
#ifdef OPTIMIZED_MAP_RENDERING
uint8_t PREVIOUS_MAP_BACKGROUND[MAP_WINDOW_SIZE];
uint8_t PREVIOUS_MAP_BACKGROUND_VARIANT[MAP_WINDOW_SIZE];
uint8_t PREVIOUS_MAP_FOREGROUND[MAP_WINDOW_SIZE];
uint8_t PREVIOUS_MAP_FOREGROUND_VARIANT[MAP_WINDOW_SIZE];
#endif
// The following are the locations where the current
// key controls are stored. These must be set before
// the game can start.
uint8_t KEY_CONFIG[26];
enum KEYS {
KEY_MOVE_UP,
KEY_MOVE_DOWN,
KEY_MOVE_LEFT,
KEY_MOVE_RIGHT,
KEY_FIRE_UP,
KEY_FIRE_DOWN,
KEY_FIRE_LEFT,
KEY_FIRE_RIGHT,
KEY_CYCLE_WEAPONS,
KEY_CYCLE_ITEMS,
KEY_USE,
KEY_SEARCH,
KEY_MOVE,
KEY_LIVE_MAP,
KEY_LIVE_MAP_ROBOTS,
KEY_PAUSE,
KEY_MUSIC,
KEY_CHEAT,
KEY_CURSOR_UP,
KEY_CURSOR_DOWN,
KEY_CURSOR_LEFT,
KEY_CURSOR_RIGHT,
KEY_SPACE,
KEY_RETURN,
KEY_YES,
KEY_NO
};
uint8_t TILE; // The tile number to be plotted
uint8_t DIRECTION; // The direction of the tile to be plotted
uint8_t WALK_FRAME; // Player walking animation frame
uint8_t DEMATERIALIZE_FRAME; // Dematerialize animation frame
uint8_t MAP_X; // Current X location on map
uint8_t MAP_Y; // Current Y location on map
uint8_t MAP_WINDOW_X; // Top left location of what is displayed in map window
uint8_t MAP_WINDOW_Y; // Top left location of what is displayed in map window
uint8_t DECNUM; // a decimal number to be displayed onscreen as 3 digits.
uint8_t ATTRIB; // Tile attribute value
uint8_t UNIT; // Current unit being processed
uint8_t TEMP_A; // used within some routines
uint8_t TEMP_B; // used within some routines
uint8_t TEMP_C; // used within some routines
uint8_t TEMP_D; // used within some routines
uint8_t CURSOR_X; // For on-screen cursor
uint8_t CURSOR_Y; // For on-screen cursor
uint8_t CURSOR_ON; // Is cursor active or not? 1=yes 0=no
uint8_t REDRAW_WINDOW; // 1=yes 0=no
uint8_t MOVE_RESULT; // 1=Move request success, 0=fail.
uint8_t UNIT_FIND; // 255=no unit present.
uint8_t MOVE_TYPE; // %00000001=WALK %00000010=HOVER
uint8_t* CUR_PATTERN; // stores the memory location of the current musical pattern being played.
uint8_t* MAP_SOURCE; // $FD
uint8_t SCREEN_MEMORY[SCREEN_WIDTH_IN_CHARACTERS * SCREEN_HEIGHT_IN_CHARACTERS]; // $8000
int main(int argc, char *argv[])
{
PlatformClass platformInstance;
if (!platform) {
return 1;
}
convertToPETSCII(INTRO_MESSAGE);
convertToPETSCII(MSG_CANTMOVE);
convertToPETSCII(MSG_BLOCKED);
convertToPETSCII(MSG_SEARCHING);
convertToPETSCII(MSG_NOTFOUND);
convertToPETSCII(MSG_FOUNDKEY);
convertToPETSCII(MSG_FOUNDGUN);
convertToPETSCII(MSG_FOUNDEMP);
convertToPETSCII(MSG_FOUNDBOMB);
convertToPETSCII(MSG_FOUNDPLAS);
convertToPETSCII(MSG_FOUNDMED);
convertToPETSCII(MSG_FOUNDMAG);
convertToPETSCII(MSG_MUCHBET);
convertToPETSCII(MSG_EMPUSED);
convertToPETSCII(MSG_TERMINATED);
convertToPETSCII(MSG_TRANS1);
convertToPETSCII(MSG_ELEVATOR);
convertToPETSCII(MSG_LEVELS);
convertToPETSCII(MSG_PAUSED);
convertToPETSCII(MSG_MUSICON);
convertToPETSCII(MSG_MUSICOFF);
convertToPETSCII(MAP_NAMES);
convertToPETSCII(LOAD_MSG2);
convertToPETSCII(INTRO_OPTIONS);
convertToPETSCII(DIFF_LEVEL_WORDS);
convertToPETSCII(WIN_MSG);
convertToPETSCII(LOS_MSG);
convertToPETSCII(CONTROLTEXT);
convertToPETSCII(CINEMA_MESSAGE);
for (int i = 0; i < PLATFORM_MAP_WINDOW_TILES_HEIGHT; i++) {
MAP_CHART[i] = i * 3 * SCREEN_WIDTH_IN_CHARACTERS;
}
platform->stopNote(); // RESET SOUND TO ZERO
#ifdef PLATFORM_STDOUT_MESSAGES
DISPLAY_LOAD_MESSAGE1();
#endif
TILE_LOAD_ROUTINE();
SETUP_INTERRUPT();
SET_CONTROLS(); // copy initial key controls
while (!platform->quit) {
INTRO_SCREEN();
}
return 0;
}
void INIT_GAME()
{
SCREEN_SHAKE = 0;
#ifdef PLATFORM_LIVE_MAP_SUPPORT
LIVE_MAP_ON = 0;
#ifdef PLATFORM_LIVE_MAP_SINGLE_KEY
LIVE_MAP_ROBOTS_ON = 0;
#endif
#endif
RESET_KEYS_AMMO();
platform->fadeScreen(0, false);
DISPLAY_GAME_SCREEN();
#ifndef INACTIVITY_TIMEOUT_GAME
DISPLAY_LOAD_MESSAGE2();
#endif
platform->fadeScreen(15, false);
MAP_LOAD_ROUTINE();
#ifdef PLATFORM_MODULE_BASED_AUDIO
START_IN_GAME_MUSIC();
#endif
SET_DIFF_LEVEL();
ANIMATE_PLAYER();
CACULATE_AND_REDRAW();
#ifdef OPTIMIZED_MAP_RENDERING
INVALIDATE_PREVIOUS_MAP();
#endif
DRAW_MAP_WINDOW();
DISPLAY_PLAYER_HEALTH();
DISPLAY_KEYS();
DISPLAY_WEAPON();
UNIT_TYPE[0] = 1;
SET_INITIAL_TIMERS();
PRINT_INTRO_MESSAGE();
KEYTIMER = 30;
MAIN_GAME_LOOP();
}
//char MAPNAME[] = "level-a";
#ifdef PLATFORM_STDOUT_MESSAGES
const char* LOADMSG1 = "loading tiles...\x0d";
#endif
uint8_t KEYS = 0; // bit0=spade bit2=heart bit3=star
uint8_t AMMO_PISTOL = 0; // how much ammo for the pistol
uint8_t AMMO_PLASMA = 0; // how many shots of the plasmagun
uint8_t INV_BOMBS = 0; // How many bombs do we have
uint8_t INV_EMP = 0; // How many EMPs do we have
uint8_t INV_MEDKIT = 0; // How many medkits do we have?
uint8_t INV_MAGNET = 0; // How many magnets do we have?
uint8_t SELECTED_WEAPON = 0; // 0=none 1=pistol 2=plasmagun
uint8_t SELECTED_ITEM = 0; // 0=none 1=bomb 2=emp 3=medkit 4=magnet
uint8_t SELECT_TIMEOUT = 0; // can only change weapons once it hits zero
uint8_t ANIMATE = 1; // 0=DISABLED 1=ENABLED
uint8_t BIG_EXP_ACT = 0; // 0=No explosion active 1=big explosion active
uint8_t MAGNET_ACT = 0; // 0=no magnet active 1=magnet active
uint8_t PLASMA_ACT = 0; // 0=No plasma fire active 1=plasma fire active
uint8_t RANDOM = 0; // used for random number generation
uint8_t BORDER = 0; // Used for border flash timing
uint8_t SCREEN_SHAKE = 0; // 1=shake 0=no shake
uint8_t CONTROL = PLATFORM_DEFAULT_CONTROL; // 0=keyboard 1=custom keys 2=snes 3=analog
uint16_t BORDER_COLOR = 0xf00; // Used for border flash coloring
char INTRO_MESSAGE[] = "welcome to "
PLATFORM_NAME
"-robots!\xff"
"by david murray 2021\xff"
PLATFORM_NAME
" port by vesa halttunen and nolemretaw";
char MSG_CANTMOVE[] = "can't move that!";
char MSG_BLOCKED[] = "blocked!";
char MSG_SEARCHING[] = "searching";
char MSG_NOTFOUND[] = "nothing found here.";
char MSG_FOUNDKEY[] = "you found a key card!";
char MSG_FOUNDGUN[] = "you found a pistol!";
char MSG_FOUNDEMP[] = "you found an emp device!";
char MSG_FOUNDBOMB[] = "you found a timebomb!";
char MSG_FOUNDPLAS[] = "you found a plasma gun!";
char MSG_FOUNDMED[] = "you found a medkit!";
char MSG_FOUNDMAG[] = "you found a magnet!";
char MSG_MUCHBET[] = "ahhh, much better!";
char MSG_EMPUSED[] = "emp activated!\xff"
"nearby robots are rebooting.";
char MSG_TERMINATED[] = "you're terminated!";
char MSG_TRANS1[] = "transporter will not activate\xff"
"until all robots destroyed.";
char MSG_ELEVATOR[] = "[ elevator panel ] down\xff"
"[ select level ] opens";
char MSG_LEVELS[] = "[ ] door";
#ifdef INACTIVITY_TIMEOUT_GAME
char MSG_PAUSED[] = "exit game?\xff"
"left=yes right=no";
#else
char MSG_PAUSED[] = "game paused.\xff"
"exit game (y/n)";
#endif
char MSG_MUSICON[] = "music on.";
char MSG_MUSICOFF[] = "music off.";
uint8_t SELECTED_MAP = 0;
char MAP_NAMES[] = "01-research lab "
"02-headquarters "
"03-the village "
"04-the islands "
"05-downtown "
"06-pi university"
"07-more islands "
"08-robot hotel "
"09-forest moon "
"10-death tower "
"11-river death "
"12-bunker "
"13-castle robot "
"14-rocket center";
#ifdef PLATFORM_MODULE_BASED_AUDIO
uint8_t MUSIC_ON = 1; // 0=off 1=on
#else
// THE FOLLOWING ARE USED BY THE SOUND SYSTEM*
uint8_t TEMPO_TIMER = 0; // used for counting down to the next tick
uint8_t TEMPO = 7; // How many IRQs between ticks
uint8_t DATA_LINE = 0; // used for playback to keep track of which line we are executing.
uint8_t ARP_MODE = 0; // 0=no 1=major 2=minor 3=sus4
uint8_t CHORD_ROOT = 0; // root note of the chord
uint8_t MUSIC_ON = 0; // 0=off 1=on
uint8_t SOUND_EFFECT = 0xff; // FF=OFF or number of effect in progress
#endif
#ifdef PLATFORM_STDOUT_MESSAGES
void DISPLAY_LOAD_MESSAGE1()
{
for (int Y = 0; Y != 17; Y++) {
platform->chrout(LOADMSG1[Y]);
}
}
#endif
// Displays loading message for map.
void DISPLAY_LOAD_MESSAGE2()
{
int Y;
for (Y = 0; Y != 12; Y++) {
writeToScreenMemory((PLATFORM_SCREEN_HEIGHT - 32) / 2 / 8 * SCREEN_WIDTH_IN_CHARACTERS + (PLATFORM_SCREEN_WIDTH - 320) / 2 / 8 + Y, LOAD_MSG2[Y]);
}
char* name = CALC_MAP_NAME();
for (Y = 0; Y != 16; Y++) {
writeToScreenMemory((PLATFORM_SCREEN_HEIGHT - 32) / 2 / 8 * SCREEN_WIDTH_IN_CHARACTERS + (PLATFORM_SCREEN_WIDTH - 320) / 2 / 8 + 12 + Y, name[Y]);
}
}
char LOAD_MSG2[] = "loading map:";
void SETUP_INTERRUPT()
{
platform->setInterrupt(&RUNIRQ);
}
// This is the routine that runs every 60 seconds from the IRQ.
// BGTIMER1 is always set to 1 every cycle, after which the main
// program will reset it to 0 when it is done with it's work for
// that cycle. BGTIMER2 is a count-down to zero and then stays
// there.
void RUNIRQ()
{
#ifndef PLATFORM_MODULE_BASED_AUDIO
MUSIC_ROUTINE();
#endif
UPDATE_GAME_CLOCK();
ANIMATE_WATER();
BGTIMER1 = 1;
if (BGTIMER2 != 0) {
BGTIMER2--;
}
if (KEYTIMER != 0) {
KEYTIMER--;
}
if (BORDER != 0) {
BORDER--;
platform->fadeScreen(15 - BORDER);
}
#ifdef PLATFORM_HARDWARE_BASED_SHAKE_SCREEN
if (CLOCK_ACTIVE != 0 && SCREEN_SHAKE != 0) {
platform->shakeScreen();
}
#endif
// Back to usual IRQ routine
}
uint8_t BGTIMER1 = 0;
uint8_t BGTIMER2 = 0;
uint8_t KEYTIMER = 0; // Used for repeat of movement
// Since the PET has no real-time clock, and the Jiffy clock
// is a pain to read from assembly language, I have created my own.
void UPDATE_GAME_CLOCK()
{
if (CLOCK_ACTIVE != 1) {
return;
}
CYCLES++;
if (CYCLES != platform->framesPerSecond()) { // 60 for ntsc or 50 for pal
return;
}
CYCLES = 0;
SECONDS++;
#ifdef INACTIVITY_TIMEOUT_GAME
INACTIVE_SECONDS++;
#endif
if (SECONDS != 60) {
return;
}
SECONDS = 0;
MINUTES++;
if (MINUTES != 60) {
return;
}
SECONDS = 0;
MINUTES = 0;
HOURS++;
}
uint8_t HOURS = 0;
uint8_t MINUTES = 0;
uint8_t SECONDS = 0;
uint8_t CYCLES = 0;
uint8_t CLOCK_ACTIVE = 0;
#ifdef INACTIVITY_TIMEOUT_GAME
uint8_t INACTIVE_SECONDS = 0;
#endif
// This routine spaces out the timers so that not everything
// is running out once. It also starts the game_clock.
void SET_INITIAL_TIMERS()
{
CLOCK_ACTIVE = 1;
for (int X = 1; X != 48; X++) {
UNIT_TIMER_A[X] = X;
UNIT_TIMER_B[X] = 0;
}
}
void MAIN_GAME_LOOP()
{
platform->renderFrame();
bool done = false;
while (!done && !platform->quit) {
#ifdef INACTIVITY_TIMEOUT_GAME
if (INACTIVE_SECONDS >= INACTIVITY_TIMEOUT_GAME) {
return;
}
#endif
if (BGTIMER1 != 1) {
platform->renderFrame(true);
}
PET_SCREEN_SHAKE();
BACKGROUND_TASKS();
if (UNIT_TYPE[0] != 1) { // Is player unit alive
GAME_OVER();
return;
}
KEY_REPEAT(platform->isKeyOrJoystickPressed(CONTROL >= 2 ? true : false));
uint8_t A = platform->readKeyboard();
uint16_t B = platform->readJoystick(CONTROL >= 2 ? true : false);
// Keyboard controls here.
if (A != 0xff) {
#ifdef INACTIVITY_TIMEOUT_GAME
INACTIVE_SECONDS = 0;
#endif
KEYTIMER = 5;
if (A == KEY_CONFIG[KEY_CURSOR_RIGHT] || A == KEY_CONFIG[KEY_MOVE_RIGHT]) { // CURSOR RIGHT
UNIT = 0;
MOVE_TYPE = 1; // %00000001
REQUEST_WALK_RIGHT();
AFTER_MOVE();
} else if (A == KEY_CONFIG[KEY_CURSOR_LEFT] || A == KEY_CONFIG[KEY_MOVE_LEFT]) { // CURSOR LEFT
UNIT = 0;
MOVE_TYPE = 1; // %00000001
REQUEST_WALK_LEFT();
AFTER_MOVE();
} else if (A == KEY_CONFIG[KEY_CURSOR_DOWN] || A == KEY_CONFIG[KEY_MOVE_DOWN]) { // CURSOR DOWN
UNIT = 0;
MOVE_TYPE = 1; // %00000001
REQUEST_WALK_DOWN();
AFTER_MOVE();
} else if (A == KEY_CONFIG[KEY_CURSOR_UP] || A == KEY_CONFIG[KEY_MOVE_UP]) { // CURSOR UP
UNIT = 0;
MOVE_TYPE = 1; // %00000001
REQUEST_WALK_UP();
AFTER_MOVE();
} else if (A == KEY_CONFIG[KEY_CYCLE_WEAPONS]) {
CYCLE_WEAPON();
CLEAR_KEY_BUFFER();
} else if (A == KEY_CONFIG[KEY_CYCLE_ITEMS]) {
CYCLE_ITEM();
CLEAR_KEY_BUFFER();
} else if (A == KEY_CONFIG[KEY_MOVE]) {
MOVE_OBJECT();
CLEAR_KEY_BUFFER();
} else if (A == KEY_CONFIG[KEY_SEARCH]) {
SEARCH_OBJECT();
CLEAR_KEY_BUFFER();
} else if (A == KEY_CONFIG[KEY_USE]) {
USE_ITEM();
CLEAR_KEY_BUFFER();
} else if (A == KEY_CONFIG[KEY_FIRE_UP]) {
FIRE_UP();
KEYTIMER = 20;
} else if (A == KEY_CONFIG[KEY_FIRE_LEFT]) {
FIRE_LEFT();
KEYTIMER = 20;
} else if (A == KEY_CONFIG[KEY_FIRE_DOWN]) {
FIRE_DOWN();
KEYTIMER = 20;
} else if (A == KEY_CONFIG[KEY_FIRE_RIGHT]) {
FIRE_RIGHT();
KEYTIMER = 20;
} else if (A == KEY_CONFIG[KEY_PAUSE]) { // RUN/STOP
done = PAUSE_GAME();
} else if (A == KEY_CONFIG[KEY_CHEAT]) { // SHIFT-C
CHEATER();
CLEAR_KEY_BUFFER();
} else if (A == KEY_CONFIG[KEY_MUSIC]) { // SHIFT-M
TOGGLE_MUSIC();
CLEAR_KEY_BUFFER();
}
#ifdef PLATFORM_LIVE_MAP_SUPPORT
else if (A == KEY_CONFIG[KEY_LIVE_MAP]) {
TOGGLE_LIVE_MAP();
CLEAR_KEY_BUFFER();
} else if (A == KEY_CONFIG[KEY_LIVE_MAP_ROBOTS]) {
TOGGLE_LIVE_MAP_ROBOTS();
CLEAR_KEY_BUFFER();
}
#endif
}
// SNES CONTROLLER starts here
if (B != 0) {
#ifdef INACTIVITY_TIMEOUT_GAME
INACTIVE_SECONDS = 0;
#endif
// first we start with the 4 directional buttons.
if ((CONTROL >= 2 && (B & Platform::JoystickPlay) == 0) ||
(CONTROL < 2 && (B & Platform::JoystickBlue) == 0)) {
if (CONTROL < 2 && B & Platform::JoystickRed) {
if (B & Platform::JoystickLeft) {
FIRE_LEFT();
KEYTIMER = 20;
} else if (B & Platform::JoystickRight) {
FIRE_RIGHT();
KEYTIMER = 20;
} else if (B & Platform::JoystickUp) {
FIRE_UP();
KEYTIMER = 20;
} else if (B & Platform::JoystickDown) {
FIRE_DOWN();
KEYTIMER = 20;
}
} else {
if (B & Platform::JoystickLeft) {
UNIT = 0;
MOVE_TYPE = 1; // %00000001
REQUEST_WALK_LEFT();
AFTER_MOVE_SNES();
} else if (B & Platform::JoystickRight) {
UNIT = 0;
MOVE_TYPE = 1; // %00000001
REQUEST_WALK_RIGHT();
AFTER_MOVE_SNES();
} else if (B & Platform::JoystickUp) {
UNIT = 0;
MOVE_TYPE = 1; // %00000001
REQUEST_WALK_UP();
AFTER_MOVE_SNES();
} else if (B & Platform::JoystickDown) {
UNIT = 0;
MOVE_TYPE = 1; // %00000001
REQUEST_WALK_DOWN();
AFTER_MOVE_SNES();
}
}
}
// Now check for non-repeating buttons
switch (CONTROL) {
case 3:
if (B & Platform::JoystickPlay) {
if (B & Platform::JoystickLeft) {
FIRE_LEFT();
KEYTIMER = 20;
}
if (B & Platform::JoystickRight) {
FIRE_RIGHT();
KEYTIMER = 20;
}
if (B & Platform::JoystickUp) {
FIRE_UP();
KEYTIMER = 20;
}
if (B & Platform::JoystickDown) {
FIRE_DOWN();
KEYTIMER = 20;
}
if (B & Platform::JoystickExtra) {
TOGGLE_MUSIC();
CLEAR_KEY_BUFFER();
}
#ifdef PLATFORM_LIVE_MAP_SUPPORT
if (B & Platform::JoystickYellow) {
TOGGLE_LIVE_MAP_ROBOTS();
CLEAR_KEY_BUFFER();
}
#endif
} else {
#ifdef PLATFORM_LIVE_MAP_SUPPORT
if (B & Platform::JoystickYellow) {
TOGGLE_LIVE_MAP();
CLEAR_KEY_BUFFER();
}
#endif
if (B & Platform::JoystickGreen) {
CYCLE_ITEM();
KEYTIMER = 15;
}
if (B & Platform::JoystickBlue) {
CYCLE_WEAPON();
KEYTIMER = 15;
}
if (B & Platform::JoystickRed) {
USE_ITEM();
KEYTIMER = 15;
}
if (B & Platform::JoystickReverse) {
SEARCH_OBJECT();
KEYTIMER = 15;
}
if (B & Platform::JoystickForward) {
MOVE_OBJECT();
KEYTIMER = 15;
}
if (B & Platform::JoystickExtra) {
done = PAUSE_GAME();
}
}
break;
case 2:
if (B & Platform::JoystickPlay) {
if (B & Platform::JoystickReverse) {
CYCLE_ITEM();
KEYTIMER = 15;
}
if (B & Platform::JoystickForward) {
CYCLE_WEAPON();
KEYTIMER = 15;
}
#ifdef PLATFORM_LIVE_MAP_SUPPORT
if (B & Platform::JoystickLeft) {
TOGGLE_LIVE_MAP();
CLEAR_KEY_BUFFER();
}
if (B & Platform::JoystickDown) {
TOGGLE_LIVE_MAP_ROBOTS();
CLEAR_KEY_BUFFER();
}
#endif
if (B & Platform::JoystickBlue) {
done = PAUSE_GAME();
}
if (B & Platform::JoystickRed) {
TOGGLE_MUSIC();
CLEAR_KEY_BUFFER();
}
#ifdef GAMEPAD_CD32
if (B == Platform::JoystickPlay) {
USE_ITEM();
KEYTIMER = 15;
}
#endif
} else {
if (B & Platform::JoystickGreen) {
FIRE_LEFT();
KEYTIMER = 20;
}
if (B & Platform::JoystickBlue) {
FIRE_RIGHT();
KEYTIMER = 20;
}
if (B & Platform::JoystickYellow) {
FIRE_UP();
KEYTIMER = 20;
}
if (B & Platform::JoystickRed) {
FIRE_DOWN();
KEYTIMER = 20;
}
if (B & Platform::JoystickReverse) {
SEARCH_OBJECT();
KEYTIMER = 15;
}
if (B & Platform::JoystickForward) {
MOVE_OBJECT();
KEYTIMER = 15;
}
#ifndef GAMEPAD_CD32
if (B == Platform::JoystickExtra) {
USE_ITEM();
KEYTIMER = 15;
}
#endif
}
break;
default:
if (B & Platform::JoystickBlue) {
if (B & Platform::JoystickLeft) {
CYCLE_ITEM();
KEYTIMER = 15;
}
if (B & Platform::JoystickRight) {
CYCLE_WEAPON();
KEYTIMER = 15;
}
if (B & Platform::JoystickUp) {
MOVE_OBJECT();
KEYTIMER = 15;
}
if (B & Platform::JoystickDown) {
SEARCH_OBJECT();
KEYTIMER = 15;
}
if (B == Platform::JoystickBlue) {
USE_ITEM();
KEYTIMER = 15;
}
}
break;
}
}
}
}
// This routine handles things that are in common to
// all 4 directions of movement.
void AFTER_MOVE_SNES()
{
if (MOVE_RESULT == 1) {
ANIMATE_PLAYER();
}
CACULATE_AND_REDRAW();
if (KEY_FAST == 0) {
KEYTIMER = 15;
KEY_FAST = 1;
} else {
KEYTIMER = 6;
}
}
void TOGGLE_MUSIC()
{
if (MUSIC_ON == 1) {
PRINT_INFO(MSG_MUSICOFF);
MUSIC_ON = 0;
#ifdef PLATFORM_MODULE_BASED_AUDIO
platform->playModule(Platform::ModuleSoundFX);
#else
platform->stopNote(); // turn off sound
#endif
} else {
PRINT_INFO(MSG_MUSICON);
MUSIC_ON = 1;
START_IN_GAME_MUSIC();
}
}
void START_IN_GAME_MUSIC()
{
#ifdef PLATFORM_MODULE_BASED_AUDIO
platform->playModule(MUSIC_ON == 1 ? LEVEL_MUSIC[SELECTED_MAP] : Platform::ModuleSoundFX);
#else
MUSIC_ON = 1;
if (SOUND_EFFECT == 0xFF) { // FF=NO sound effect in progress
DATA_LINE = 0;
CUR_PATTERN = IN_GAME_MUSIC1 + (LEVEL_MUSIC[SELECTED_MAP] << 8);
} else {
// apparently a sound-effect is active, so we do things differently.
DATA_LINE_TEMP = 0;
PATTERN_TEMP = IN_GAME_MUSIC1 + (LEVEL_MUSIC[SELECTED_MAP] << 8);
}
#endif
}
#ifdef PLATFORM_MODULE_BASED_AUDIO
Platform::Module LEVEL_MUSIC[] = {
Platform::ModuleInGame1,
Platform::ModuleInGame2,
Platform::ModuleInGame3,
Platform::ModuleInGame4,
Platform::ModuleInGame1,
Platform::ModuleInGame2,
Platform::ModuleInGame3,
Platform::ModuleInGame4,
Platform::ModuleInGame1,
Platform::ModuleInGame2,
Platform::ModuleInGame3,
Platform::ModuleInGame4,
Platform::ModuleInGame1,
Platform::ModuleInGame2
};
#else
uint8_t LEVEL_MUSIC[] = { 0,1,2,0,1,2,0,1,2,0,1,2,0,1 };
#endif
// TEMP ROUTINE TO GIVE ME ALL ITEMS AND WEAPONS
void CHEATER()
{
PLAY_SOUND(12);
KEYS = 7;
AMMO_PISTOL = 100;
AMMO_PLASMA = 100;
INV_BOMBS = 100;
INV_EMP = 100;
INV_MEDKIT = 100;
INV_MAGNET = 100;
SELECTED_WEAPON = 1;
SELECTED_ITEM = 1;
#ifdef PLATFORM_IMAGE_SUPPORT
REDRAW_WINDOW = 1;
#endif
DISPLAY_KEYS();
DISPLAY_WEAPON();
DISPLAY_ITEM();
}
bool PAUSE_GAME()
{
PLAY_SOUND(15);
// pause clock
CLOCK_ACTIVE = 0;
// display message to user
SCROLL_INFO();
PRINT_INFO(MSG_PAUSED);
// for (BGTIMER1 = 0; BGTIMER1 != 1;); // to prevent double-tap of run/stop
CLEAR_KEY_BUFFER();
platform->renderFrame();
while (!platform->quit) {
uint8_t A = platform->readKeyboard();
uint16_t B = platform->readJoystick(CONTROL >= 2 ? true : false);
if (A == KEY_CONFIG[KEY_PAUSE] || // RUN/STOP
A == KEY_CONFIG[KEY_NO] ||
(B & Platform::JoystickBlue)) { // N-KEY
SCROLL_INFO();
SCROLL_INFO();
SCROLL_INFO();
CLEAR_KEY_BUFFER();
CLOCK_ACTIVE = 1;
PLAY_SOUND(15);
return false;
} else if (A == KEY_CONFIG[KEY_YES] || (B & Platform::JoystickRed)) { // Y-KEY
UNIT_TYPE[0] = 0; // make player dead
PLAY_SOUND(15);
GOM4();
return true;
}
platform->renderFrame(true);
}
return false;
}
void CLEAR_KEY_BUFFER()
{
platform->clearKeyBuffer(); // CLEAR KEYBOARD BUFFER
KEYTIMER = 20;
}
void USE_ITEM()
{
// check select timeout to prevent accidental double-tap
if (SELECT_TIMEOUT != 0) {
return;
}
// First figure out which item to use.
switch (SELECTED_ITEM) {
case 1: // BOMB
USE_BOMB();
break;
case 2: // EMP
USE_EMP();
break;
case 3: // MEDKIT
USE_MEDKIT();
break;
case 4: // MAGNET
USE_MAGNET();
break;
default:
break;
}
}
void USE_BOMB()
{
#ifdef PLATFORM_CURSOR_SHAPE_SUPPORT
platform->setCursorShape(Platform::ShapeUse);
#endif
USER_SELECT_OBJECT();
// NOW TEST TO SEE IF THAT SPOT IS OPEN
if (BOMB_MAGNET_COMMON1()) {
// Now scan for any units at that location:
CHECK_FOR_UNIT();
if (UNIT_FIND == 255) { // 255 means no unit found.
for (int X = 28; X != 32; X++) { // Start of weapons units
if (UNIT_TYPE[X] == 0) {
UNIT_TYPE[X] = 6; // bomb AI
UNIT_TILE[X] = 130; // bomb tile
UNIT_LOC_X[X] = MAP_X;
UNIT_LOC_Y[X] = MAP_Y;
UNIT_TIMER_A[X] = 100; // How long until explosion?
UNIT_A[X] = 0;
INV_BOMBS--;
DISPLAY_ITEM();
REDRAW_WINDOW = 1;
SELECT_TIMEOUT = 3; // 3 cycles before next item can be used, pet version only
PLAY_SOUND(6); // SOUND PLAY
return;
}
}
return; // no slots available right now, abort.
}
}
BOMB_MAGNET_COMMON2();
}
void USE_MAGNET()
{
if (MAGNET_ACT != 0) { // only one magnet active at a time.
return;
}
#ifdef PLATFORM_CURSOR_SHAPE_SUPPORT
platform->setCursorShape(Platform::ShapeUse);
#endif
USER_SELECT_OBJECT();
// NOW TEST TO SEE IF THAT SPOT IS OPEN
if (BOMB_MAGNET_COMMON1()) {
for (int X = 28; X != 32; X++) { // Start of weapons units
if (UNIT_TYPE[X] == 0) {
UNIT_TYPE[X] = 20; // MAGNET AI
UNIT_TILE[X] = 134; // MAGNET tile
UNIT_LOC_X[X] = MAP_X;
UNIT_LOC_Y[X] = MAP_Y;
UNIT_TIMER_A[X] = 1; // How long until ACTIVATION
UNIT_TIMER_B[X] = 255; // how long does it live -A
UNIT_A[X] = 3; // how long does it live -B
MAGNET_ACT = 1; // only one magnet allowed at a time.
INV_MAGNET--;
DISPLAY_ITEM();
REDRAW_WINDOW = 1;
PLAY_SOUND(6); // move sound, SOUND PLAY
return;
}
}
return; // no slots available right now, abort.
}
BOMB_MAGNET_COMMON2();
}
bool BOMB_MAGNET_COMMON1()
{
#ifdef PLATFORM_CURSOR_SUPPORT
platform->hideCursor();
#else
CURSOR_ON = 0;
DRAW_MAP_WINDOW(); // ERASE THE CURSOR
#endif
MAP_X = CURSOR_X + MAP_WINDOW_X;
MOVTEMP_UX = MAP_X;
MAP_Y = CURSOR_Y + MAP_WINDOW_Y;
MOVTEMP_UY = MAP_Y;
GET_TILE_FROM_MAP();
return (TILE_ATTRIB[TILE] & 0x01) == 0x01; // %00000001 is that spot available for something to move onto it?
}
void BOMB_MAGNET_COMMON2()
{
PRINT_INFO(MSG_BLOCKED);
PLAY_SOUND(11); // ERROR SOUND, SOUND PLAY
}
void USE_EMP()
{
EMP_FLASH();
// REDRAW_WINDOW = 0; // attempt to delay window redrawing (pet only)
PLAY_SOUND(3); // EMP sound, SOUND PLAY
INV_EMP--;
DISPLAY_ITEM();
for (int X = 1; X != 28; X++) { // start with unit#1 (skip player)
if (UNIT_TYPE[X] != 0 && // CHECK THAT UNIT EXISTS
UNIT_LOC_X[X] >= MAP_WINDOW_X && // CHECK HORIZONTAL POSITION
UNIT_LOC_X[X] <= (MAP_WINDOW_X + PLATFORM_MAP_WINDOW_TILES_WIDTH - 1) && // NOW CHECK VERTICAL
UNIT_LOC_Y[X] >= MAP_WINDOW_Y &&
UNIT_LOC_Y[X] <= (MAP_WINDOW_Y + PLATFORM_MAP_WINDOW_TILES_HEIGHT - 1)) {
UNIT_TIMER_A[X] = 255;
// test to see if unit is above water
MAP_X = UNIT_LOC_X[X];
MAP_Y = UNIT_LOC_Y[X];
GET_TILE_FROM_MAP();
if (TILE == 204) { // WATER
UNIT_TYPE[X] = 5;
UNIT_TIMER_A[X] = 5;
UNIT_TIMER_B[X] = 3;
UNIT_A[X] = 60; // how long to show sparks.
UNIT_TILE[X] = 140; // Electrocuting tile
}
}
}
PRINT_INFO(MSG_EMPUSED);
SELECT_TIMEOUT = 3; // 3 cycles before next item can be used
}
void USE_MEDKIT()
{
if (UNIT_HEALTH[0] == 12) { // Do we even need the medkit?
return;
}
// Now figure out how many HP we need to be healthy.
TEMP_A = 12 - UNIT_HEALTH[0]; // how many we need.
if (INV_MEDKIT >= TEMP_A) {
// we had more than we need, so go to full health.
UNIT_HEALTH[0] = 12;
INV_MEDKIT -= TEMP_A;
} else {
// we had less than we need, so we'll use what is available.
UNIT_HEALTH[0] += INV_MEDKIT;
INV_MEDKIT = 0;
}
DISPLAY_PLAYER_HEALTH();
DISPLAY_ITEM();
PLAY_SOUND(2); // MEDKIT SOUND, SOUND PLAY
PRINT_INFO(MSG_MUCHBET);
}
void FIRE_UP()
{