-
Notifications
You must be signed in to change notification settings - Fork 6
/
game.c
1545 lines (1218 loc) · 38.3 KB
/
game.c
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
/*
Copyright 2012 Bubble Zap Games
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
//#define SOUND_DISABLE //sound loading is rather slow, it could be disabled to make tests faster
const char versionStr[]="V2.01";
#include "sneslib.h"
#define FP 4
#define POS(x,y) (((y)<<5)+(x))
#include "data.h"
static unsigned int global_stereo;
static unsigned int global_volume;
static unsigned int game_frame_cnt;
static unsigned int game_bg_anim;
static unsigned char game_level;
static unsigned char game_lives;
static unsigned char game_rivets;
static unsigned long game_score;
static unsigned long game_best_score;
static unsigned char game_loops;
static unsigned int game_bonus;
static unsigned char game_score_change;
static unsigned char game_bonus_change;
static unsigned char game_bonus_cnt;
static unsigned char game_level_difficulty;
static unsigned int game_level_difficulty_count;
static unsigned char game_object_jump;
static unsigned char game_bounce_delay;
static unsigned char game_bounce_speed;
static unsigned char game_fireballs;
static unsigned char game_fireballs_max;
static unsigned char game_test_mode;
static unsigned char game_hard_mode;
static unsigned char game_update_palette;
static unsigned char game_flip;
static unsigned char game_lives_update;
static unsigned char game_belts_update;
static unsigned char game_rivets_update;
static unsigned char barrel_fire;
static unsigned char barrel_fire_x;
static unsigned char barrel_fire_y;
static unsigned int barrel_fire_off;
static unsigned char conveyor_dir[3];
static unsigned char conveyor_cnt[3];
static unsigned char conveyor_items[3];
static unsigned int conveyor_cnt_middle;
static unsigned int nametable1[32*32];
static unsigned int nametable2[32*32];
static unsigned int nametable3[32*32];//offset data
static unsigned char map[32*32];
static unsigned char walkmap[32*224];
static unsigned int back_buffer[24576/2];
static unsigned int back_graphics[384*8];
static unsigned int snes_palette_to[256];
#define LEVEL_CLEAR 1
#define LEVEL_LOSE 2
#define LEVEL_LOSE_WINCH 3
#define LEVEL_LOSE_TIME_OUT 4
#define T_FLOOR 1
#define T_LADDER 2
#define T_LADDER_BROKEN 4
#define T_RIVET 8
#define T_ELEVATOR 16
#define T_LDRTOP (T_LADDER|T_FLOOR)
#define T_SOLID (T_FLOOR|T_RIVET|T_ELEVATOR)
const unsigned char tileAttribute[128][8]={
{ 0,0,0,0,0,0,0,0 },//empty
{ T_FLOOR,0,0,0,0,0,0,0 },//other kind of floor
{ T_RIVET,0,0,0,0,0,0,0 },//tile rivet
{ T_LDRTOP,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER },
{ 0,0,0,0,0,0,0,0 },//empty
{ 0,0,0,0,0,0,0,0 },//empty
{ T_FLOOR,0,0,0,0,0,0,0 },//floor
{ T_FLOOR,0,0,0,0,0,0,0 },//floor
{ T_FLOOR,0 ,0 ,0 ,0 ,0 ,0 ,0 },
{ 0 ,T_FLOOR,0 ,0 ,0 ,0 ,0 ,0 },
{ 0 ,0 ,T_FLOOR,0 ,0 ,0 ,0 ,0 },
{ 0 ,0 ,0 ,T_FLOOR,0 ,0 ,0 ,0 },
{ 0 ,0 ,0 ,0 ,T_FLOOR,0 ,0 ,0 },
{ 0 ,0 ,0 ,0 ,0 ,T_FLOOR,0 ,0 },
{ 0 ,0 ,0 ,0 ,0 ,0 ,T_FLOOR,0 },
{ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,T_FLOOR },
{ T_LADDER_BROKEN,T_LADDER_BROKEN,T_LADDER_BROKEN,T_LADDER_BROKEN,
T_LADDER_BROKEN,T_LADDER_BROKEN,T_LADDER_BROKEN,T_LADDER_BROKEN },
{ 0,0,0,0,0,0,0,0 },//empty
{ 0,0,0,0,0,0,0,0 },//empty
{ 0,0,0,0,0,0,0,0 },//empty
{ 0,0,0,0,0,0,0,0 },//empty
{ 0,0,0,0,0,0,0,0 },//empty
{ 0,0,0,0,0,0,0,0 },//empty
{ 0,0,0,0,0,0,0,0 },//empty
{ 0,0,0,0,0,0,0,0 },//floor bottom
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ T_LDRTOP,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER },
{ 0 ,T_LDRTOP,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER },
{ 0 ,0 ,T_LDRTOP,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER },
{ 0 ,0 ,0 ,T_LDRTOP,T_LADDER,T_LADDER,T_LADDER,T_LADDER },
{ 0 ,0 ,0 ,0 ,T_LDRTOP,T_LADDER,T_LADDER,T_LADDER },
{ 0 ,0 ,0 ,0 ,0 ,T_LDRTOP,T_LADDER,T_LADDER },
{ 0 ,0 ,0 ,0 ,0 ,0 ,T_LDRTOP,T_LADDER },
{ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,T_LDRTOP },
{ T_FLOOR ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
{ T_LADDER,T_FLOOR ,0 ,0 ,0 ,0 ,0 ,0 },
{ T_LADDER,T_LADDER,T_FLOOR ,0 ,0 ,0 ,0 ,0 },
{ T_LADDER,T_LADDER,T_LADDER,T_FLOOR ,0 ,0 ,0 ,0 },
{ T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_FLOOR ,0 ,0 ,0 },
{ T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_FLOOR ,0 ,0 },
{ T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_FLOOR ,0 },
{ T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_FLOOR },
{ T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER },
{ T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER },
{ T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER },
{ T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER },
{ T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER },
{ T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER },
{ T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER },
{ T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER,T_LADDER },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },//barrel
{ 0,0,0,0,0,0,0,0 },//barrel
{ 0,0,0,0,0,0,0,0 },//barrel
{ 0,0,0,0,0,0,0,0 },//barrel
{ T_FLOOR,0,0,0,0,0,0,0 },//elevator thing
{ T_FLOOR,0,0,0,0,0,0,0 },//elevator thing
{ T_FLOOR,0,0,0,0,0,0,0 },//elevator thing
{ T_FLOOR,0,0,0,0,0,0,0 },//elevator thing
{ 0,0,0,0,0,0,0,0 },//dangerous elevator thing
{ 0,0,0,0,0,0,0,0 },//dangerous elevator thing
{ 0,0,0,0,0,0,0,0 },//dangerous elevator thing
{ 0,0,0,0,0,0,0,0 },//dangerous elevator thing
{ 0,0,0,0,0,0,0,0 },//fire
{ 0,0,0,0,0,0,0,0 },//fire
{ 0,0,0,0,0,0,0,0 },//elevator rope
{ 0,0,0,0,0,0,0,0 },//elevator rope
{ 0,0,0,0,0,0,0,0 },//empty
{ 0,0,0,0,0,0,0,0 },//empty
{ 0,0,0,0,0,0,0,0 },//empty
{ 0,0,0,0,0,0,0,0 },//empty
{ 0,0,0,0,0,0,0,0 },//empty
{ 0,0,0,0,0,0,0,0 },//empty
};
//palette and prioirty for sprites
#define PLAYER_ATR (SPR_PAL(0)|SPR_PRI(2))
#define ITEM_ATR (SPR_PAL(1)|SPR_PRI(2))
#define KONG_ATR (SPR_PAL(2)|SPR_PRI(2))
#define PRINCESS_ATR (SPR_PAL(5)|SPR_PRI(2))
#define BARREL_ATR (SPR_PAL(3)|SPR_PRI(2))
#define ENEMY_ATR (SPR_PAL(4)|SPR_PRI(2))
#define GAMEOVER_ATR (SPR_PAL(7)|SPR_PRI(3))
#define TEXT_ATR (0x0100|BG_PAL(0)|BG_PRI)
//OAM offsets for objects
#define OAM_GAMEOVER (0<<2) //8 sprites
#define OAM_SPLAT (8<<2) //1 sprite
#define OAM_HAMMER (9<<2) //2 sprites
#define OAM_PLAYER (11<<2) //1 sprite
#define OAM_ENEMY (12<<2) //ENEMY_MAX sprites
#define OAM_PARTICLES (OAM_ENEMY+(ENEMY_MAX<<2)) //PARTICLES_MAX sprites
#define OAM_ITEMS (OAM_PARTICLES+(PARTICLES_MAX<<2)) //ITEMS_MAX sprites
#define OAM_ELEVATORS (OAM_ITEMS+(ITEMS_MAX<<2)) //ELEVATORS_MAX sprites
#define OAM_BARRELS (OAM_ELEVATORS+(ELEVATORS_MAX<<2)) //5 sprites
#define OAM_KONG (OAM_BARRELS+(5<<2)) //5 sprites
#define OAM_PRINCESS (OAM_KONG+(5<<2)) //3 sprites
#define OAM_LADDERS (OAM_PRINCESS+(3<<2)) //2 sprites
#define NAM_OFF(x,y) ((((y)>>3)<<5)+((x)>>3))
#define WMAP_OFF(x,y) (((y)<<5)+((x)>>3))
#define TEST_MAP(x,y) (walkmap[WMAP_OFF(x,y)])
//VRAM offsets for sprite graphics
#define PLAYER_TILE 0
#define ITEMS_TILE (PLAYER_TILE+(3072>>5))
#define KONG_TILE (ITEMS_TILE +(2048>>5))
#define BARREL_TILE (KONG_TILE +(5120>>5))
#define ENEMY_TILE (BARREL_TILE+(1024>>5))
#define PRINCESS_TILE (ENEMY_TILE +(4096>>5))
//player variables
#define MAX_FALL_HEIGHT 15 //in pixels from initial height
#define PLR_BBOX_HWDT (4/2)
static int player_x;
static int player_y;
static unsigned char player_step;
static unsigned char player_ladder;
static unsigned char player_jump;
static unsigned char player_jump_cnt;
static int player_jump_y;
static unsigned int player_anim;
static unsigned char player_dir;
static unsigned char player_dir_prev;
static unsigned char player_fall;
static unsigned char player_speed_div;
static unsigned char player_rivet_delay;
static unsigned int player_hammer_time;
static unsigned char player_hammer_phase;
static unsigned char player_hammer_cnt;
//items variables
#define ITEM_NONE 0
#define ITEM_HAMMER 1
#define ITEM_UMBRELLA 2
#define ITEM_BAG 3
#define ITEM_HEART 4
#define ITEM_ELEVATOR 5
#define ITEMS_MAX 6
static unsigned char items_all;
static unsigned char item_type[ITEMS_MAX];
static unsigned char item_x [ITEMS_MAX];
static unsigned char item_y [ITEMS_MAX];
const unsigned int itemSpriteTable[5]={
0,
ITEMS_TILE+0x00|ITEM_ATR,
ITEMS_TILE+0x02|ITEM_ATR,
ITEMS_TILE+0x04|ITEM_ATR,
ITEMS_TILE+0x06|ITEM_ATR
};
//elevator variables
#define ELEVATORS_MAX 6
static unsigned char elevators_all;
static int elevator_x [ELEVATORS_MAX];
static int elevator_y [ELEVATORS_MAX];
static int elevator_dy[ELEVATORS_MAX];
static unsigned char elevator_top;
static unsigned char elevator_bottom;
//enemy variables
#define ENEMY_MAX 16
#define ENEMY_NONE 0
#define ENEMY_ROLLING_BARREL 1
#define ENEMY_LADDER_BARREL 2
#define ENEMY_WILD_BARREL 3 //to refer to all three kinds
#define ENEMY_WILD_BARREL_DOWN 3
#define ENEMY_WILD_BARREL_CHANGE 4
#define ENEMY_WILD_BARREL_SIDE 5
#define ENEMY_FIREBALL_1_JUMP_IN 6
#define ENEMY_FIREBALL_1_SPAWN 7
#define ENEMY_FIREBALL_1 8
#define ENEMY_FIREBALL_2 9
#define ENEMY_BOUNCE 10
#define ENEMY_CEMENT_PAN 11
#define BOUNCE_FP 7
static unsigned char enemy_free;
static unsigned char enemy_all;
static unsigned char enemy_type [ENEMY_MAX];
static unsigned char enemy_x [ENEMY_MAX];
static unsigned char enemy_y [ENEMY_MAX];
static unsigned char enemy_sy [ENEMY_MAX];
static unsigned char enemy_dx [ENEMY_MAX];
static unsigned char enemy_fall [ENEMY_MAX];
static unsigned char enemy_anim [ENEMY_MAX];
static unsigned char enemy_land [ENEMY_MAX];
static int enemy_ix [ENEMY_MAX];
static int enemy_iy [ENEMY_MAX];
static int enemy_idy [ENEMY_MAX];
static unsigned char enemy_cnt [ENEMY_MAX];
static unsigned char enemy_ladder[ENEMY_MAX];
static unsigned char enemy_spawn[ENEMY_MAX];
static unsigned char enemy_speed[ENEMY_MAX];
const char fireBallJumpInAnimation[]={
0,-1,0,-1,0,-1,0,-1,0,-1,0,-1,0,-1,0,-1,0,-1,0,-1,0,-1,0,-1,0,-1,0,-1,0,-1,0,-1,
1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,
1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1
};
const unsigned int fireBallSpawnAnim[]={
ENEMY_TILE+0x20|ENEMY_ATR,
ENEMY_TILE+0x22|ENEMY_ATR,
ENEMY_TILE+0x24|ENEMY_ATR,
ENEMY_TILE+0x26|ENEMY_ATR,
ENEMY_TILE+0x24|ENEMY_ATR,
ENEMY_TILE+0x22|ENEMY_ATR,
ENEMY_TILE+0x20|ENEMY_ATR,
ENEMY_TILE+0x22|ENEMY_ATR,
ENEMY_TILE+0x24|ENEMY_ATR,
ENEMY_TILE+0x26|ENEMY_ATR,
ENEMY_TILE+0x28|ENEMY_ATR,
ENEMY_TILE+0x26|ENEMY_ATR,
ENEMY_TILE+0x24|ENEMY_ATR,
ENEMY_TILE+0x22|ENEMY_ATR,
ENEMY_TILE+0x20|ENEMY_ATR,
ENEMY_TILE+0x22|ENEMY_ATR,
ENEMY_TILE+0x24|ENEMY_ATR,
ENEMY_TILE+0x26|ENEMY_ATR,
ENEMY_TILE+0x28|ENEMY_ATR,
ENEMY_TILE+0x2a|ENEMY_ATR,
ENEMY_TILE+0x2c|ENEMY_ATR,
ENEMY_TILE+0x2e|ENEMY_ATR
};
#define FIREBALL_SPAWN_MAX 8
static unsigned char fireball_spawn_all;
static unsigned char fireball_spawn_x[FIREBALL_SPAWN_MAX];
static unsigned char fireball_spawn_y[FIREBALL_SPAWN_MAX];
const int bounce_speed[5*2]={
(128+64)*100/100,16*100/100,//1.5 pixels
(128+64)*125/100,16*125/100,
(128+64)*150/100,16*150/100,
(128+64)*175/100,16*175/100,
(128+64)*200/100,16*200/100,
};
//particles
#define PARTICLES_MAX 4
#define PART_TYPE_NONE 0
#define PART_TYPE_100 1
#define PART_TYPE_300 2
#define PART_TYPE_500 3
#define PART_TYPE_800 4
#define PART_TYPE_HELP 5
#define PART_TYPE_SMOKE 6
#define PART_TYPE_SMOKE_UP 7
#define PART_TYPE_HEART 8
static unsigned char particle_free;
static unsigned char particle_type[PARTICLES_MAX];
static unsigned char particle_x [PARTICLES_MAX];
static unsigned char particle_y [PARTICLES_MAX];
static unsigned char particle_cnt1[PARTICLES_MAX];
static unsigned char particle_cnt2[PARTICLES_MAX];
static unsigned int particle_spr [PARTICLES_MAX];
//jump states
#define JUMP_NONE 0
#define JUMP_AIR 1
#define JUMP_LAND 2
#define JUMP_DUMMY 3
//movement directions
#define DIR_NONE 0
#define DIR_LEFT 1
#define DIR_RIGHT 2
#define DIR_UP 3
#define DIR_DOWN 4
//playfield horizontal boundaries
#define CLIP_LEFT 2
#define CLIP_RIGHT 238
//player animation
const unsigned int playerWalkAnimLeft[6]={
PLAYER_TILE+0x00|PLAYER_ATR,
PLAYER_TILE+0x02|PLAYER_ATR,
PLAYER_TILE+0x00|PLAYER_ATR,
PLAYER_TILE+0x04|PLAYER_ATR,
PLAYER_TILE+0x06|PLAYER_ATR,
PLAYER_TILE+0x04|PLAYER_ATR
};
const unsigned int playerWalkAnimRight[6]={
PLAYER_TILE+0x00|PLAYER_ATR|SPR_HFLIP,
PLAYER_TILE+0x02|PLAYER_ATR|SPR_HFLIP,
PLAYER_TILE+0x00|PLAYER_ATR|SPR_HFLIP,
PLAYER_TILE+0x04|PLAYER_ATR|SPR_HFLIP,
PLAYER_TILE+0x06|PLAYER_ATR|SPR_HFLIP,
PLAYER_TILE+0x04|PLAYER_ATR|SPR_HFLIP
};
const unsigned int playerClimbAnim[2*4]={
PLAYER_TILE+0x20|PLAYER_ATR,
PLAYER_TILE+0x20|PLAYER_ATR|SPR_HFLIP,
PLAYER_TILE+0x22|PLAYER_ATR,
PLAYER_TILE+0x22|PLAYER_ATR|SPR_HFLIP,
PLAYER_TILE+0x24|PLAYER_ATR,
PLAYER_TILE+0x24|PLAYER_ATR|SPR_HFLIP,
PLAYER_TILE+0x26|PLAYER_ATR,
PLAYER_TILE+0x26|PLAYER_ATR|SPR_HFLIP
};
const unsigned int playerLoseAnim[4]={
PLAYER_TILE+0x2a|PLAYER_ATR,
PLAYER_TILE+0x2c|PLAYER_ATR,
PLAYER_TILE+0x2a|PLAYER_ATR|SPR_VFLIP,
PLAYER_TILE+0x2c|PLAYER_ATR|SPR_HFLIP
};
const int playerJumpTable[]={
-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,
0,-1,0,-1,0,-1,0,-1,
0,0,0,0,0,0,0,0,
1,0,1,0,1,0,1,0,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,1,1,1//extra
};
const char hammerOffsets[8]={//x and y offsets for moving part of the hammer
-16, 0-1,//hammer at the left
0,-16-1,//hammer at the top
16, 0-1,//hammer at the right
0,-16-1 //hammer at the top
};
const unsigned int hammerSprites[8]={//pair of tile numbers per phase
PLAYER_TILE+0x40|PLAYER_ATR, //hammer at the left
PLAYER_TILE+0x42|PLAYER_ATR,
PLAYER_TILE+0x44|PLAYER_ATR, //hammer at the top
PLAYER_TILE+0x46|PLAYER_ATR,
PLAYER_TILE+0x40|PLAYER_ATR|SPR_HFLIP, //hammer at the right
PLAYER_TILE+0x42|PLAYER_ATR|SPR_HFLIP,
PLAYER_TILE+0x44|PLAYER_ATR|SPR_HFLIP, //hammer at the top
PLAYER_TILE+0x46|PLAYER_ATR|SPR_HFLIP
};
//kong variables
#define KONG_STATE_STAND 0
#define KONG_STATE_TAKE 1
#define KONG_STATE_MIDDLE 2
#define KONG_STATE_DROP 3
#define KONG_STATE_WAIT 4
static unsigned char kong_x;
static int kong_y;
static unsigned char kong_frame_cnt;
static unsigned char kong_state;
static unsigned char kong_delay;
static const unsigned int* kong_frame;
static unsigned char kong_throw_wild_barrel;
static unsigned char kong_wild_barrel_type;
static unsigned char kong_start;
//kong animation
const unsigned int kongLargeSpriteFace1[]={
0, 0,KONG_TILE+0x00|KONG_ATR,
0,16,KONG_TILE+0x20|KONG_ATR,
16, 0,KONG_TILE+0x00|KONG_ATR|SPR_HFLIP,
16,16,KONG_TILE+0x20|KONG_ATR|SPR_HFLIP,
128
};
const unsigned int kongLargeSpriteFace2Both[]={
0 ,0 ,KONG_TILE+0x02|KONG_ATR,
0 ,16,KONG_TILE+0x22|KONG_ATR,
16,0 ,KONG_TILE+0x02|KONG_ATR|SPR_HFLIP,
16,16,KONG_TILE+0x22|KONG_ATR|SPR_HFLIP,
128
};
const unsigned int kongLargeSpriteFace3Both[]={
0, 0,KONG_TILE+0x04|KONG_ATR,
0,16,KONG_TILE+0x24|KONG_ATR,
16, 0,KONG_TILE+0x04|KONG_ATR|SPR_HFLIP,
16,16,KONG_TILE+0x24|KONG_ATR|SPR_HFLIP,
128
};
const unsigned int kongLargeSpriteFace4Both[]={
0, 0,KONG_TILE+0x06|KONG_ATR,
0,16,KONG_TILE+0x26|KONG_ATR,
16, 0,KONG_TILE+0x06|KONG_ATR|SPR_HFLIP,
16,16,KONG_TILE+0x26|KONG_ATR|SPR_HFLIP,
128
};
const unsigned int kongLargeSpriteFace2Left[]={
0, 0,KONG_TILE+0x02|KONG_ATR,
0,16,KONG_TILE+0x22|KONG_ATR,
16, 0,KONG_TILE+0x42|KONG_ATR|SPR_HFLIP,
16,16,KONG_TILE+0x62|KONG_ATR|SPR_HFLIP,
128
};
const unsigned int kongLargeSpriteFace3Left[]={
0, 0,KONG_TILE+0x04|KONG_ATR,
0,16,KONG_TILE+0x24|KONG_ATR,
16, 0,KONG_TILE+0x44|KONG_ATR|SPR_HFLIP,
16,16,KONG_TILE+0x64|KONG_ATR|SPR_HFLIP,
128
};
const unsigned int kongLargeSpriteFace4Left[]={
0, 0,KONG_TILE+0x06|KONG_ATR,
0,16,KONG_TILE+0x26|KONG_ATR,
16, 0,KONG_TILE+0x46|KONG_ATR|SPR_HFLIP,
16,16,KONG_TILE+0x66|KONG_ATR|SPR_HFLIP,
128
};
const unsigned int kongLargeSpriteFace2Right[]={
0, 0,KONG_TILE+0x42|KONG_ATR,
0,16,KONG_TILE+0x62|KONG_ATR,
16, 0,KONG_TILE+0x02|KONG_ATR|SPR_HFLIP,
16,16,KONG_TILE+0x22|KONG_ATR|SPR_HFLIP,
128
};
const unsigned int kongLargeSpriteFace3Right[]={
0, 0,KONG_TILE+0x44|KONG_ATR,
0,16,KONG_TILE+0x64|KONG_ATR,
16, 0,KONG_TILE+0x04|KONG_ATR|SPR_HFLIP,
16,16,KONG_TILE+0x24|KONG_ATR|SPR_HFLIP,
128
};
const unsigned int kongLargeSpriteFace4Right[]={
0, 0,KONG_TILE+0x46|KONG_ATR,
0,16,KONG_TILE+0x66|KONG_ATR,
16, 0,KONG_TILE+0x06|KONG_ATR|SPR_HFLIP,
16,16,KONG_TILE+0x26|KONG_ATR|SPR_HFLIP,
128
};
const unsigned int kongLargeSpriteSideL[]={
0, 0,KONG_TILE+0x08|KONG_ATR,
0,16,KONG_TILE+0x28|KONG_ATR,
16, 0,KONG_TILE+0x0a|KONG_ATR,
16,16,KONG_TILE+0x2a|KONG_ATR,
128
};
const unsigned int kongLargeSpriteSideR[]={
0, 0,KONG_TILE+0x0a|KONG_ATR|SPR_HFLIP,
0,16,KONG_TILE+0x2a|KONG_ATR|SPR_HFLIP,
16, 0,KONG_TILE+0x08|KONG_ATR|SPR_HFLIP,
16,16,KONG_TILE+0x28|KONG_ATR|SPR_HFLIP,
128
};
const unsigned int kongLargeSpriteThrow[]={
0, 0,KONG_TILE+0x0c|KONG_ATR,
0,16,KONG_TILE+0x2c|KONG_ATR,
16, 0,KONG_TILE+0x0c|KONG_ATR|SPR_HFLIP,
16,16,KONG_TILE+0x2c|KONG_ATR|SPR_HFLIP,
128
};
const unsigned int kongLargeSpriteLaugh[]={
0, 0,KONG_TILE+0x0e|KONG_ATR,
0,16,KONG_TILE+0x2e|KONG_ATR,
16, 0,KONG_TILE+0x0e|KONG_ATR|SPR_HFLIP,
16,16,KONG_TILE+0x2e|KONG_ATR|SPR_HFLIP,
128
};
const unsigned int kongLargeSpriteFalling1[]={
-8, 8,KONG_TILE+0x80|KONG_ATR,
8, 8,KONG_TILE+0x82|KONG_ATR,
24, 8,KONG_TILE+0x84|KONG_ATR,
8,24,KONG_TILE+0x8a|KONG_ATR,
128
};
const unsigned int kongLargeSpriteFalling2[]={
-8, 8,KONG_TILE+0x84|KONG_ATR|SPR_HFLIP,
8, 8,KONG_TILE+0x86|KONG_ATR,
24, 8,KONG_TILE+0x80|KONG_ATR|SPR_HFLIP,
8,24,KONG_TILE+0x8e|KONG_ATR,
128
};
const unsigned int kongLargeSpriteFell[]={
-8, 8,KONG_TILE+0x88|KONG_ATR,
8, 8,KONG_TILE+0x8c|KONG_ATR,
24, 8,KONG_TILE+0x88|KONG_ATR|SPR_HFLIP,
128,
128
};
const unsigned int kongLargeSpriteClimb1L[]={
0, 0,KONG_TILE+0x4a|KONG_ATR|SPR_HFLIP,
16, 0,KONG_TILE+0x48|KONG_ATR|SPR_HFLIP,
0,16,KONG_TILE+0x6a|KONG_ATR|SPR_HFLIP,
16,16,KONG_TILE+0x68|KONG_ATR|SPR_HFLIP,
128
};
const unsigned int kongLargeSpriteClimb2L[]={
0, 0,KONG_TILE+0x4e|KONG_ATR|SPR_HFLIP,
16, 0,KONG_TILE+0x4c|KONG_ATR|SPR_HFLIP,
0,16,KONG_TILE+0x6e|KONG_ATR|SPR_HFLIP,
16,16,KONG_TILE+0x6c|KONG_ATR|SPR_HFLIP,
128
};
const unsigned int kongLargeSpriteClimb1R[]={
0, 0,KONG_TILE+0x48|KONG_ATR,
16, 0,KONG_TILE+0x4a|KONG_ATR,
0,16,KONG_TILE+0x68|KONG_ATR,
16,16,KONG_TILE+0x6a|KONG_ATR,
128
};
const unsigned int kongLargeSpriteClimb2R[]={
0, 0,KONG_TILE+0x4c|KONG_ATR,
16, 0,KONG_TILE+0x4e|KONG_ATR,
0,16,KONG_TILE+0x6c|KONG_ATR,
16,16,KONG_TILE+0x6e|KONG_ATR,
128
};
const unsigned int* const kongAnimationLeftRight[]={
kongLargeSpriteFace1,
kongLargeSpriteFace2Left,
kongLargeSpriteFace3Left,
kongLargeSpriteFace4Left,
kongLargeSpriteFace3Left,
kongLargeSpriteFace2Left,
kongLargeSpriteFace1,
kongLargeSpriteFace2Right,
kongLargeSpriteFace3Right,
kongLargeSpriteFace4Right,
kongLargeSpriteFace3Right,
kongLargeSpriteFace2Right,
kongLargeSpriteFace1,
kongLargeSpriteFace1
};
const unsigned int* const kongAnimationBoth[]={
kongLargeSpriteFace1,
kongLargeSpriteFace2Both,
kongLargeSpriteFace3Both,
kongLargeSpriteFace4Both,
kongLargeSpriteFace3Both,
kongLargeSpriteFace1
};
const unsigned int* const kongAnimationStartCutscene[]={
kongLargeSpriteFace4Both,
kongLargeSpriteFace3Both,
kongLargeSpriteFace2Both,
kongLargeSpriteFace1
};
const unsigned int princessAnimation[]={
PRINCESS_TILE+0x00|PRINCESS_ATR,
PRINCESS_TILE+0x02|PRINCESS_ATR,
PRINCESS_TILE+0x00|PRINCESS_ATR,
PRINCESS_TILE+0x0a|PRINCESS_ATR,
PRINCESS_TILE+0x04|PRINCESS_ATR,
PRINCESS_TILE+0x06|PRINCESS_ATR
};
//this animation is used for a barrel that is just landed
//it subtracted from the screen y coordinate to make it appear like jumping
const unsigned char barrelLandingAnimation[]={
1,2,2,3,3,3,3,2,2,1,0,0,0,0,1,2,2,1,0
};
//splat variables
static unsigned char splat_x;
static unsigned char splat_y;
static unsigned char splat_cnt;
const unsigned int splatAnimation[]={
ENEMY_TILE+0x60|ENEMY_ATR,
ENEMY_TILE+0x62|ENEMY_ATR,
ENEMY_TILE+0x64|ENEMY_ATR,
ENEMY_TILE+0x66|ENEMY_ATR,
ENEMY_TILE+0x64|ENEMY_ATR,
ENEMY_TILE+0x62|ENEMY_ATR,
ENEMY_TILE+0x60|ENEMY_ATR,
ENEMY_TILE+0x62|ENEMY_ATR,
ENEMY_TILE+0x64|ENEMY_ATR,
ENEMY_TILE+0x66|ENEMY_ATR,
ENEMY_TILE+0x64|ENEMY_ATR,
ENEMY_TILE+0x62|ENEMY_ATR,
ENEMY_TILE+0x60|ENEMY_ATR,
ENEMY_TILE+0x62|ENEMY_ATR,
ENEMY_TILE+0x64|ENEMY_ATR,
ENEMY_TILE+0x66|ENEMY_ATR,
ENEMY_TILE+0x64|ENEMY_ATR,
ENEMY_TILE+0x62|ENEMY_ATR,
ENEMY_TILE+0x68|ENEMY_ATR,
ENEMY_TILE+0x68|ENEMY_ATR,
ENEMY_TILE+0x6a|ENEMY_ATR,
ENEMY_TILE+0x6a|ENEMY_ATR,
ENEMY_TILE+0x6c|ENEMY_ATR,
ENEMY_TILE+0x6c|ENEMY_ATR,
ENEMY_TILE+0x6e|ENEMY_ATR,
ENEMY_TILE+0x6e|ENEMY_ATR
};
//princess variables
static unsigned char princess_x;
static int princess_y;
//intro cutscene animation and variables
const unsigned int platformAnim[2*8]={
0x0149|BG_PAL(1),0x0159|BG_PAL(1),
0x014a|BG_PAL(1),0x015a|BG_PAL(1),
0x014b|BG_PAL(1),0x015b|BG_PAL(1),
0x014c|BG_PAL(1),0x015c|BG_PAL(1),
0x014d|BG_PAL(1),0x015d|BG_PAL(1),
0x014e|BG_PAL(1),0x015e|BG_PAL(1),
0x014f|BG_PAL(1),0x015f|BG_PAL(1),
0x0148|BG_PAL(1),0x0158|BG_PAL(1)
};
static unsigned char platformAnimCnt[6*32];
//ladders variables
#define LADDERS_MAX 22
static unsigned char ladders_x [LADDERS_MAX];
static unsigned char ladders_y [LADDERS_MAX];
static unsigned char ladders_dir [LADDERS_MAX];
static unsigned char ladders_cnt [LADDERS_MAX];
static unsigned char ladders_delay[LADDERS_MAX];
//sound variables
#define SFX_CHN 4
#define SFX_BARREL1 0
#define SFX_BARREL2 1
#define SFX_BARREL3 2
#define SFX_BARREL4 3
#define SFX_HERO_JUMP 4
#define SFX_ITEM 5
#define SFX_PAUSE 6
#define SFX_JUMP_OVER 7
#define SFX_FIRE_SPAWN 8
#define SFX_RAFT_FALL 9
#define SFX_KONG_LEFT 10
#define SFX_KONG_RIGHT 11
#define SFX_RIVET 12
#define SFX_BOUNCE_FALL 13
#define SFX_BOUNCE_JUMP 14
#define SFX_KONG_FALLS 15
#define SFX_KONG_LANDS 16
#define SFX_LOVE 17
#define SFX_BRIDGE 18
#define SFX_DESTROY 19
#define SFX_START 20
#define SFX_LADDER1 21
#define SFX_LADDER2 22
#define SFX_BARREL_ROLL 23
#define SFX_HERO_FALL 24
#define SFX_HERO_LANDS 25
#define SFX_HERO_HIT 26
#define SFX_KONG_LAUGH 27
#define SFX_CRACK 28
#define SFX_SWITCH 29
#define SFX_BURN 30
#define SFX_EXTRA_LIFE 31
#define SFX_HEART 32
#define SOUNDS_ALL 33
#define MUS_TITLE 0
#define MUS_GAME_START 1
#define MUS_STAGE_START 2
#define MUS_LOSE 3
#define MUS_STAGE_CLEAR 4
#define MUS_HAMMER 5
#define MUS_LEVEL1 6
#define MUS_TIME_OUT 7
#define MUS_VICTORY 8
#define MUSIC_ALL 9
const unsigned char* const musicListPtr[MUSIC_ALL]={
music_title_data,
music_game_start_data,
music_stage_start_data,
music_lose_data,
music_stage_clear_data,
music_hammer_data,
music_level1_data,
music_time_out_data,
music_victory_data
};
const unsigned int* const musicListSize[MUSIC_ALL]={
music_title_size,
music_game_start_size,
music_stage_start_size,
music_lose_size,
music_stage_clear_size,
music_hammer_size,
music_level1_size,
music_time_out_size,
music_victory_size
};
//empty hdma list, used when the background gradient is disabled
const unsigned char hdmaTableNull[]={ 0 };
//pointers to the hdma lists
const unsigned char* const hdmaTables[8][3]={
{ hdmaTableNull,hdmaTableNull,hdmaTableNull },//no gradient
{ hdmaGradient0List0,hdmaGradient0List1,hdmaGradient0List2 },//level 1
{ hdmaGradient5List0,hdmaGradient5List1,hdmaGradient5List2 },//level 2
{ hdmaGradient2List0,hdmaGradient2List1,hdmaGradient2List2 },//level 3
{ hdmaGradient1List0,hdmaGradient1List1,hdmaGradient1List2 },//level 4
{ hdmaGradient3List0,hdmaGradient3List1,hdmaGradient3List2 },//title
{ hdmaGradient4List0,hdmaGradient4List1,hdmaGradient4List2 },//sound test, levels clear
{ hdmaGradient6List0,hdmaGradient6List1,hdmaGradient6List2 },//how high can you get
};
const unsigned char flipTable[256]={
0x00,0x80,0x40,0xc0,0x20,0xa0,0x60,0xe0,0x10,0x90,0x50,0xd0,0x30,0xb0,0x70,0xf0,
0x08,0x88,0x48,0xc8,0x28,0xa8,0x68,0xe8,0x18,0x98,0x58,0xd8,0x38,0xb8,0x78,0xf8,
0x04,0x84,0x44,0xc4,0x24,0xa4,0x64,0xe4,0x14,0x94,0x54,0xd4,0x34,0xb4,0x74,0xf4,
0x0c,0x8c,0x4c,0xcc,0x2c,0xac,0x6c,0xec,0x1c,0x9c,0x5c,0xdc,0x3c,0xbc,0x7c,0xfc,
0x02,0x82,0x42,0xc2,0x22,0xa2,0x62,0xe2,0x12,0x92,0x52,0xd2,0x32,0xb2,0x72,0xf2,
0x0a,0x8a,0x4a,0xca,0x2a,0xaa,0x6a,0xea,0x1a,0x9a,0x5a,0xda,0x3a,0xba,0x7a,0xfa,
0x06,0x86,0x46,0xc6,0x26,0xa6,0x66,0xe6,0x16,0x96,0x56,0xd6,0x36,0xb6,0x76,0xf6,
0x0e,0x8e,0x4e,0xce,0x2e,0xae,0x6e,0xee,0x1e,0x9e,0x5e,0xde,0x3e,0xbe,0x7e,0xfe,
0x01,0x81,0x41,0xc1,0x21,0xa1,0x61,0xe1,0x11,0x91,0x51,0xd1,0x31,0xb1,0x71,0xf1,
0x09,0x89,0x49,0xc9,0x29,0xa9,0x69,0xe9,0x19,0x99,0x59,0xd9,0x39,0xb9,0x79,0xf9,
0x05,0x85,0x45,0xc5,0x25,0xa5,0x65,0xe5,0x15,0x95,0x55,0xd5,0x35,0xb5,0x75,0xf5,
0x0d,0x8d,0x4d,0xcd,0x2d,0xad,0x6d,0xed,0x1d,0x9d,0x5d,0xdd,0x3d,0xbd,0x7d,0xfd,
0x03,0x83,0x43,0xc3,0x23,0xa3,0x63,0xe3,0x13,0x93,0x53,0xd3,0x33,0xb3,0x73,0xf3,
0x0b,0x8b,0x4b,0xcb,0x2b,0xab,0x6b,0xeb,0x1b,0x9b,0x5b,0xdb,0x3b,0xbb,0x7b,0xfb,
0x07,0x87,0x47,0xc7,0x27,0xa7,0x67,0xe7,0x17,0x97,0x57,0xd7,0x37,0xb7,0x77,0xf7,
0x0f,0x8f,0x4f,0xcf,0x2f,0xaf,0x6f,0xef,0x1f,0x9f,0x5f,0xdf,0x3f,0xbf,0x7f,0xff
};
#include "spccmd.h"
void sfx_play(unsigned int chn,unsigned int sfx,int pan)
{
if(pan<0) pan=0;
if(pan>255) pan=255;
spc_sfx_play(chn,sfx,pan);
}
void music_play(unsigned int mus)
{
spc_music_stop();
spc_reload();
spc_load_music(musicListPtr[mus],*musicListSize[mus]);
spc_volume(global_volume);
spc_music_play();
}
void music_stop(void)
{
spc_music_stop();
}
void unrle(unsigned char *dst,const unsigned char *src)
{
static unsigned char i,tag,byte;
tag=*src++;
byte=0;
while(1)
{
i=*src++;
if(i==tag)
{
i=*src++;
if(!i) break;
while(i)
{
*dst++=byte;
--i;
}
}
else
{
byte=i;;
*dst++=byte;
}
}
}
//fade the screen brightness in or out, together with global sound volume if needed
void fade_screen(unsigned char in,unsigned char sound)
{
static unsigned char i;
static char volume;
volume=127;
for(i=1;i<16;++i)
{
nmi_wait();
if(in)
{
set_bright(i);
}
else
{
set_bright(15-i);
if(sound)
{
volume-=8;