-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgorillas.c
1524 lines (1153 loc) · 35 KB
/
gorillas.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
/*
* Gorillas for Uzebox - remake of the popular QBASIC game
* Version 1.1
* Copyright (C) 2011 Hartmut Wendt
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <string.h>
#include <avr/io.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
#include "kernel/uzebox.h"
#include "data/backgroundTiles.pic.inc"
#include "data/fonts.pic.inc"
#include "data/gorillas_sprites4.inc"
#include "data/lutsin.inc"
#include "data/patches.inc"
#include "data/gorillas-tracks.inc"
/* global definitons */
// program modes
#define PM_Intro 0 // program mode intro
#define PM_Enter_Player_Count 1 // program mode: enter the count of players in game menu
#define PM_Enter_Player1_Name 2 // program mode: enter the name of player 1 in game menu
#define PM_Enter_Player2_Name 3 // program mode: enter the name of player 2 in game menu
#define PM_Enter_Point_Count 4 // program mode: enter the count of points in game menu
#define PM_Show_Gorilla_Dance 5 // program mode: shows the gorilla dance
#define PM_Prepare_Game 9 // program mode: prepare play ground and skyline for game
#define PM_Enter_Angle_P1 11 // program mode: enter the throw angle for player 1
#define PM_Enter_Power_P1 12 // program mode: enter the throw power for player 1
#define PM_Enter_Angle_P2 16 // program mode: enter the throw angle for player 2
#define PM_Enter_Power_P2 17 // program mode: enter the throw power for player 2
#define PM_THROW_P1 10 // program mode player 1 banana throw
#define PM_THROW_P2 15 // program mode player 2 banana throw
#define PM_Game_over 20 // program mode for game over screen
#define PM_Crash_Skyscraper_P1 30 // banana of player 1 hits skyscraper
#define PM_Crash_Skyscraper_P2 31 // banana of player 2 hits skyscraper
#define PM_Crash_Gorilla_P1 32 // banana of player 1 hits gorilla
#define PM_Crash_Gorilla_P2 33 // banana of player 2 hits gorilla
// colors
#define red 0
#define cyan 1
#define grey 2
// banana hits
#define hit_nothing 0
#define hit_gorilla 1
#define hit_skyscraper 2
#define wide_throw 3
#define hit_sun 4
// 8-bit, 255 period LFSR (for generating pseudo-random numbers)
#define PRNG_NEXT() (prng = ((u8)((prng>>1) | ((prng^(prng>>2)^(prng>>3)^(prng>>4))<<7))))
#define max_cards 48
#define gravity 10
//#define delta_t 1
#define MAX(x,y) ((x)>(y) ? (x) : (y))
struct EepromBlockStruct ebs;
u8 prng; // Pseudo-random number generator
int PosX=0, PosY=0;
u8 program_mode; // program mode (intro, 1 player mode, 2 player mode, ....
u8 PLAYER; // 0 = Player 1 / 1 = Player 2
u8 ani_count=0; // counter for animation
//u8 Music_on = true;
u8 Ypos_gorilla1;
u8 Ypos_gorilla2;
u8 PlayerCNT = 1; // count of players
char Player1_Name[9]={"PLAYER1 "};
char Player2_Name[9]={"PLAYER2 "};
u8 ThrowAngle;
u8 ThrowPower;
u8 StartYPos;
u8 StartXPos = 0;
u8 ScoreP1;
u8 ScoreP2;
u8 Total_score_points = 3;
u8 StartPlayer = 0;
char Windspeed = 0;
char Windforce;
char CPU_Angle;
char CPU_Speed;
double t = 0;
u8 Ypos_left_skyscraper;
u8 Controller_status2;
u8 autorepeat_cnt;
//int Xold=0;
//long Yold=0;
/*
int V0V;
int V0H;
*/
double InitYVel;
double InitXVel;
/*** function prototypes *****************************************************************/
void init(void);
void set_PM_mode(u8 mode);
void msg_window(u8 x1, u8 y1, u8 x2, u8 y2);
u8 set_def_EEPROM(void);
void load_def_EEPROM(void);
void save_def_EEPROM(void);
void create_new_skyline(void);
void draw_skyscraper(u8 position, u8 floors);
const char * get_skyscraper_map(u8 floor, u8 color);
void animate_banana(u8 xx, int yy);
void calculate_position(double dt);
void animate_star_frame(void);
bool edit_value(u8 *value, u8 min, u8 max, u8 Xpos, u8 Ypos, int *b_mode, int *b_mode_old);
void edit_name(char *value, u8 *entry, int *b_mode, int *b_mode_old);
void PrintName(int x, int y, char *s, bool Bcursor, u8 CurPos);
void animate_2gorillas_dance(void);
void clear_text(void);
u8 GetTile(u8 x, u8 y);
char get_tile_pixel(unsigned char x,unsigned char y,char tile, const char *tileset);
char get_sprite_tile(unsigned char x,unsigned char y);
char checkcollision(int xx, int yy);
void destroy_skyscraper(int xx, int yy);
void show_score(void);
void animate_gorilla_victory(u8 xx, u8 yy);
void draw_wind_arrow(void);
void AI_calculation(void);
void copy_buf(unsigned char *BUFA, unsigned char *BUFB, unsigned char ucANZ);
void init(void)
// init program
{
// init tile table
SetTileTable(BGTiles);
// init font table
SetFontTilesIndex(BGTILES_SIZE);
// init Sprites
SetSpritesTileTable(spriteTiles);
// init music
InitMusicPlayer(patches);
// load into screen
set_PM_mode(PM_Intro);
// init random generator
Controller_status2 = DetectControllers() & 0x0C;
prng = 15;
//Use block 22
ebs.id = 22;
if (!isEepromFormatted())
return;
if (EEPROM_ERROR_BLOCK_NOT_FOUND == EepromReadBlock(22,&ebs))
{
set_def_EEPROM();
}
}
int main(){
int ibuttons=0,ibuttons_old;
u8 b = 0;
// init program
init();
// proceed game
while(1)
{
WaitVsync(3);
// get controller state
ibuttons_old = ibuttons;
ibuttons = ReadJoypad(PLAYER);
switch(program_mode)
{
// proceed intro mode
case PM_Intro:
// proceed game over mode
case PM_Game_over:
animate_star_frame();
if (((BTN_A & ibuttons) && !(ibuttons_old & BTN_A)) ||
((BTN_B & ibuttons) && !(ibuttons_old & BTN_B)) ||
((BTN_START & ibuttons) && !(ibuttons_old & BTN_START)) ||
((BTN_SELECT & ibuttons) && !(ibuttons_old & BTN_SELECT))) {
set_PM_mode(PM_Enter_Player_Count);
}
break;
// proceed input of player count
case PM_Enter_Player_Count:
if (edit_value(&PlayerCNT,1,2,21,6,&ibuttons,&ibuttons_old)) {
// wait for release of button A
while (BTN_A & ReadJoypad(PLAYER)) {
prng++;
WaitVsync(1);
}
prng = MAX(prng,1);
set_PM_mode(PM_Enter_Player1_Name);
}
break;
// proceed input of player 1 name
case PM_Enter_Player1_Name:
edit_name(&Player1_Name[0],&b,&ibuttons,&ibuttons_old);
PrintName(19,9,Player1_Name,true,b);
if ((BTN_A & ibuttons) && !(ibuttons_old & BTN_A)) {
PrintName(19,9,Player1_Name,false,b);
if (PlayerCNT == 2) {
set_PM_mode(PM_Enter_Player2_Name);
} else {
Print(2,12,PSTR("NAME OF PLAYER2:"));
Player2_Name[0] = 'C';
Player2_Name[1] = 'P';
Player2_Name[2] = 'U';
Player2_Name[3] = 0;
PrintName(19,12,Player2_Name,false,0);
set_PM_mode(PM_Enter_Point_Count);
}
}
break;
// proceed input of player 2 name
case PM_Enter_Player2_Name:
edit_name(&Player2_Name[0],&b,&ibuttons,&ibuttons_old);
PrintName(19,12,Player2_Name,true,b);
if ((BTN_A & ibuttons) && !(ibuttons_old & BTN_A)) {
PrintName(19,12,Player2_Name,false,0);
set_PM_mode(PM_Enter_Point_Count);
}
break;
// proceed input total point count
case PM_Enter_Point_Count:
if (edit_value(&Total_score_points,1,9,26,15,&ibuttons,&ibuttons_old)) {
save_def_EEPROM();
set_PM_mode(PM_Show_Gorilla_Dance);
}
break;
// gorilla dance intro
case PM_Show_Gorilla_Dance:
animate_2gorillas_dance();
if (((BTN_A & ibuttons) && !(ibuttons_old & BTN_A)) ||
((BTN_B & ibuttons) && !(ibuttons_old & BTN_B)) ||
((BTN_START & ibuttons) && !(ibuttons_old & BTN_START)) ||
((BTN_SELECT & ibuttons) && !(ibuttons_old & BTN_SELECT))) {
set_PM_mode(PM_Prepare_Game);
}
break;
// proceed input of angle for player 1
case PM_Enter_Angle_P1:
//t = 0;
if (edit_value(&ThrowAngle,0,90,9,2,&ibuttons,&ibuttons_old)) {
set_PM_mode(PM_Enter_Power_P1);
}
break;
// proceed input of power for player 1
case PM_Enter_Power_P1:
if (edit_value(&ThrowPower,1,50,9,3,&ibuttons,&ibuttons_old)) {
set_PM_mode(PM_THROW_P1);
}
break;
// proceed input of angle for player 2
case PM_Enter_Angle_P2:
//t = 0;
if (edit_value(&ThrowAngle,0,90,28,2,&ibuttons,&ibuttons_old)) {
set_PM_mode(PM_Enter_Power_P2);
}
break;
// proceed input of power for player 2
case PM_Enter_Power_P2:
if (edit_value(&ThrowPower,1,50,28,3,&ibuttons,&ibuttons_old)) {
set_PM_mode(PM_THROW_P2);
}
break;
// proceed player 1 throw
case PM_THROW_P1:
// WaitVsync(20);
// calcuate new banana position
calculate_position(t);
t = t + 0.2;
// to wide throw?
if (((PosX + 8) > 240) || (PosX < 0)) {
// hide banana sprite
MapSprite2(1,banana_empty,0);
// change player
set_PM_mode(PM_Enter_Angle_P2);
break;
}
// check collision
if (PosY < 224) {
b = checkcollision(PosX,224 - PosY);
if (b == hit_skyscraper) {
set_PM_mode(PM_Crash_Skyscraper_P1);
break;
} else if (b == hit_gorilla) {
if (PosX > 120) set_PM_mode(PM_Crash_Gorilla_P2);
else set_PM_mode(PM_Crash_Gorilla_P1);
break;
} else if (b == hit_sun) {
// banana hits the sun --> draw surprised sun
DrawMap2(13,0,sun_surprised);
}
}
// draw animated banana
if (PosY < 224) {
SetSpriteVisibility(true);
animate_banana(PosX, 224 - PosY);
} else SetSpriteVisibility(false);
break;
// proceed player 2 throw
case PM_THROW_P2:
// calcuate new banana position
calculate_position(t);
t = t + 0.2;
// to wide throw?
if (((PosX + 8) > 240) || (PosX < 0)) {
AI_calculation();
// hide banana sprite
MapSprite2(1,banana_empty,0);
// change player
set_PM_mode(PM_Enter_Angle_P1);
break;
}
// check collision
if (PosY < 224) {
b = checkcollision(240 - PosX,224 - PosY);
if (b == hit_skyscraper) {
AI_calculation();
set_PM_mode(PM_Crash_Skyscraper_P2);
break;
} else if (b == hit_gorilla) {
if (PosX < 120) set_PM_mode(PM_Crash_Gorilla_P2);
else set_PM_mode(PM_Crash_Gorilla_P1);
break;
} else if (b == hit_sun) {
// banana hits the sun --> draw surprised sun
DrawMap2(13,0,sun_surprised);
}
}
// draw animated banana
if (PosY < 224) {
SetSpriteVisibility(true);
animate_banana(240 - PosX, 224 - PosY);
} else SetSpriteVisibility(false);
break;
break;
case PM_Crash_Gorilla_P1:
case PM_Crash_Gorilla_P2:
animate_banana(PosX, PosY);
break;
// banana of player 1 hits skyscraper
case PM_Crash_Skyscraper_P1:
animate_banana(PosX - 4, 224 - PosY - 4);
break;
// banana of player 2 hits skyscraper
case PM_Crash_Skyscraper_P2:
animate_banana(240 - PosX - 4, 224 - PosY - 4);
break;
}
//ani_count++; // increase counter for animation
}
}
void set_PM_mode(u8 mode) {
// set parameters, tiles, background etc for choosed program mode
double winkel;
switch (mode)
{
case PM_Intro:
// cursor is invisible now
StopSong();
ClearVram();
Print(4,3,PSTR("U Z E G O R I L L A S"));
Print(9,5,PSTR("VERSION 1.0"));
Print(4,8,PSTR("(C) HARTMUT WENDT 2011"));
Print(4,9,PSTR("SOUNDTRACK BY C. KUNZ"));
Print(4,10,PSTR("WWW.HWHARDSOFT.DE.VU"));
Print(4,13,PSTR("YOUR MISSION IS TO HIT"));
Print(4,14,PSTR("YOUR OPPONENT WITH THE"));
Print(4,15,PSTR("EXPLODING BANANA BY"));
Print(4,16,PSTR("VARYING THE ANGLE AND"));
Print(4,17,PSTR("POWER OF YOUR THROW."));
Print(7,20,PSTR("LICENCED UNDER"));
Print(9,21,PSTR("GNU GPL V3"));
Print(8,26,PSTR("PRESS ANY KEY"));
//start sound track
SetMasterVolume(130);
WaitVsync(10);
StartSong(introtheme);
break;
case PM_Enter_Player_Count:
// blank screen - no music
StopSong();
ClearVram();
WaitVsync(2);
// Draw help
Print(1,26,PSTR("CONFIRM INPUT WITH BUTTON A"));
Print(2,6,PSTR("COUNT OF PLAYERS:"));
load_def_EEPROM();
PLAYER=0;
StartPlayer = 0;
break;
case PM_Enter_Player1_Name:
Print(2,9,PSTR("NAME OF PLAYER1:"));
break;
case PM_Enter_Player2_Name:
Print(2,12,PSTR("NAME OF PLAYER2:"));
break;
case PM_Enter_Point_Count:
Print(2,15,PSTR("HOW MANY TOTAL POINTS:"));
ScoreP1 = 0;
ScoreP2 = 0;
break;
case PM_Show_Gorilla_Dance:
// blank screen - no music
ClearVram();
WaitVsync(30);
Print(3,4,PSTR("U Z E G O R I L L A S"));
Print(10,7,PSTR("STARRING:"));
PrintName(4,10,Player1_Name,false,0);
Print(13,10,PSTR("AND"));
PrintName(18,10,Player2_Name,false,0);
Print(8,26,PSTR("PRESS ANY KEY"));
// draw gorillas
DrawMap2(8,15,gorilla_map);
DrawMap2(18,15,gorilla_map);
ani_count = 1;
//start sound track
//SetMasterVolume(130);
StartSong(maintheme);
break;
case PM_Prepare_Game:
// clear screen & stop music
StopSong();
ClearVram();
// generate playground
create_new_skyline();
// calculate Windspeed (values -5...5)
Windspeed = PRNG_NEXT() % 11;
Windspeed -= 5;
Windspeed *= 2;
draw_wind_arrow();
// calculate start values for AI in 1 player mode
CPU_Speed = 20 + (PRNG_NEXT() % 11);
if ((Ypos_left_skyscraper < Ypos_gorilla2) && ((Ypos_gorilla2 - Ypos_left_skyscraper) > 5)) CPU_Angle = 45 + (PRNG_NEXT() % 11);
else CPU_Angle = 30 + (PRNG_NEXT() % 21);
// show actual score
show_score();
if (StartPlayer) {
// Player 2 will start
mode = PM_Enter_Angle_P2;
StartPlayer = 0;
} else {
// Player 1 will start
mode = PM_Enter_Angle_P1;
StartPlayer = 1;
}
case PM_Enter_Angle_P1:
case PM_Enter_Angle_P2:
// draw sun
DrawMap2(13,0,sun_laughing);
// draw gorillas
DrawMap2(3,Ypos_gorilla1,gorilla_map);
DrawMap2(24,Ypos_gorilla2,gorilla_map);
// print player names
PrintName(1,1,Player1_Name,false,0);
PrintName(20,1,Player2_Name,false,0);
if (mode == PM_Enter_Angle_P1) {
Print(1,2,PSTR("ANGLE:"));
PLAYER=0;
} else {
Print(20,2,PSTR("ANGLE:"));
if (Controller_status2 == 0x04) PLAYER=1;
}
// AI??
if ((PlayerCNT == 1) && (mode == PM_Enter_Angle_P2)) {
Print(20,3,PSTR("POWER:"));
PrintByte(28,2,CPU_Angle,false);
WaitVsync(60);
PrintByte(28,3,CPU_Speed,false);
ThrowAngle = CPU_Angle;
ThrowPower = CPU_Speed;
WaitVsync(90);
mode = PM_THROW_P2;
goto AI_THROW;
} else {
// reset Angle
ThrowAngle = 0;
}
break;
case PM_Enter_Power_P1:
Print(1,3,PSTR("POWER:"));
// reset power
ThrowPower = 0;
break;
case PM_Enter_Power_P2:
Print(20,3,PSTR("POWER:"));
// reset power
ThrowPower = 0;
break;
case PM_THROW_P1:
case PM_THROW_P2:
AI_THROW:
// delete text over the skyline
clear_text();
// move arm up
if (mode == PM_THROW_P1) {
DrawMap2(3,Ypos_gorilla1,arm_up_left);
} else {
DrawMap2(26,Ypos_gorilla2,arm_up_right);
}
// calculate Windforce;
if (mode == PM_THROW_P1) Windforce = Windspeed;
else Windforce = Windspeed * (-1);
// calculate start position for throw
t = 0;
if (mode == PM_THROW_P1) {
StartXPos = 24;
StartYPos = 230 - (Ypos_gorilla1 * 8);
} else {
StartXPos = 34;
StartYPos = 230 - (Ypos_gorilla2 * 8);
}
// calculate vector Y
memcpy_P( &winkel, &sincosLUT[ThrowAngle], sizeof( double ) );
InitYVel = winkel * ThrowPower * 0.5;
// calculate vector X
memcpy_P( &winkel, &sincosLUT[90-ThrowAngle], sizeof( double ) );
InitXVel = winkel * ThrowPower * 0.5;
//Sound
TriggerNote(3,1,11,0x7f);
break;
case PM_Crash_Gorilla_P1:
PosX = 24;
PosY = Ypos_gorilla1 * 8;
ani_count = 0;
ScoreP2++;
// Sound
TriggerNote(3,2,11,0x7f);
break;
case PM_Crash_Gorilla_P2:
PosX = 192;
PosY = Ypos_gorilla2 * 8;
ani_count = 0;
ScoreP1++;
// Sound
TriggerNote(3,2,11,0x7f);
break;
case PM_Crash_Skyscraper_P1:
case PM_Crash_Skyscraper_P2:
ani_count = 0;
// Sound
TriggerNote(3,2,11,0x7f);
break;
case PM_Game_over:
ClearVram();
Print(10,9,PSTR("GAME OVER!"));
Print(12,12,PSTR("SCORE:"));
// print scores
PrintByte(20,14,ScoreP1,false);
PrintByte(20,15,ScoreP2,false);
// print player names
PrintName(10,14,Player1_Name,false,0);
PrintName(10,15,Player2_Name,false,0);
Print(8,26,PSTR("PRESS ANY KEY"));
PLAYER=0;
}
program_mode = mode;
}
void create_new_skyline(void) {
// creates a new randomized city skyline
u8 u1,u2;
for(u1 = 0; u1 < 10; u1++) {
// skyscraper
u2 = PRNG_NEXT() % 14;
// Save heigth of 2nd and 9th skyscraper for gorillas
if (u1 == 1) Ypos_gorilla1 = 19 - u2;
else if (u1 == 7) Ypos_left_skyscraper = 19 - u2; // heigth of left skyscraper for AI
else if (u1 == 8) Ypos_gorilla2 = 19 - u2;
draw_skyscraper(u1, u2);
}
}
void draw_skyscraper(u8 position, u8 floors) {
// draw a skyscraper at defined position
u8 u1;
for(u1 = 1; u1 < (floors + 6); u1++) {
DrawMap2(position * 3, 27 - u1, get_skyscraper_map(PRNG_NEXT() % 4, position % 3));
}
}
const char * get_skyscraper_map(u8 floor, u8 color) {
// get a map for a skyscraper
if (color == red) {
switch(floor) {
case 1:
return(house_red2);
break;
case 2:
return(house_red3);
break;
case 3:
return(house_red4);
break;
default:
return(house_red1);
break;
}
} else if (color == cyan) {
switch(floor) {
case 1:
return(house_cyan2);
break;
case 2:
return(house_cyan3);
break;
case 3:
return(house_cyan4);
break;
default:
return(house_cyan1);
break;
}
} else {
switch(floor) {
case 1:
return(house_grey2);
break;
case 2:
return(house_grey3);
break;
case 3:
return(house_grey4);
break;
default:
return(house_grey1);
break;
}
}
}
void calculate_position(double dt) {
// calculate ballistic trajectory
// this is the calculation from the original game:
// x# = StartXPos + (InitXVel# * t#) + (.5 * (Wind / 5) * t# ^ 2)
// y# = StartYPos + ((-1 * (InitYVel# * t#)) + (.5 * gravity# * t# ^ 2)) * (ScrHeight / 350)
// PosX = StartXPos + (0.1 * InitXVel * dt) + (0.05 * (Windspeed / 5) * dt * dt);
PosX = StartXPos + (InitXVel * dt) + (0.1 * (Windforce / 5) * dt * dt);
PosY = StartYPos + ((InitYVel * dt) + ((-0.05 * gravity * dt * dt)));
}
void clear_text(void) {
// clear all text in upper screen
Fill(1,1,9,3,0);
Fill(20,1,9,3,0);
}
u8 GetTile(u8 x, u8 y)
// get background tile from vram
{
return (vram[(y * 30) + x] - RAM_TILES_COUNT);
}
// get the tile from the actual sprite
char get_sprite_tile(unsigned char x,unsigned char y) {
if (x < 8) {
if (y < 8) return(sprites[1].tileIndex);
else return(sprites[3].tileIndex);
} else {
if (y < 8) return(sprites[2].tileIndex);
else return(sprites[4].tileIndex);
}
}
// get pixel value from a tile
char get_tile_pixel(unsigned char x,unsigned char y,char tile, const char *tileset) {
return(pgm_read_byte(&(tileset[(64 * tile) + (8 * y) + x])));
}
// check the collision of the banana with the sun, skyscrapers or other gorilla
char checkcollision(int xx, int yy) {
// returns 0 - no collision
// returns 1 - gorilla
// returns 2 - skyscraper
// returns 4 - hit sun
u8 x,y;
unsigned char pix_sprite, pix_bg, tile_bg;
// check collision
for(y = 0; y < 8; y=y + 1)
for(x = 0; x < 8; x=x + 1)
{
// banana hit the sun
if (((xx + x)>= 104) && ((xx + x)< 136) && ((yy + y) < 32)) return(hit_sun);
// check banana collision
tile_bg = GetTile((xx + x) / 8, (yy + y) / 8);
// enable this output for debugging
// PrintByte(5,24,tile_bg,1);
if (tile_bg)
{
pix_bg = get_tile_pixel((xx + x) % 8,(yy + y) % 8,tile_bg,BGTiles);
pix_sprite = get_tile_pixel(x ,y ,sprites[1].tileIndex,spriteTiles);
/* enable this output for debugging
PrintByte(5,25,pix_bg,1);
PrintByte(5,26,pix_sprite,1);
PrintByte(5,27,sprites[1].tileIndex,1);
*/
// crash?
if ((pix_sprite != 0xFE) && (pix_bg != 0x40)) {
// banana hits gorilla
if ((pix_bg == 0x27) || !(pix_bg)) return(hit_gorilla);
// banana hits skyscraper
return(hit_skyscraper);
}
}
}
return(hit_nothing);
}
// damage a skyscraper after a collision with a banana
void destroy_skyscraper(int xx, int yy) {
//unsigned char tile_bg;
// check left upper edge of banana tile
if (GetTile(xx / 8, yy / 8)) SetTile(xx / 8,yy / 8,0);
// check right upper edge of banana tile
if (GetTile((xx + 8) / 8, yy / 8)) SetTile((xx + 8) / 8,yy / 8,0);
// check left lower edge of banana tile
if (GetTile(xx / 8, (yy + 8) / 8)) SetTile(xx / 8,(yy + 8) / 8,0);
// check right lower edge of banana tile
if (GetTile((xx + 8) / 8, (yy + 8) / 8)) SetTile((xx + 8) / 8,(yy + 8) / 8,0);
}
/**** A N I M A T I O N S ***************************************************************/
void animate_banana(u8 xx, int yy) {
// draw and animate the banana
if ((program_mode == PM_Crash_Skyscraper_P1) || (program_mode == PM_Crash_Skyscraper_P2)) {
// banana explosion after skyscraper hit
switch (ani_count)
{
case 0: // 1st picture for explosion
//TriggerFx(3, 0xff, true);
case 12:
MapSprite2(1,Exp_small_0,0);
break;
case 1: // 2nd picture for explosion
case 11:
MapSprite2(1,Exp_small_1,0);
break;
case 2: // 3rd picture for explosion
destroy_skyscraper(xx + 4,yy + 4);
case 10:
MapSprite2(1,Exp_small_2,0);
break;
case 3: // 4th picture for explosion
case 9:
MapSprite2(1,Exp_small_3,0);
break;
case 4: // 5th picture for explosion
case 8:
MapSprite2(1,Exp_small_4,0);
break;
case 5: // 6th picture for explosion
case 7:
MapSprite2(1,Exp_small_5,0);
break;