-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_loop.h
1626 lines (1234 loc) · 31.3 KB
/
game_loop.h
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.
*/
//divide player horizontal speed by skipping a frame every n frames
unsigned char player_horz_div(unsigned char n)
{
++player_speed_div;
if(player_speed_div>=n) player_speed_div=0;
return player_speed_div;
}
//divide player vertical speed
unsigned char player_ladder_div(void)
{
++player_speed_div;
if(player_speed_div>=3) player_speed_div=0;
return !player_speed_div?1:0;
}
//add an item into the item list
void game_item_add(unsigned char x,unsigned char y,unsigned char type)
{
if(items_all>=ITEMS_MAX) return;
item_type[items_all]=type;
item_x [items_all]=x;
item_y [items_all]=y;
++items_all;
}
//update item sprites
void game_item_update_oam(void)
{
static unsigned char i,j;
static unsigned int spr;
spr=OAM_ITEMS;
for(i=0;i<items_all;++i)
{
j=item_type[i];
if(j!=ITEM_NONE&&j!=ITEM_ELEVATOR)
{
oam_spr1(item_x[i],item_y[i],itemSpriteTable[j],spr);
}
else
{
oam_spr1(0,240,0,spr);
}
spr+=4;
}
}
//update displayed score in the nametable
void game_update_score(void)
{
put_num(&nametable1[POS(1,1)],game_score,5);
put_str(&nametable1[POS(6,1)],"0");
}
//update displayed number of lives in the nametable
void game_update_lives(unsigned char lives)
{
static unsigned char i;
if(!game_flip)
{
for(i=0;i<10;++i)
{
if(i<lives)
{
nametable1[POS(30-i,2)]=TEXT_ATR|2;
nametable1[POS(30-i,3)]=TEXT_ATR|3;
}
else
{
nametable1[POS(30-i,2)]=TEXT_ATR;
nametable1[POS(30-i,3)]=TEXT_ATR;
}
}
}
else
{
for(i=0;i<10;++i)
{
if(i<lives)
{
nametable1[POS(1+i,2)]=TEXT_ATR|2;
nametable1[POS(1+i,3)]=TEXT_ATR|3;
}
else
{
nametable1[POS(1+i,2)]=TEXT_ATR;
nametable1[POS(1+i,3)]=TEXT_ATR;
}
}
}
game_lives_update=TRUE;
}
//add n points to the game score, check for extra live scores
//n is a real value, but the score resolution is 10 points to increase range
void game_add_score(unsigned int n)
{
static unsigned long prev;
prev=game_score;
game_score+=n/10;
game_score_change=TRUE;
if(game_score>99999) game_score=99999;
if((prev< 1000&&game_score>= 1000)||//extra life, scores are divided by ten
(prev< 2500&&game_score>= 2500)||
(prev< 5000&&game_score>= 5000)||
(prev<10000&&game_score>=10000))
{
++game_lives;
game_update_lives(game_lives);
sfx_play(SFX_CHN+3,SFX_EXTRA_LIFE,128);
}
}
//update displayed bonus counter in the nametable
void game_update_bonus(void)
{
static unsigned char i,x;
x=!game_flip?22:14;
if(game_bonus!=0xffff||game_frame_cnt&32)
{
put_num(&nametable1[POS(x,1)],game_bonus<0xffff?game_bonus:0,4);
}
else
{
for(i=0;i<4;++i) nametable1[POS(x+i,1)]=0x140;
}
}
//update all stats at once, including level and labels
void game_update_stats(void)
{
put_str(&nametable1[POS(!game_flip?16:8,1)],"BONUS:");
put_str(&nametable1[POS(27,1)],"L=");
put_num(&nametable1[POS(29,1)],game_loops+1,2);
game_update_score();
game_update_lives(game_lives);
game_update_bonus();
}
//display kong meta sprite
//off is offset in the OAM, x is never goes off the screen,
//y can go behind the screen in both directions,
//animation frame is set in a global variable
void game_show_kong(unsigned int off,unsigned char x,int y)
{
static int ky;
static unsigned char kx,i,pp;
pp=0;
for(i=0;i<5;++i)
{
kx=kong_frame[pp];
if(kx!=128)
{
ky=y+kong_frame[pp+1];
if(ky>=0)
{
if(ky<240)
{
oam_spr1(x+kx,ky,kong_frame[pp+2],off);
}
else
{
oam_spr1(0,240,0,off);
}
}
else
{
oam_spr(x+kx,ky,kong_frame[pp+2],off);
}
pp+=3;
}
else
{
oam_spr1(0,240,0,off);
++pp;
}
off+=4;
}
}
//update nametable when the burning barrel starts to burn,
void barrel_show_fire(unsigned char show)
{
if(game_level<2)
{
nametable1[barrel_fire_off+0]=show?(0x18c|BG_PAL(2)|BG_PRI):0x140;
nametable1[barrel_fire_off+1]=show?(0x18d|BG_PAL(2)|BG_PRI):0x140;
}
}
//kong animation when he raises hands by one, left-right
void kong_stand_animation_level1(void)
{
kong_frame=kongAnimationLeftRight[kong_frame_cnt];
if(!(game_frame_cnt&3))
{
++kong_frame_cnt;
if(kong_frame_cnt==6)
{
sfx_play(SFX_CHN+1,SFX_KONG_LEFT,kong_x+16);
}
if(kong_frame_cnt==12)
{
sfx_play(SFX_CHN+1,SFX_KONG_RIGHT,kong_x+16);
kong_frame_cnt=0;
}
}
}
//kong animation for levels 2-4 with a specific beat pattern
void kong_stand_animation_level2(void)
{
unsigned char frame;
kong_frame=kongAnimationBoth[kong_frame_cnt];
frame=game_frame_cnt&255;
if(!frame||frame==35||frame==70||frame==90) kong_frame_cnt=0;
if(!(game_frame_cnt&3))
{
++kong_frame_cnt;
if(kong_frame_cnt==4) sfx_play(SFX_CHN+1,SFX_KONG_LEFT,kong_x+16);
if(kong_frame_cnt>5) kong_frame_cnt=5;
}
}
//update princess meta sprite
//global variables are used, the sprite can go behind the bottom edge of the screen
void game_show_princess(unsigned char frame)
{
static unsigned char i;
static unsigned int flip;
flip=!game_flip?0:SPR_HFLIP;
if(princess_y<224)
{
i=frame<<1;
if(princess_y>=0)
{
oam_spr1(princess_x,princess_y ,princessAnimation[i+0]|flip,OAM_PRINCESS+0);
oam_spr1(princess_x,princess_y+16,princessAnimation[i+1]|flip,OAM_PRINCESS+4);
}
else
{
oam_spr(princess_x,princess_y ,princessAnimation[i+0]|flip,OAM_PRINCESS+0);
oam_spr(princess_x,princess_y+16,princessAnimation[i+1]|flip,OAM_PRINCESS+4);
}
}
}
//process the items list
unsigned char process_items(unsigned char clear,unsigned char elevator)
{
static unsigned char i,anim;
static unsigned int score,particle;
anim=FALSE;
for(i=game_frame_cnt&1;i<items_all;i+=2)//process half of the list per frame
{
switch(item_type[i])
{
case ITEM_ELEVATOR://check if player touches an elevator gear
{
if(elevator)
{
if(item_y[i]+8 >player_y)
if(item_y[i] <player_y+16)
if(item_x[i]+16>player_x)
if(item_x[i] <player_x+16)
{
clear=LEVEL_LOSE_WINCH;
}
}
}
break;
case ITEM_HAMMER://check if player touches a hammer
{
if(item_y[i]+8>player_y+2)
if(item_y[i] <player_y+14)
if(item_x[i]+8>player_x)
if(item_x[i] <player_x+16)
{
sfx_play(SFX_CHN+3,SFX_ITEM,player_x+8);
item_type[i]=ITEM_NONE;
anim=TRUE;
player_hammer_time=10*60;//the hammer lasts 10 seconds
player_hammer_phase=0;
player_hammer_cnt=0;
music_play(MUS_HAMMER);
}
}
break;
case ITEM_UMBRELLA://other items give score
case ITEM_BAG:
case ITEM_HEART:
{
if(item_y[i]+8>=player_y+4)
if(item_y[i] <=player_y+12)
if(item_x[i]+8>=player_x+4)
if(item_x[i] <=player_x+12)
{
sfx_play(SFX_CHN+3,SFX_ITEM,player_x+8);
switch(game_loops)
{
case 0: score=300; particle=PART_TYPE_300; break;
case 1: score=500; particle=PART_TYPE_500; break;
default: score=800; particle=PART_TYPE_800;
}
game_add_score(score);
particle_add(particle,item_x[i],item_y[i]);
item_type[i]=ITEM_NONE;
anim=TRUE;
}
}
break;
}
}
if(anim) game_item_update_oam();
return clear;
}
//process elevators
//they change the walkmap, no special collision checks are needed
void process_elevators(void)
{
static unsigned char i,elevator,floor1;
static unsigned int off,spr;
//check if the player stands on an elevator
floor1=(TEST_MAP(player_x+8-PLR_BBOX_HWDT,player_y+16)
|TEST_MAP(player_x+8+PLR_BBOX_HWDT,player_y+16))&T_ELEVATOR;
//elevator movement speed is once per four frames
if(!(game_frame_cnt&3))
{
spr=OAM_ELEVATORS;
for(i=0;i<elevators_all;++i)
{
//remove an elevator from the walkmap
if(elevator_y[i]<elevator_bottom-4)
{
off=(elevator_y[i]<<5)+(elevator_x[i]>>3);
walkmap[off+0 ]=0;
walkmap[off+1 ]=0;
walkmap[off+32]=0;
walkmap[off+33]=0;
}
//move elevator
elevator_y[i]+=elevator_dy[i];
if(elevator_y[i]<elevator_top) elevator_y[i]=elevator_bottom;
if(elevator_y[i]>elevator_bottom) elevator_y[i]=elevator_top;
//put an elevator into the walkmap
if(elevator_y[i]<elevator_bottom-4)
{
off=(elevator_y[i]<<5)+(elevator_x[i]>>3);
walkmap[off+0 ]=T_ELEVATOR;
walkmap[off+1 ]=T_ELEVATOR;
walkmap[off+32]=T_ELEVATOR;
walkmap[off+33]=T_ELEVATOR;
}
//update elevator sprite
oam_spr1(elevator_x[i],elevator_y[i]-1,ITEMS_TILE+0x08|SPR_PAL(1)|SPR_PRI(2),spr);
spr+=4;
}
}
//check if the player stands on an elevator again
elevator=(TEST_MAP(player_x+8-PLR_BBOX_HWDT,player_y+16)
|TEST_MAP(player_x+8+PLR_BBOX_HWDT,player_y+16))&T_ELEVATOR;
//if he was on an elevator, but no longer on it after elevators moved,
//move player down to avoid the falling state
if(floor1&&!elevator)
{
++player_y;
elevator=T_ELEVATOR;
}
return elevator;
}
//play two alternating sounds while climbing on a ladder
void game_ladder_sound(void)
{
static unsigned char off;
off=player_step&7;
if(off==0) sfx_play(SFX_CHN,SFX_LADDER1,player_x);
if(off==4) sfx_play(SFX_CHN,SFX_LADDER2,player_x);
}
//wait for next frame, update nametable
//during gameplay, only game stats and rivets on the third level needs to be updated
void game_wait_and_update_nametables()
{
static unsigned char x;
nmi_wait();
copy_to_vram(POS( 0,1),(unsigned char*)&nametable1[POS( 0,1)],32*2);//stats
if(game_lives_update)
{
game_lives_update=FALSE;
x=!game_flip?21:1;
copy_to_vram(POS(x,2),(unsigned char*)&nametable1[POS(x,2)],10*2);//lives
copy_to_vram(POS(x,3),(unsigned char*)&nametable1[POS(x,3)],10*2);
}
if(!game_level)//burning barrel
{
copy_to_vram(POS(barrel_fire_x>>3,barrel_fire_y>>3),(unsigned char*)&nametable1[POS(barrel_fire_x>>3,barrel_fire_y>>3)],2*2);
}
if(game_belts_update)//conveyor belts that change directions during play
{
game_belts_update=FALSE;
copy_to_vram(POS(3, 7),(unsigned char*)&nametable1[POS(3, 7)],26*2);
copy_to_vram(POS(0,13),(unsigned char*)&nametable1[POS(0,13)],32*2);
copy_to_vram(POS(0,22),(unsigned char*)&nametable1[POS(0,22)],32*2);
}
if(game_rivets_update)//rivets
{
game_rivets_update=FALSE;
copy_to_vram(POS(8, 7),(unsigned char*)&nametable1[POS(8, 7)],16*2);
copy_to_vram(POS(8,12),(unsigned char*)&nametable1[POS(8,12)],16*2);
copy_to_vram(POS(8,17),(unsigned char*)&nametable1[POS(8,17)],16*2);
copy_to_vram(POS(8,22),(unsigned char*)&nametable1[POS(8,22)],16*2);
}
}
void game_update_vram_animation(void)
{
copy_to_vram(0x1800,(game_level!=1?tileset2_gfx:tileset2alt_gfx)+game_bg_anim,512);
//background animation counter
if(!(game_frame_cnt&3))
{
game_bg_anim+=512;
if(game_bg_anim>=512*4) game_bg_anim=0;
}
}
unsigned char player_clip_left(void)
{
if(game_level<3&&player_y<=40&&!game_flip) return 104; else return CLIP_LEFT;
}
unsigned char player_clip_right(void)
{
if(game_level<3&&player_y<=40&&game_flip) return 256-104-16; else return CLIP_RIGHT;
}
#include "enemy.h"
#include "game_levels.h"
#include "cutscenes.h"
//gameplay loop
unsigned char game_loop(void)
{
static unsigned int i,j,k,ptr,off,bright,yoff,spr,start_delay;
static unsigned char n,floor1,floor2,clear,anim,pause,elevator,player_fall_sound;
static int x,y,dy;
game_flip=(game_loops/5)&1;//flip every 5 loops
set_bright(0);
setup_hdma_gradient(-1);
oam_clear();
setup_ingame_graphics();
game_update_vram_animation();
clear_nametables();
//unpack level into the map array
switch(game_level)
{
case 0: unrle(map,map1); break;
case 1: unrle(map,map2); break;
case 2: unrle(map,map3); break;
case 3: unrle(map,map4); break;
}
//break some ladders in the first level on later game loops
if(!game_level)
{
if(game_loops>=5 ) map[POS(16,16)]=0x10;
if(game_loops>=10) map[POS(14,20)]=0x10;
if(game_loops>=15) map[POS(11,12)]=0x10;
}
if(game_flip)
{
ptr=0;
for(i=0;i<32;++i)
{
for(j=0;j<16;++j)
{
n=map[ptr+j];
map[ptr+j]=map[ptr+31-j];
map[ptr+31-j]=n;
}
ptr+=32;
}
}
enemy_clear();
particles_clear();
items_all=0;
elevators_all=0;
fireball_spawn_all=0;
//convert map into the walkmap, check object markers and set up objects lists
ptr=0;
y=0;
for(i=0;i<28;++i)
{
x=0;
for(j=0;j<32;++j)
{
n=map[ptr];
//check for object markers
switch(n)
{
case 0x48://elevator dangerous parts
case 0x4a:
if(game_level==2) game_item_add(x-8,y,ITEM_ELEVATOR);
break;
case 0x4c://barrel fire
barrel_fire_x=!game_flip?x:x-8;
barrel_fire_y=y;
barrel_fire_off=!game_flip?ptr:ptr-1;
case 0x4d:
n=0;
break;
case 0xf3://fireball spawn
if(fireball_spawn_all<FIREBALL_SPAWN_MAX)
{
fireball_spawn_x[fireball_spawn_all]=x-4;
fireball_spawn_y[fireball_spawn_all]=y;
++fireball_spawn_all;
}
break;
case 0xf4://fireball
enemy_add(ENEMY_FIREBALL_1,x-4,y,0);
break;
case 0xf6://hammer
game_item_add(x-4,y-4,ITEM_HAMMER);
break;
case 0xf7://umbrella
game_item_add(x-4,y-4,ITEM_UMBRELLA);
break;
case 0xf8://bag
game_item_add(x-4,y-4,ITEM_BAG);
break;
case 0xf9://heart
game_item_add(x-4,y-4,ITEM_HEART);
break;
case 0xfa://elevator top bound
elevator_top=y;
break;
case 0xfb://elevator bottom bound
elevator_bottom=y;
break;
case 0xfc://elevator platform down
case 0xfd://elevator platform up
if(elevators_all<ELEVATORS_MAX)
{
elevator_x [elevators_all]=!game_flip?x+8:x-16;
elevator_y [elevators_all]=y;
elevator_dy[elevators_all]=(n==0xfc?1:-1);
++elevators_all;
}
break;
case 0xfe://kong
kong_x=!game_flip?x:x-24;
kong_y=y-1;
break;
case 0xff://player start position
player_x=x-4;
player_y=y;
break;
}
if(n>=128) n=0;
k=n+0x0140|(n<0x40?BG_PAL(1):BG_PAL(2));
k|=(n<0x40||n>=(game_level==1?0x44:0x4e)?0:BG_PRI);
if(n>=0x4e&&j<8) k|=BG_VFLIP;
if(game_level==1)
{
if(n>=0x11&&n<0x17) k|=BG_PRI;
}
if(game_flip) k|=BG_HFLIP;
nametable1[ptr]=k;
if(game_level==1)
{
switch(n)
{
case 0x40://barrel top
case 0x41:
case 0x44://conveyor belts
case 0x45:
case 0x47:
case 0x48:
case 0x49:
case 0x4b: n=0x08; break;
case 0x46://conveyor ladders
case 0x4a: n=0x20; break;
}
}
off=(i<<8)+j;
for(k=0;k<8;++k)
{
walkmap[off]=tileAttribute[n][k];
off+=32;
}
if(n==0x30)//ladder
{
if(game_level==1)//remove moving parts of the ladders from nametable
{
if(i==8) nametable1[ptr]=0x157|BG_PAL(1);
if(i==9) nametable1[ptr]=0x140;
}
}
++ptr;
x+=8;
}
y+=8;
}
switch(game_loops)
{
case 0: game_bonus=5000; break;
case 1: game_bonus=6000; break;
case 2: game_bonus=7000; break;
default: game_bonus=8000;
}
game_frame_cnt=-1;//to make it zero on the first iteration
game_bg_anim=0;
game_rivets=0;
game_object_jump=0;
game_level_difficulty=game_loops+1;
game_level_difficulty_count=0;
game_fireballs=0;
game_update_palette=FALSE;
game_score_change=FALSE;
game_bonus_change=FALSE;
game_bonus_cnt=0;
game_bounce_delay=0;
game_bounce_speed=game_loops;
game_lives_update=FALSE;
game_belts_update=FALSE;
game_rivets_update=FALSE;
if(game_bounce_speed>4) game_bounce_speed=4;
player_anim=!game_flip?playerWalkAnimRight[0]:playerWalkAnimLeft[0];
player_step=0;
player_fall=FALSE;
player_ladder=FALSE;
player_jump=JUMP_NONE;
player_dir=DIR_NONE;
player_dir_prev=!game_flip?DIR_RIGHT:DIR_LEFT;
player_speed_div=0;
player_hammer_time=0;
player_fall_sound=255;
player_rivet_delay=0;
bright=0;
clear=0;
pause=FALSE;
splat_cnt=255;
switch(game_level)
{
case 0:
case 1:
case 2:
game_fireballs_max=2+game_loops/2;
if(game_fireballs_max>4) game_fireballs_max=4;
break;
case 3:
game_fireballs_max=4+game_loops;
if(game_fireballs_max>8) game_fireballs_max=8;
break;
}
if(game_level_difficulty>5) game_level_difficulty=5;
start_delay=50;
kong_frame_cnt=0;
kong_state=KONG_STATE_STAND;
kong_delay=20;
kong_throw_wild_barrel=TRUE;
kong_frame=kongAnimationLeftRight[0];
kong_start=TRUE;
kong_wild_barrel_type=game_loops%3;
princess_x=!game_flip?80:256-80-16;
princess_y=12;
barrel_fire=FALSE;
if(game_level==1)
{
barrel_show_fire(TRUE);
conveyor_cnt_middle=10*60;
for(i=0;i<3;++i)
{
conveyor_cnt[i]=0;
conveyor_items[i]=0;
}
conveyor_dir[0]=1^game_flip;
conveyor_dir[1]=0;
conveyor_dir[2]=game_flip;
ladders_x[0]=32;
ladders_x[1]=216;
for(i=0;i<2;++i)
{
ladders_y [i]=64;
ladders_dir[i]=0;
ladders_cnt[i]=0;
}
}
set_background(game_level+1);
game_update_stats();
update_nametables();
setup_palettes();
update_palette();
for(i=0;i<512;i+=4) oam_size(i,1);//all sprites are 16x16
if(!game_level)//barrels pile for the first level
{
x=!game_flip?0:208;
oam_spr1(x+12,23,BARREL_TILE+0x0c|BARREL_ATR,OAM_BARRELS+(0<<2));
oam_spr1(x+22,23,BARREL_TILE+0x0c|BARREL_ATR,OAM_BARRELS+(1<<2));
oam_spr1(x+10,39,BARREL_TILE+0x0c|BARREL_ATR,OAM_BARRELS+(2<<2));
oam_spr1(x+24,39,BARREL_TILE+0x0c|BARREL_ATR,OAM_BARRELS+(3<<2));
}
game_show_kong(OAM_KONG,kong_x,kong_y);
game_show_princess(0);
game_show_ladders();
setup_hdma_gradient(game_level+1);
music_play(MUS_LEVEL1);
while(1)
{
game_wait_and_update_nametables();
if(!pause) game_update_vram_animation();
if(game_update_palette)
{
game_update_palette=FALSE;
update_palette();
}
if(!pause)
{
if(bright<15)
{
++bright;
set_bright(bright);
}
}
else
{
if(bright>8)
{
--bright;
set_bright(bright);
}
}
pad_read_ports();
i=pad_poll_trigger(0);
if(!start_delay&&i&PAD_START)
{
pause^=TRUE;
sfx_play(SFX_CHN,SFX_PAUSE,128);
}
if(start_delay)
{
--start_delay;
if(!start_delay) game_item_update_oam();
continue;
}
if(pause) continue;
++game_frame_cnt;
//process splat
if(splat_cnt<((sizeof(splatAnimation)/sizeof(unsigned int))<<1))
{
oam_spr1(splat_x,splat_y,splatAnimation[splat_cnt>>1],OAM_SPLAT);
++splat_cnt;
continue;//splat animation pauses the gameplay
}