-
Notifications
You must be signed in to change notification settings - Fork 0
/
lander.c
1152 lines (948 loc) · 28 KB
/
lander.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
/*
* Uzebox quick and dirty tutorial
* Copyright (C) 2008 Alec Bourque
*
* 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 <avr/io.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
#include <uzebox.h>
#include "data/patches.inc"
#include "data/background.pic.inc"
#include "data/rocketsprites.pic.inc"
#include "data/backgroundTiles.map.inc"
#include "data/rocketman-track.inc"
//Initialize a struct and define the block id
// 3 datasets: 8 byte name; 2 byte highscore
struct EepromBlockStruct ebs;
// function prototypes
void init(void);
void LanderPrintInt(int x,int y, unsigned int val,bool zeropad,u8 digits);
void LanderPrintByte(int x,int y, unsigned char val,bool zeropad);
void LanderPrint(int x, int y, const char *s);
void LanderPrintI(int x, int y, const char *s);
char get_map_tile(unsigned char x,unsigned char y,const char *map);
char get_sprite_tile(unsigned char x,unsigned char y);
char get_tile_pixel(unsigned char x,unsigned char y,char tile, const char *tileset);
void calculate_position(u8 angle, u8 B_engine);
char checkcollision(u8 xx, u8 yy, u8 angle, const char *map);
void animate_rocket(u8 xx, u8 yy, u8 angle, u8 B_engine);
void set_PM_mode(u8 mode);
void msg_window(u8 x1, u8 y1, u8 x2, u8 y2);
void view_bottom_line(u8 level);
int randomize(void);
void ready_steady_go(const char *map);
u8 set_def_highscore(void);
u8 view_highscore_entry(u8 x, u8 y, u8 entry, u8 load_data);
void clear_highsore(u8 entry);
u8 check_highscore(void);
void copy_highsore(u8 entry_from, u8 entry_to);
void edit_highscore_entry(u8 entry, u8 cursor_pos, u8 b_mode);
void show_highscore_char(u8 entry, u8 position, u8 cursor_on);
void fade_out_volume(void);
/* global definitons */
// program modes
#define PM_Intro 0 // program mode intro
#define PM_Level1 1 // program mode level 1
#define PM_Level2 2 // program mode level 2
#define PM_Level3 3 // program mode level 3
#define PM_Level4 4 // program mode level 4
#define PM_Level5 5 // program mode level 5
#define PM_Level6 6 // program mode level 6
#define PM_Level7 7 // program mode level 7
#define PM_Crash 10 // program mode crash
#define PM_HoF_view 20 // program mode view hall of fame
#define PM_HoF_edit 21 // program mode edit hall of fame
// angles
#define angle_0 0 // 0 degree
#define angle_45 1 // 45 degree 0°
#define angle_90 2 // 90 degree 45° 315°
#define angle_135 3 // 135 degree
#define angle_180 4 // 180 degree 90° R 270°
#define angle_225 5 // 225 degree
#define angle_270 6 // 270 degree 135° 225°
#define angle_315 7 // 315 degree 180°
#define gravity 2 // gravity 2 m/s²
#define e_acceleration 4 // engine acceleration 4 m/s²
#define delta_t 1 // 1s time difference for calculation
/* globale variable definitions */
int iFuel=300; // fuel capacity
int iSCORE; // Highscore
u8 program_mode; // program mode (intro, level1, level2, ....
int ibuttons; // status of SNES controller 1
u8 ani_count=0; // counter for animated sprite frame
int V0H=0; // v0 horizontal
int V0V=0; // v0 vertical
int Xold=12000; // old X position
int Yold=0; // old Y position
u8 edit_entry; // entry in hall o fame
u8 cursor; // cursor to edit entry
u8 Music_on = true; // set the background music on/off
void init(void)
// init program
{
// init music
InitMusicPlayer(patches);
//Set sprites to use.
SetSpritesTileTable(rocket);
// load into screen
set_PM_mode(PM_Intro);
//Use block 20
ebs.id = 20;
if (!isEepromFormatted())
return;
if (EEPROM_ERROR_BLOCK_NOT_FOUND == EepromReadBlock(20,&ebs))
{
set_def_highscore();
}
}
int main(){
u8 rocket_angle=0;
u8 ibuttons_old;
int y_pos=0;
int x_pos=0;
u8 a=99,b = 0;
// init program
init();
// proceed game
while(1)
{
WaitVsync(2);
// edit an entry in the hall of fame
// get controller state
ibuttons_old = ibuttons;
ibuttons = ReadJoypad(0);
switch(program_mode)
{
case PM_Intro:
// display blinking text:
if (b == 14) {
LanderPrintI(9,12,PSTR("PRESS START"));
b = 0;
} else if (b==7) {
LanderPrintI(9,12,PSTR(" "));
}
b++;
// check start button
if (BTN_START & ibuttons) {
b = 0;
rocket_angle=0;
set_PM_mode(PM_Level1);
}
if (BTN_A & ibuttons) {
iSCORE = 0;
b = 0;
set_PM_mode(PM_HoF_view);
}
if (a == b) {
LanderPrintI(10,15,PSTR(" "));
a = 99;
}
if ((ibuttons & BTN_B) && !(ibuttons_old & BTN_B)) {
if (Music_on) {
Music_on = false;
LanderPrintI(10,15,PSTR("MUSIC OFF"));
} else {
Music_on = true;
LanderPrintI(10,15,PSTR("MUSIC ON"));
}
a = b;
}
break;
case PM_Crash:
case PM_Level1:
case PM_Level2:
case PM_Level3:
case PM_Level4:
case PM_Level5:
case PM_Level6:
case PM_Level7:
if ((ibuttons & BTN_RIGHT) && !(ibuttons_old & BTN_RIGHT)) {
if (rocket_angle == 0) rocket_angle = 8;
rocket_angle--;
}
if ((ibuttons & BTN_LEFT) && !(ibuttons_old & BTN_LEFT)) {
rocket_angle++;
if (rocket_angle >= 8) rocket_angle = 0;
}
// calculate and display fuel capacity
if ((iFuel) && (ibuttons & BTN_A) && (program_mode != PM_Crash)) {
iFuel--;
TriggerFx(5, 70, false);
}
LanderPrintInt(8,26,iFuel,1, 3);
// calculate speed, acceleration and position of the rocket
if (!(b)) calculate_position(rocket_angle,(ibuttons & BTN_A) && (iFuel));
if (Xold < 0) Xold = 0;
if (Xold > 22400) Xold = 22400;
if (Yold < 0) Yold = 0;
x_pos = Xold / 100;
y_pos = Yold / 100;
// check for collision of rocket with the ground and save landing
if (program_mode == PM_Level1) b = checkcollision(x_pos,y_pos,rocket_angle,Level1_map);
else if(program_mode == PM_Level2) b = checkcollision(x_pos,y_pos,rocket_angle,Level2_map);
else if(program_mode == PM_Level3) b = checkcollision(x_pos,y_pos,rocket_angle,Level3_map);
else if(program_mode == PM_Level4) b = checkcollision(x_pos,y_pos,rocket_angle,Level4_map);
else if(program_mode == PM_Level5) b = checkcollision(x_pos,y_pos,rocket_angle,Level5_map);
else if(program_mode == PM_Level6) b = checkcollision(x_pos,y_pos,rocket_angle,Level6_map);
else if(program_mode == PM_Level7) b = checkcollision(x_pos,y_pos,rocket_angle,Level7_map);
// crash
if (b == 3) {
if (program_mode != PM_Crash) {
program_mode = PM_Crash;
ani_count = 0;
}
// save landing
} else if ((b==1) || (b==2)) {
// switch jet engine off
MapSprite2(1,rocket_Map_0_OFF,0);
// generate message
msg_window(8,10,22,15);
LanderPrint(11,12,PSTR("THE EAGLE"));
LanderPrint(10,13,PSTR("HAS LANDED!"));
// calculate Highscore
for(;iFuel > -1;iFuel--) {
iSCORE += b;
LanderPrintInt(8,26,iFuel,1, 3);
LanderPrintInt(28,26,iSCORE,1, 4);
if ((iSCORE % 10) == 0) TriggerFx(4, 0xff, true);
WaitVsync(1);
}
WaitVsync(60);
if (program_mode == PM_Level1) set_PM_mode(PM_Level2);
else if(program_mode == PM_Level2) set_PM_mode(PM_Level3);
else if(program_mode == PM_Level3) set_PM_mode(PM_Level4);
else if(program_mode == PM_Level4) set_PM_mode(PM_Level5);
else if(program_mode == PM_Level5) set_PM_mode(PM_Level6);
else if(program_mode == PM_Level6) set_PM_mode(PM_Level7);
else if(program_mode == PM_Level7) {
fade_out_volume();
b = 0;
set_PM_mode(PM_HoF_view);
}
break;
}
animate_rocket(x_pos,y_pos,rocket_angle,(ibuttons & BTN_A) && (iFuel));
break;
case PM_HoF_edit:
// cursor blinking
b++;
if (b >= 10) b = 0;
// proceed cursor position with left & right button
if ((ibuttons & BTN_RIGHT) && !(ibuttons_old & BTN_RIGHT)) {
if (cursor < 7) {
show_highscore_char(edit_entry - 1, cursor, 0);
cursor++;
}
}
if ((ibuttons & BTN_LEFT) && !(ibuttons_old & BTN_LEFT)) {
if (cursor) {
show_highscore_char(edit_entry - 1, cursor, 0);
cursor--;
}
}
// chose character up & down button
if ((ibuttons & BTN_UP) && !(ibuttons_old & BTN_UP)) {
edit_highscore_entry(edit_entry,cursor,BTN_UP);
}
else if ((ibuttons & BTN_DOWN) && !(ibuttons_old & BTN_DOWN)) {
edit_highscore_entry(edit_entry,cursor,BTN_DOWN);
}
// show cursor
show_highscore_char(edit_entry - 1, cursor, b > 4);
// store new entry
if (ibuttons & BTN_A)
{
// store new highscore
EepromWriteBlock(&ebs);
set_PM_mode(PM_Intro);
}
break;
case PM_HoF_view:
// time control
WaitVsync(2);
if (b <= 200) b++;
if (b == 100) LanderPrint(8,24,PSTR("PRESS BUTTON A"));
if (((ibuttons & BTN_A) && !(ibuttons_old & BTN_A) && (b > 50)) || (b > 200))
{
if (Music_on) fade_out_volume();
b = 0;
set_PM_mode(PM_Intro);
}
break;
}
}
}
// get the tile from the actual background map
char get_map_tile(unsigned char x,unsigned char y,const char *map) {
x /= 8;
y /= 8;
return(pgm_read_byte(&(map[(30 * y) + 2 + x])));
}
// 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 rocket with the ground
char checkcollision(u8 xx, u8 yy, u8 angle, const char *map) {
// returns 0 for no collision
// returns 1 for save landing on landing zone A
// returns 2 for save landing on landing zone B
// returns 3 for ground collision
u8 x,y;
u8 left_edge_tile, right_edge_tile;
unsigned char pix_sprite, pix_bg, tile_bg;
// check landing
// check collision
for(y = 2; y < 14; y++)
for(x = 0; x < 16; x+=2)
{
tile_bg = get_map_tile(xx + x, yy + y,map);
if (((tile_bg >= 4) && (tile_bg <= 9)) || ((tile_bg >= 88) && (tile_bg <= 98)))
{
pix_bg = get_tile_pixel((xx + x) % 8,(yy + y) % 8,tile_bg,backgroundTileset);
if (angle < angle_225) pix_sprite = get_tile_pixel(x % 8,y % 8,get_sprite_tile(x,y),rocket);
else pix_sprite = get_tile_pixel((15 - x) % 8,y % 8,get_sprite_tile(x ,y),rocket);
// crash?
if ((pix_sprite != 0xFE) && (pix_bg)) {
// save landing ?
if ((angle == angle_0) && (V0H < 40) && (V0V< 40) && ((pix_bg == 0xD9) || (pix_bg == 0x06))) {
// check position of landing zone
left_edge_tile = get_map_tile(xx + 2, yy + 12,map);
right_edge_tile = get_map_tile(xx + 12, yy + 12,map);
if ((left_edge_tile == 0x08) && (right_edge_tile == 0x08)) return(1);
if ((left_edge_tile == 0x09) && (right_edge_tile == 0x09)) return(2);
}
//LanderPrintInt(21,26,V0H,1,5);
//LanderPrintInt(21,27,V0V,1,5);
/*
LanderPrintByte(25,26,x,1);
LanderPrintByte(25,27,xx,1);
LanderPrintByte(29,26,y,1);
LanderPrintByte(29,27,yy,1);
*/
return(3);
}
}
}
return(0);
}
//Print an unsigned byte in decimal
void LanderPrintByte(int x,int y, unsigned char val,bool zeropad){
unsigned char c,i;
for(i=0;i<3;i++){
c=val%10;
if(val>0 || i==0){
// SetFont(x--,y,c+CHAR_ZERO+RAM_TILES_COUNT);
SetTile(x--, y, c + FONT_OFFSET + 0x0F);
}else{
if(zeropad){
// SetFont(x--,y,CHAR_ZERO+RAM_TILES_COUNT);
SetTile(x--, y, c + FONT_OFFSET + 0x0F);
}else{
// SetFont(x--,y,0+RAM_TILES_COUNT);
SetTile(x--, y, 0 + FONT_OFFSET + 0x0F);
}
}
val=val/10;
}
}
//Print an unsigned int in decimal
void LanderPrintInt(int x,int y, unsigned int val,bool zeropad, u8 digits){
unsigned char c,i;
for(i=0;i<digits;i++){
c=val%10;
if(val>0 || i==0){
//SetFont(x--,y,c+CHAR_ZERO+RAM_TILES_COUNT);
SetTile(x--, y, c + FONT_OFFSET + 0x0F);
}else{
if(zeropad){
// SetFont(x--,y,CHAR_ZERO+RAM_TILES_COUNT);
SetTile(x--, y, c + FONT_OFFSET + 0x0F);
}else{
// SetFont(x--,y,0+RAM_TILES_COUNT);
SetTile(x--, y, 0 + FONT_OFFSET + 0x0F);
}
}
val=val/10;
}
}
void LanderPrint(int x, int y, const char *s) {
// print text in game screens
u8 c;
int i = 0;
while (1) {
c = pgm_read_byte(&(s[i++]));
if (c) {
while (1) {
if (c == ' ') {
SetTile(x++, y, 0); // space
break;
} else {
SetTile(x++, y, c + FONT_OFFSET - 0x21);
break;
}
}
} else {
break;
}
}
}
void LanderPrintI(int x, int y, const char *s) {
// print text in intro screen
u8 c;
int i = 0;
while (1) {
c = pgm_read_byte(&(s[i++]));
if (c) {
//while (1) {
switch (c) {
case ' ':
SetTile(x++, y, 0);
break;
case '.':
SetTile(x++, y, FONT_OFFSET_INTRO + 2);
break;
case '$':
SetTile(x++, y, FONT_OFFSET_INTRO + 1);
break;
case '0':
case '1':
case '2':
case '3':
SetTile(x++, y, c + FONT_OFFSET_INTRO - 0x2D);
break;
default:
SetTile(x++, y, c + FONT_OFFSET_INTRO - 0x3A); // A..Z
}
//}
} else {
break;
}
}
}
void msg_window(u8 x1, u8 y1, u8 x2, u8 y2) {
// draw a window with frame and black backgound on the screen
// window backgound
Fill(x1 + 1, y1 + 1, x2 - x1 - 1, y2 - y1 - 1,0);
// upper frame
Fill(x1 + 1, y1, x2 - x1 - 1, 1,162);
// lower frame
Fill(x1 + 1, y2, x2 - x1 - 1, 1,162);
// left frame
Fill(x1 , y1 + 1, 1, y2 - y1 - 1,165);
// right frame
Fill(x2, y1 + 1, 1 , y2 - y1 - 1,165);
// upper, left corner
SetTile(x1,y1,161);
// upper, right corner
SetTile(x2,y1,163);
// lower, left corner
SetTile(x1,y2,164);
// lower, right corner
SetTile(x2,y2,166);
}
void calculate_position(u8 angle, u8 B_engine) {
// calculate x and y coordinates
char a_v = gravity; //acceleration vertical
char a_h = 0; //acceleration horizontal
// set acceleration
switch (angle)
{
case angle_0: //0 degree
if (B_engine) a_v = gravity - e_acceleration;
break;
case angle_45: //45 degree
if (B_engine) {
a_v = gravity - (e_acceleration / 2);
a_h = - (e_acceleration / 2);
}
break;
case angle_315: //315 degree
if (B_engine) {
a_v = gravity - (e_acceleration / 2);
a_h = e_acceleration / 2;
}
break;
case angle_90: //90 degree
if (B_engine) a_h = - (e_acceleration);
break;
case angle_270: //270 degree
if (B_engine) a_h = e_acceleration;
break;
case angle_135: //135 degree
if (B_engine) {
a_v = gravity + (e_acceleration / 2);
a_h = - (e_acceleration / 2);
}
break;
case angle_225: //225 degree
if (B_engine) {
a_v = gravity + (e_acceleration / 2);
a_h = e_acceleration / 2;
}
break;
case angle_180: //180 degree
if (B_engine) a_v = gravity + e_acceleration;
break;
}
// calculate speed
V0V = (delta_t * a_v) + V0V;
//yy = V0V * delta_t;
V0H = (delta_t * a_h) + V0H;
//xx = V0H * delta_t;
// calculate posiion
Xold += (V0H * delta_t);
Yold += (V0V * delta_t);
}
void animate_rocket(u8 xx, u8 yy, u8 angle, u8 B_engine) {
// draw and animate the rocket
u8 spriteflag = 0;
if (program_mode == PM_Crash) {
// rocket explosion
switch (ani_count)
{
case 0: // 1st picture for explosion
TriggerFx(3, 0xff, true);
MapSprite2(1,rocket_Map_exp_0,0);
break;
case 1: // 2nd picture for explosion
MapSprite2(1,rocket_Map_exp_1,0);
break;
case 2: // 3rd picture for explosion
MapSprite2(1,rocket_Map_exp_2,0);
break;
case 3: // 4th picture for explosion
MapSprite2(1,rocket_Map_exp_3,0);
break;
case 4: // 5th picture for explosion
MapSprite2(1,rocket_Map_exp_4,0);
break;
case 5: // 6st picture for explosion
MapSprite2(1,rocket_Map_exp_5,0);
break;
case 6: // 7st picture for explosion
MapSprite2(1,rocket_Map_exp_6,0);
break;
case 7: // 8st picture for explosion
MapSprite2(1,rocket_Map_exp_7,0);
break;
case 8: // 9st picture for explosion
MapSprite2(1,rocket_Map_exp_8,0);
break;
case 9: // delete last picture of explosion
MapSprite2(1,rocket_Map_hide,0);
// message
msg_window(8,10,22,15);
LanderPrint(10,12,PSTR("YOU MADE A"));
LanderPrint(10,13,PSTR("NEW CRATER!"));
fade_out_volume();
break;
case 60:
set_PM_mode(PM_HoF_view);
break;
}
WaitVsync(3);
} else {
// normal rocket flight
switch (angle)
{
case angle_0: //0 degree
if (B_engine) {
//button A is pressed
if (ani_count & 0x01) MapSprite2(1,rocket_Map_0_ON2,spriteflag);
else MapSprite2(1,rocket_Map_0_ON1,spriteflag);
} else {
// button A is unpressed
MapSprite2(1,rocket_Map_0_OFF,spriteflag);
}
break;
case angle_315: //315 degree
spriteflag = SPRITE_FLIP_X;
case angle_45: //45 degree
if (B_engine) {
//button A is pressed
if (ani_count & 0x01) MapSprite2(1,rocket_Map_45_ON2,spriteflag);
else MapSprite2(1,rocket_Map_45_ON1,spriteflag);
} else {
// button A is unpressed
MapSprite2(1,rocket_Map_45_OFF,spriteflag);
}
break;
case angle_270: //270 degree
spriteflag = SPRITE_FLIP_X;
case angle_90: //90 degree
if (B_engine) {
//button A is pressed
if (ani_count & 0x01) MapSprite2(1,rocket_Map_90_ON2,spriteflag);
else MapSprite2(1,rocket_Map_90_ON1,spriteflag);
} else {
// button A is unpressed
MapSprite2(1,rocket_Map_90_OFF,spriteflag);
}
break;
case angle_225: //225 degree
spriteflag = SPRITE_FLIP_X;
case angle_135: //135 degree
if (B_engine) {
//button A is pressed
if (ani_count & 0x01) MapSprite2(1,rocket_Map_135_ON2,spriteflag);
else MapSprite2(1,rocket_Map_135_ON1,spriteflag);
} else {
// button A is unpressed
MapSprite2(1,rocket_Map_135_OFF,spriteflag);
}
break;
case angle_180: //180 degree
if (B_engine) {
//button A is pressed
if (ani_count & 0x01) MapSprite2(1,rocket_Map_180_ON2,spriteflag);
else MapSprite2(1,rocket_Map_180_ON1,spriteflag);
} else {
// button A is unpressed
MapSprite2(1,rocket_Map_180_OFF,spriteflag);
}
break;
}
}
MoveSprite(1,xx,yy,2,2);
ani_count++;
if (ani_count >= 200) ani_count = 0;
}
void set_PM_mode(u8 mode) {
// set parameters, tiles, background etc for choosed program mode
switch (mode)
{
case PM_Intro:
SetSpriteVisibility(false);
StopSong();
ClearVram();
WaitVsync(2);
//Set the font and tiles to use.
SetTileTable(introTileset);
// draw lander logo
DrawMap2(7,1,lander_logo_Map);
LanderPrintI(9,6,PSTR("VERSION 1.1"));
LanderPrintI(5,19,PSTR("$ 2011 HARTMUT WENDT"));
LanderPrintI(2,21,PSTR("SOUNDTRACK BX CARSTEN KUNY"));
LanderPrintI(2,24,PSTR("LICENCED UNDER GNU GPL V3"));
LanderPrintI(5,26,PSTR("WWW.HWHARDSOFT.DE.VU"));
WaitVsync(10);
SetMasterVolume(130);
break;
case PM_HoF_view:
SetMasterVolume(130);
if (Music_on) StartSong(champions_song);
SetSpriteVisibility(false);
edit_entry = check_highscore();
if (edit_entry == 2) copy_highsore(1,2);
if (edit_entry == 1) {
copy_highsore(1,2);
copy_highsore(0,1);
}
clear_highsore(edit_entry - 1);
// reset cursor to left position
cursor = 0;
//Set the font and tiles to use.
SetTileTable(backgroundTileset);
ClearVram();
msg_window(7,8,23,19);
LanderPrint(9,10,PSTR("HALL OF FAME"));
view_highscore_entry(9,13,1,!(edit_entry));
view_highscore_entry(9,15,2,!(edit_entry));
view_highscore_entry(9,17,3,!(edit_entry));
if (edit_entry == 0) {
//WaitVsync(800);
//set_PM_mode(PM_Intro);
//mode = PM_Intro;
} else {
mode = PM_HoF_edit;
LanderPrint(8,3,PSTR("CONGRATULATION"));
LanderPrint(8,5,PSTR("NEW HIGHSCORE!"));
LanderPrint(7,22,PSTR("ENTER YOUR NAME"));
LanderPrint(6,24,PSTR("AND PRESS BUTTON A"));
}
break;
case PM_Level1:
Xold = 10000;
Yold = 0;
iFuel =500;
V0V = 0;
V0H = 0;
iSCORE = 0;
//Set the font and tiles to use.
SetTileTable(backgroundTileset);
ClearVram();
// draw level1 map
DrawMap2(0,0,Level1_map);
// draw bottom text line
view_bottom_line(1);
//start sound track
if (Music_on) StartSong(rocketman_song);
ready_steady_go(Level1_map);
SetSpriteVisibility(true);
break;
case PM_Level2:
Xold = 11000;
Yold = 0;
iFuel= 400;
V0V = 50;
V0H = 0;
ClearVram();
// draw level1 map
DrawMap2(0,0,Level2_map);
// draw bottom text line
view_bottom_line(2);
ready_steady_go(Level2_map);
SetSpriteVisibility(true);
break;
case PM_Level3:
Xold = 10000;
Yold = 0;
iFuel = 400;
V0V = 40;
V0H = -40;
ClearVram();
// draw level3 map
DrawMap2(0,0,Level3_map);
// draw bottom text line
view_bottom_line(3);
ready_steady_go(Level3_map);
SetSpriteVisibility(true);
break;
case PM_Level4:
Xold = 10000;
Yold = 0;
iFuel = 350;
V0V = 20;
V0H = 20;
ClearVram();
// draw level4 map
DrawMap2(0,0,Level4_map);
// draw bottom text line
view_bottom_line(4);
ready_steady_go(Level4_map);
SetSpriteVisibility(true);
break;
case PM_Level5:
Xold = 10000;
Yold = 0;
iFuel = 400;
V0V = 20;
V0H = 00;
//Set the font and tiles to use.
SetTileTable(backgroundTileset);
ClearVram();
// draw level5 map
DrawMap2(0,0,Level5_map);
// draw bottom text line
view_bottom_line(5);
ready_steady_go(Level5_map);
SetSpriteVisibility(true);
break;
case PM_Level6:
Xold = 200;
Yold = 0;
iFuel = 550;
V0V = 20;
V0H = 00;
//Set the font and tiles to use.
SetTileTable(backgroundTileset);
ClearVram();
// draw level6 map
DrawMap2(0,0,Level6_map);
// draw bottom text line
view_bottom_line(6);
ready_steady_go(Level6_map);
SetSpriteVisibility(true);
break;
case PM_Level7:
Xold = 27000;
Yold = 0;
iFuel = 600;
V0V = 20;
V0H = 00;
//Set the font and tiles to use.
SetTileTable(backgroundTileset);
ClearVram();
// draw level6 map
DrawMap2(0,0,Level7_map);
// draw bottom text line
view_bottom_line(7);
ready_steady_go(Level7_map);
SetSpriteVisibility(true);
break;
}
program_mode = mode;
}
void view_bottom_line(u8 level) {
// views the bottom line
LanderPrint(1,26,PSTR("FUEL:"));
LanderPrintByte(16,26,level,true);
LanderPrint(10,26,PSTR("LEVEL-"));
LanderPrint(19,26,PSTR("SCORE:"));
LanderPrintInt(28,26,iSCORE,1, 4);
WaitVsync(10);
}
void ready_steady_go(const char *map) {
// ready steady go count down
u8 x,y;
SetSpriteVisibility(false);
msg_window(10,9,20,17);
LanderPrint(12,11,PSTR("READY,"));
WaitVsync(60);
LanderPrint(12,13,PSTR("STEADY,"));
WaitVsync(60);
LanderPrint(12,15,PSTR("GO!"));
WaitVsync(60);
// restore background
for(y = 9; y<=17; y++)