-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPipes.c
2252 lines (1783 loc) · 57.1 KB
/
Pipes.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
/*
* Pipe dream clone for Uzebox
* Version 1.0
* Copyright (C) 2012 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/>.
*/
//#define _Fading // enables FadeIn & FadeOut between the different screens
#define _Music // enables Music
#define Music_volume 50 // volume for music
#define SFX_volume 250 // volume for sound effects
#include <stdbool.h>
#include <string.h>
#include <avr/io.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
#include "kernel/uzebox.h"
#include "data/pipes_BGTiles.pic.inc"
#include "data/fonts.pic.inc"
#include "data/animations.inc"
#include "data/patches.inc"
#ifdef _Music
#include "data/pipes_tracks.inc"
#endif
/* global definitons */
// program modes
enum {
PM_Intro, // program mode intro
PM_Game_Start, // program mode: Game starts
PM_Game_Flow, // program mode: Game water flow
PM_Game_End, // program mode: Game ends
PM_Credits, // shows credits
PM_HoF_view, // view hall of fame
PM_HoF_edit, // edit hall of fame
PM_Game_over, // program mode for game over screen
PM_Game_Start_Menu, // small menu during game start
PM_Game_Flow_Menu, // small menu during game
PM_Help_Screen1,// help screen 1
PM_Help_Screen2,// help screen 2
PM_Help_Screen3,// help screen 3
PM_Help_Screen4,// help screen 4
};
//pipes
#define max_pipes 81
enum {
Empty,
Start_left_empty,
Start_right_empty,
Start_up_empty,
Start_down_empty,
Start_left_full,
Start_right_full,
Start_up_full,
Start_down_full,
End_left_empty,
End_right_empty,
End_up_empty,
End_down_empty,
End_left_full,
End_right_full,
End_up_full,
End_down_full,
Pump_ver_empty,
Pump_hor_empty,
Pump_ver_full,
Pump_hor_full,
Reservoir_ver_empty,
Reservoir_hor_empty,
Reservoir_ver_full,
Reservoir_hor_full,
Straight_ver_empty,
Straight_hor_empty,
Straight_ver_full,
Straight_hor_full,
Edge_upper_left_empty,
Edge_upper_left_full,
Edge_lower_left_empty,
Edge_lower_left_full,
Edge_upper_right_empty,
Edge_upper_right_full,
Edge_lower_right_empty,
Edge_lower_right_full,
Cross_hor_empty_ver_empty,
Cross_hor_full_ver_empty,
Cross_hor_empty_ver_full,
Cross_hor_full_ver_full,
Arrow_right_empty,
Arrow_right_full,
Arrow_left_empty,
Arrow_left_full,
Arrow_up_empty,
Arrow_up_full,
Arrow_down_empty,
Arrow_down_full,
Cursor_straight_ver,
Cursor_straight_hor,
Cursor_edge_upper_left,
Cursor_edge_lower_left,
Cursor_edge_upper_right,
Cursor_edge_lower_right,
Cursor_cross,
Cursor_arrow_right,
Cursor_arrow_left,
Cursor_arrow_up,
Cursor_arrow_down
};
// difficulty
enum {
Easy, // difficulty easy
Medium, // difficulty medium
Hard, // difficulty hard
};
// flow directions
enum {
flow_left,
flow_right,
flow_up,
flow_down
};
struct pipe_stack_options {
u8 CursorMap;
u8 StackMap;
u8 GameMap;
};
// general parameters
// 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 Flow_Speed_Easy 28
#define Flow_Speed_Medium 24
#define Flow_Speed_Hard 20
//#define delta_t 1
#define MAX(x,y) ((x)>(y) ? (x) : (y))
struct EepromBlockStruct ebs;
struct pipe_stack_options pipe_stack[5];
u8 prng; // Pseudo-random number generator
u8 program_mode; // program mode (intro, 1 player mode, 2 player mode, ....
u8 PosX=0, PosY=0; // position of cursor
//u8 current_step;
int iSCORE; // Highscore
bool Music_on= true;
u8 Start_point_X;
u8 Start_point_Y;
u8 End_point_X,End_point_Y;
u8 ani_cur = 0;
u8 Flow_direction;
u8 Flow_ani_cnt = 0;
u8 Flow_speed;
u8 Flow_step = 0;
int Flow_animation[4];
u8 Difficulty = Easy;
u8 Tunnel_ver;
u8 Tunnel_hor;
u8 Wrenches=3;
u8 Distance;
u8 pump_cnt;
u8 loop_cnt;
u8 menu_background[40];
u8 CUR_POS_GM;
static u8 playing_field[max_pipes];
/*** function prototypes *****************************************************************/
void init(void);
void set_PM_mode(u8 mode);
void copy_buf(unsigned char *BUFA, unsigned char *BUFB, unsigned char ucANZ);
void fill_buf(unsigned char *BUFA, unsigned char value, unsigned char ucANZ);
void msg_window(u8 x1, u8 y1, u8 x2, u8 y2, bool background, bool shadow);
int get_highscore(u8 entry);
u8 check_highscore(void);
void copy_highsore(u8 entry_from, u8 entry_to);
void clear_highsore(u8 entry);
u8 set_def_highscore(void);
u8 view_highscore_entry(u8 x, u8 y, u8 entry, u8 load_data, u8 uDiff);
void edit_highscore_entry(u8 entry, u8 cursor_pos, u8 b_mode);
void show_highscore_char(u8 entry, u8 position, u8 cursor_on);
int GetTile(u8 xx, u8 yy);
void create_new_playing_field(u8 uDiff);
u8 check_pipe_area(u8 uX, u8 uY);
void init_pipe_stack(u8 uDiff);
void show_pipe_stack(void);
void cycle_pipe_stack(u8 uDiff);
void pipe_stack_random_map(u8 uDiff, u8 index);
u8 get_pipe(u8 uX, u8 uY);
void set_pipe_cursor(u8 xx, u8 yy);
void hide_pipe_cursor(u8 xx, u8 yy);
void place_pipe(u8 uX, u8 uY, u8 uPipe);
void set_pipe(u8 uX, u8 uY, u8 uPipe);
u8 next_pipe(bool bStart);
void Draw_Wrench_reserve(void);
void Draw_Intro_char(u8 uX, u8 uY, const int *PChar, u8 columns);
void animate_pipes(void);
void animate_start(u8 uDiff);
void animate_explosion(u8 *uX,u8 *uY, u8 *Step, bool BEndGame);
void end_game(void);
u8 read_eep_block(u8 uDiff);
void dbg_highscore_print(u8 entry, u8 position);
//void fade_out_volume(void);
void set_flow_speed(void);
void save_background(u8 x1, u8 y1,u8 x2, u8 y2);
void restore_background(u8 x1, u8 y1,u8 x2, u8 y2);
void init(void)
// init program
{
//Set the tile table to use.
SetTileTable(BGTiles);
// init font table
SetFontTable(fonts);
// init music
InitMusicPlayer(patches);
#ifdef _Music
StartSong(Pipes_menu_song);
#endif
SetMasterVolume(Music_volume);
// init random generator
prng = 15;
// load into screen
set_PM_mode(PM_Intro);
//Use block 25
ebs.id = 25;
if (!isEepromFormatted())
return;
if (EEPROM_ERROR_BLOCK_NOT_FOUND == EepromReadBlock(25,&ebs))
{
set_def_highscore();
}
//Use block 26
ebs.id = 26;
if (!isEepromFormatted())
return;
if (EEPROM_ERROR_BLOCK_NOT_FOUND == EepromReadBlock(26,&ebs))
{
set_def_highscore();
}
}
int main(){
int ibuttons=0,ibuttons_old;
u8 u1,b=0,uX,uY,uPos_EXP_X,uPos_EXP_Y;
u8 EXP_ANI_CNT = 0;
// init program
init();
// proceed game
while(1)
{
WaitVsync(2);
// get controller state
ibuttons_old = ibuttons;
ibuttons = ReadJoypad(0);
switch(program_mode)
{
// proceed intro mode
case PM_Intro:
// button A
if ((BTN_A & ibuttons) && !(ibuttons_old & BTN_A)) {
// wait for release of button A
while (BTN_A & ReadJoypad(0)) {
prng++;
WaitVsync(1);
}
prng = MAX(prng,1);
if (PosY == 0) set_PM_mode(PM_Game_Start);
else if (PosY == 1) {
if (Difficulty == Hard) {
Print(13,18,PSTR(" EASY"));
Difficulty = Easy;
} else if (Difficulty == Easy) {
Print(13,18,PSTR("MEDIUM"));
Difficulty = Medium;
} else {
Print(13,18,PSTR(" HARD"));
Difficulty = Hard;
}
}
else if (PosY == 2) set_PM_mode(PM_Credits);
else if (PosY == 3) {
iSCORE = 0;
set_PM_mode(PM_HoF_view);
}
else if (PosY == 4) {
if (Music_on) {
SetMasterVolume(0);
Music_on = false;
Print(10,21,PSTR("MUSIC OFF"));
StopSong();
} else {
SetMasterVolume(Music_volume);
Music_on = true;
Print(10,21,PSTR(" MUSIC ON"));
ResumeSong();
}
} else set_PM_mode(PM_Help_Screen1);
}
// UP button
if ((ibuttons & BTN_UP) && !(ibuttons_old & BTN_UP)) {
// wait for release of button BTN_UP
while (BTN_UP & ReadJoypad(0));
PrintChar(20,17+PosY,' ');
if (PosY) PosY--;
PrintChar(20,17+PosY,'$');
// DOWN button
} else if ((ibuttons & BTN_DOWN) && !(ibuttons_old & BTN_DOWN)) {
// wait for release of button BTN_DOWN
while (BTN_DOWN & ReadJoypad(0));
PrintChar(20,17+PosY,' ');
if (PosY<5) PosY++;
PrintChar(20,17+PosY,'$');
}
break;
// game play
case PM_Game_Start:
case PM_Game_Flow:
uX = PosX;
uY = PosY;
// check controller action
if ((BTN_LEFT & ibuttons) && !(BTN_LEFT & ibuttons_old) && (uX)) uX--;
else if ((BTN_RIGHT & ibuttons) && !(BTN_RIGHT & ibuttons_old) && (uX<8)) uX++;
if ((BTN_UP & ibuttons) && !(BTN_UP & ibuttons_old) && (uY)) uY--;
else if ((BTN_DOWN & ibuttons) && !(BTN_DOWN & ibuttons_old) && (uY<8)) uY++;
set_pipe_cursor(uX,uY);
if ((BTN_A & ibuttons) && !(ibuttons_old & BTN_A)) {
// place pipe
u1 = get_pipe(PosX,PosY);
if (u1 == Empty) {
place_pipe(PosX,PosY,pipe_stack[0].GameMap);
playing_field[(PosY * 9) + PosX] = pipe_stack[0].GameMap;
cycle_pipe_stack(Difficulty);
show_pipe_stack();
TriggerFx(4, 0x7f, true);
} else if (((u1 == Straight_ver_empty) || (u1 == Straight_hor_empty) || (u1 == Edge_upper_left_empty) ||
(u1 == Edge_lower_right_empty) || (u1 == Edge_lower_left_empty) || (u1 == Edge_upper_right_empty) ||
(u1 == Cross_hor_empty_ver_empty) || (u1 == Arrow_right_empty) || (u1 == Arrow_left_empty) ||
(u1 == Arrow_up_empty) || (u1 == Arrow_down_empty)) && !(EXP_ANI_CNT)) {
//place_pipe(PosX,PosY,*pipe_maps[Empty]);
playing_field[(PosY * 9) + PosX] = pipe_stack[0].GameMap;
cycle_pipe_stack(Difficulty);
show_pipe_stack();
if (iSCORE >= 5) iSCORE -= 5;
// set values for pipe explosion
uPos_EXP_X = PosX;
uPos_EXP_Y = PosY;
EXP_ANI_CNT = 11;
TriggerFx(5, 0x7f, true);
}
}
// button START
else if ((BTN_START & ibuttons) && !(ibuttons_old & BTN_START)) {
if (program_mode == PM_Game_Start) set_PM_mode(PM_Game_Start_Menu);
else set_PM_mode(PM_Game_Flow_Menu);
}
// show score & Distance
PrintInt(20,2,iSCORE,false);
PrintByte(16,4,Distance,false);
// handle animation explosion
animate_explosion(&uPos_EXP_X,&uPos_EXP_Y,&EXP_ANI_CNT,false);
// handle animation pipe flow
if (program_mode == PM_Game_Flow) {
Flow_step++;
if (Flow_step >= Flow_speed) {
Flow_step = 0;
animate_pipes();
}
} else if (program_mode == PM_Game_Start) {
Flow_step++;
if (Flow_step >= Flow_speed) {
Flow_step = 0;
animate_start(Difficulty);
}
}
break;
// game play ends
case PM_Game_End:
if ((ibuttons) && (ibuttons != ibuttons_old)) {
// wait for release of all buttons
while (ReadJoypad(0)) {
prng++;
WaitVsync(1);
}
prng = MAX(prng,1);
if (Wrenches) set_PM_mode(PM_Game_Start);
else {
StopSong;
set_PM_mode(PM_HoF_view);
#ifdef _Music
if (Music_on == true) StartSong(Pipes_menu_song);
#endif
}
}
break;
// menu in games
case PM_Game_Start_Menu:
case PM_Game_Flow_Menu:
// UP button
if ((ibuttons & BTN_UP) && !(ibuttons_old & BTN_UP)) {
PrintChar(17,13+CUR_POS_GM,' ');
if (CUR_POS_GM) CUR_POS_GM--;
PrintChar(17,13+CUR_POS_GM,'$');
// DOWN button
} else if ((ibuttons & BTN_DOWN) && !(ibuttons_old & BTN_DOWN)) {
PrintChar(17,13+CUR_POS_GM,' ');
if (CUR_POS_GM<1) CUR_POS_GM++;
PrintChar(17,13+CUR_POS_GM,'$');
}
if ((BTN_A & ibuttons) && !(ibuttons_old & BTN_A)) {
// wait for release of button A
while (BTN_A & ReadJoypad(0));
ibuttons = 0;
if (CUR_POS_GM) {
#ifdef _Music
if (Music_on == true) StartSong(Pipes_menu_song);
#endif
set_PM_mode(PM_Intro);
} else {
if (program_mode == PM_Game_Start_Menu) program_mode = PM_Game_Start;
else program_mode = PM_Game_Flow;
restore_background(12,12,19,16);
}
}
break;
// show credits screen...
case PM_Credits:
if ((ibuttons) && (ibuttons != ibuttons_old)) {
// wait for release of all buttons
while (ReadJoypad(0));
set_PM_mode(PM_Intro);
}
break;
case PM_HoF_view:
// time control
if (b <= 200) b++;
if (b == 50) Print(9,22,PSTR("PRESS ANY KEY"));
if (((ibuttons & BTN_A) && !(ibuttons_old & BTN_A) && (b > 50)) || (b > 200))
{
b = 0;
set_PM_mode(PM_Intro);
}
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 (PosX < 2) {
show_highscore_char(PosY - 1, PosX, 0);
PosX++;
}
}
if ((ibuttons & BTN_LEFT) && !(ibuttons_old & BTN_LEFT)) {
if (PosX) {
show_highscore_char(PosY - 1, PosX, 0);
PosX--;
}
}
// chose character up & down button
if ((ibuttons & BTN_UP) && !(ibuttons_old & BTN_UP)) {
edit_highscore_entry(PosY,PosX,BTN_UP);
}
else if ((ibuttons & BTN_DOWN) && !(ibuttons_old & BTN_DOWN)) {
edit_highscore_entry(PosY,PosX,BTN_DOWN);
}
// show cursor
show_highscore_char(PosY - 1, PosX, b > 4);
// store new entry
if (ibuttons & BTN_A)
{
// store new highscore
if (Difficulty == Hard) ebs.id = 26;
else ebs.id = 25;
EepromWriteBlock(&ebs);
set_PM_mode(PM_Intro);
}
break;
case PM_Help_Screen1:
case PM_Help_Screen2:
case PM_Help_Screen3:
case PM_Help_Screen4:
// Help screens
if ((ibuttons) && (ibuttons != ibuttons_old)) {
// wait for release of all buttons
while (ReadJoypad(0));
program_mode++;
if (program_mode > PM_Help_Screen4) set_PM_mode(PM_Intro);
else set_PM_mode(program_mode);
}
break;
}
}
}
void set_PM_mode(u8 mode) {
// set parameters, tiles, background etc for choosed program mode
u8 a,b, dmyhighscore[30];
switch (mode)
{
case PM_Intro:
// init variables
PosY = 0;
iSCORE = 0;
Wrenches=3;
//clear screen with fade
#ifdef _Fading
FadeOut(1, true);
#endif
ClearVram();
Fill(0,0,30,28,2);
Fill(1,1,28,12,1);
// draw P
Draw_Intro_char(2,2,&pipe_logo_P[0],3);
Draw_Intro_char(9,2,&pipe_logo_I[0],1);
Draw_Intro_char(12,2,&pipe_logo_P[0],3);
Draw_Intro_char(19,2,&pipe_logo_E[0],2);
Draw_Intro_char(24,2,&pipe_logo_S[0],2);
// menu
msg_window(8,15,22,24,true,true);
Print(15,17,PSTR("PLAY $"));
// Difficulty
if (Difficulty == Easy) {
Print(15,18,PSTR("EASY"));
} else if (Difficulty == Medium) {
Print(13,18,PSTR("MEDIUM"));
} else {
Print(15,18,PSTR("HARD"));
}
Print(12,19,PSTR("CREDITS"));
Print(10,20,PSTR("HIGHSCORE"));
// Music on/off
if (Music_on) {
Print(11,21,PSTR("MUSIC ON "));
} else {
Print(10,21,PSTR("MUSIC OFF "));
}
Print(15,22,PSTR("HELP"));
#ifdef _Fading
FadeIn(1, true);
#endif
break;
case PM_Game_Start:
// game play
// stop music
StopSong();
// full volume
SetMasterVolume(SFX_volume);
// set variables
PosX=0, PosY=0;
loop_cnt = 0;
pump_cnt = 0;
Flow_ani_cnt = 0;
//clear screen with fade
#ifdef _Fading
FadeOut(1, true);
#endif
ClearVram();
Fill(0,0,30,28,2);
// pipe reservoir
msg_window(1,1,4,11,true,true);
SetTile(1,1,frame_vertical);
SetTile(4,1,frame_vertical);
// message box
msg_window(7,1,26,5,true,true);
Print(9,2,PSTR("SCORE"));
Print(9,3,PSTR("WRENCHES "));
Print(9,4,PSTR("DIST"));
if (Difficulty == Easy) {
Print(21,4,PSTR("EASY"));
Distance = 15;
} else if (Difficulty == Medium) {
Print(19,4,PSTR("MEDIUM"));
Distance = 20;
} else {
Print(21,4,PSTR("HARD"));
Distance = 25;
}
set_flow_speed();
PrintByte(16,4,Distance,false);
Draw_Wrench_reserve();
// playing field
msg_window(7,6,26,25,false,true);
create_new_playing_field(Difficulty);
for(a=0; a<9 ; a++)
for(b=0; b<9 ; b++) place_pipe(a,b,playing_field[(b * 9) + a]);
// pipe stack
init_pipe_stack(Difficulty);
show_pipe_stack();
// draw progressbar
for(a=0; a<20 ; a++) SetTile(27,a+6,time_bar);
#ifdef _Fading
FadeIn(1, true);
#endif
#ifdef _Music
if (Music_on == true) StartSong(Pipes_game_song);
#endif
break;
case PM_Credits:
// show credits
//clear screen with fade
#ifdef _Fading
FadeOut(1, true);
#endif
ClearVram();
Fill(0,0,30,28,2);
msg_window(4,4,26,23,true,true);
Print(7,6,PSTR("PIPES FOR UZEBOX"));
Print(9,7,PSTR("VERSION 1.0"));
Print(7,10,PSTR("COPYRIGHT % 2012"));
Print(7,11,PSTR("BY HARTMUT WENDT"));
Print(7,12,PSTR("WWW.HWHARDSOFT.DE"));
Print(9,15,PSTR("SOUND TRACK"));
Print(7,16,PSTR("BY CARSTEN KUNZ"));
Print(8,19,PSTR("LICENSED UNDER"));
Print(10,20,PSTR("GNU GPL V3"));
#ifdef _Fading
FadeIn(1, true);
#endif
break;
case PM_Help_Screen1:
// help screen 1
// introduce all the crazy pipes
//clear screen with fade
#ifdef _Fading
FadeOut(1, true);
#endif
ClearVram();
Fill(0,0,30,28,1);
Print(8,1,PSTR("HELP - PAGE 1/4"));
// first row
DrawMap(4,4,pipe_straight_ve);
DrawMap(14,4,pipe_edge_ul_e);
DrawMap(24,4,pipe_cross_ve_he);
Print(1,7,PSTR("STRAIGHT"));
Print(12,7,PSTR("CORNER"));
Print(23,7,PSTR("CROSS"));
// second row
DrawMap(4,12,pipe_arrow_left_he);
DrawMap(14,12,start_piece_de);
SetTile(14,12,Start_sign);
DrawMap(24,12,start_piece_de);
SetTile(24,12,End_sign);
Print(1,15,PSTR("ONE-WAY"));
Print(12,15,PSTR("START"));
Print(23,15,PSTR("END"));
// third row
DrawMap(4,20,reservoir_ve);
DrawMap(14,20,pump_he);
SetTile(22,20,frame_horizontal);
SetTile(23,20,frame_horizontal);
SetTile(24,20,GB_Black);
SetTile(25,20,GB_Black);
SetTile(26,20,frame_horizontal);
SetTile(27,20,frame_horizontal);
Print(1,23,PSTR("RESERVOIR"));
Print(13,23,PSTR("PUMP"));
Print(22,23,PSTR("TUNNEL"));
Print(8,26,PSTR("PRESS ANY KEY"));
#ifdef _Fading
FadeIn(1, true);
#endif
break;
case PM_Help_Screen2:
// help screen 2
// pipes basics
//clear screen with fade
#ifdef _Fading
FadeOut(1, true);
#endif
ClearVram();
Fill(0,0,30,28,1);
Print(8,1,PSTR("HELP - PAGE 2/4"));
Print(1, 3,PSTR("THE OBJECT IS TO SCORE AS"));
Print(1, 4,PSTR("MANY POINTS AS POSSIBLE BY"));
Print(1, 5,PSTR("CONSTRUCTING A CONTINUOUS"));
Print(1, 6,PSTR("PIPE FROM THE STARTING PIECE"));
Print(1, 8,PSTR("THE NEXT PIECE TO BE PLAYED"));
Print(1, 9,PSTR("APPEARS ON THE BOTTOM OF THE"));
Print(1,10,PSTR("DISPENSER (LEFT) AND OVER"));
Print(1,11,PSTR("THE PLAYFIELD."));
Print(1,13,PSTR("YOU MUST PLAY THE PIPES IN"));
Print(1,14,PSTR("THE ORDER THAT THEY COME."));
Print(1,15,PSTR("YOU CAN PLACE A PIPE ANY-"));
Print(1,16,PSTR("WHERE YOU LIKE WITH THE"));
Print(1,17,PSTR("BUTTON A."));
Print(1,19,PSTR("YOU CAN 'BLAST' A PREVIOUSLY"));
Print(1,20,PSTR("PLAYED PIECE BY PLACING A"));
Print(1,21,PSTR("NEW PIECE ON TOP OF IT."));
Print(1,22,PSTR("SPECIAL PIPE PIECES (GREY)"));
Print(1,23,PSTR("MAY NOT BE 'BLASTED'."));
Print(8,26,PSTR("PRESS ANY KEY"));
#ifdef _Fading
FadeIn(1, true);
#endif
break;
case PM_Help_Screen3:
// help screen 3
// pipes additional information
//clear screen with fade
#ifdef _Fading
FadeOut(1, true);
#endif
ClearVram();
Fill(0,0,30,28,1);
Print(8,1,PSTR("HELP - PAGE 3/4"));
Print(1, 3,PSTR("THE DIST(ANCE) COUNTER IN"));
Print(1, 4,PSTR("THE UPPER RIGHT OF THE"));
Print(1, 5,PSTR("SCREEN SHOWS THE REMAINING"));
Print(1, 6,PSTR("NUMBER OF PIPE PIECES TO BE"));
Print(1, 7,PSTR("FILLED TO REACH MINIMUM"));
Print(1, 8,PSTR("DISTANCE."));
Print(1,10,PSTR("IF YOU DO NOT REACH MINIMUM"));
Print(1,11,PSTR("DISTANCE, YOU WILL LOSE A"));
Print(1,12,PSTR("WRENCH. YOU WILL HAVE A"));
Print(1,13,PSTR("TOTAL OF THREE WRENCHES."));
Print(1,14,PSTR("WHEN THEY ARE GONE, THE GAME"));
Print(1,15,PSTR("GAME IS OVER."));
Print(1,17,PSTR("USE CROSS PIECES WISELY."));
Print(1,18,PSTR("EACH ONE CAN DELIVER EXTRA"));
Print(1,19,PSTR("POINTS. PUMPS WILL SPEED UP"));
Print(1,20,PSTR("THE FLOOZ FOR A FEW PIPE"));
Print(1,21,PSTR("SECTIONS. RESERVOIRS BRIEFLY"));
Print(1,22,PSTR("SLOW DOWN THE FLOOZ. TUNNELS"));
Print(1,23,PSTR("ALLOW YOU TO CONNECT YOUR."));
Print(1,24,PSTR("PIPES TO THE OPPOSITE SIDE."));
Print(8,26,PSTR("PRESS ANY KEY"));
#ifdef _Fading
FadeIn(1, true);
#endif
break;
case PM_Help_Screen4:
// help screen 4
// scoring
//clear screen with fade
#ifdef _Fading
FadeOut(1, true);
#endif
ClearVram();
Fill(0,0,30,28,1);
Print(8,1,PSTR("HELP - PAGE 4/4"));
Print(1, 3,PSTR("YOU WILL RECEIVE POINTS FOR"));
Print(1, 4,PSTR("THE FOLLOWING WHEN THE FLOOZ"));
Print(1, 5,PSTR("FLOW THROUGH THE PIPES:"));
Print(5, 7,PSTR("TYPE SCORE"));
Print(5, 8,PSTR("--------------------"));
Print(5, 9,PSTR("NORMAL PIPE 5"));
Print(5,10,PSTR("ONE-WAY PIPE 10"));
Print(5,11,PSTR("RESERVOIR 20"));
Print(5,12,PSTR("PUMP 100"));
Print(5,13,PSTR("TUNNEL 80"));
Print(5,14,PSTR("CROSS 5"));
Print(5,15,PSTR("CROSS LOOP 20"));
Print(5,16,PSTR("END PIECE *2"));
Print(1,18,PSTR("YOU WILL LOSE 5 POINTS FOR"));
Print(1,19,PSTR("EACH PIPE YOU 'BLAST'."));
Print(1,20,PSTR("AT THE END OF EACH ROUND,"));
Print(1,21,PSTR("YOU WILL LOSE 10 POINTS FOR"));
Print(1,22,PSTR("EACH PIPE ON THE PLAYFIELD"));
Print(1,23,PSTR("THAT THE FLOOZ DID NOT PASS"));
Print(1,24,PSTR("THROUGH."));
Print(8,26,PSTR("PRESS ANY KEY"));
#ifdef _Fading
FadeIn(1, true);
#endif
break;
case PM_Game_Start_Menu:
case PM_Game_Flow_Menu:
// save background under menu window
save_background(12,12,19,16);
msg_window(12,12,18,15,true,true);
Print(13,13,PSTR("BACK"));
Print(13,14,PSTR("MENU"));
// cursor
PrintChar(17,13,'$');
CUR_POS_GM = 0;
break;
case PM_HoF_view:
// show the hall of fame
//clear screen with fade
#ifdef _Fading
FadeOut(1, true);
#endif
ClearVram();
Fill(0,0,30,28,2);
msg_window(4,2,26,24,true,true);
// check and sort highscore for actual difficulty
PosY = check_highscore();