/
FACE.CPP
1831 lines (1563 loc) · 45.9 KB
/
FACE.CPP
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
/*-------------------------------------------------------*/
/* I N T E R F A C E */
/* */
/* [c]copyright 1995 by AlphaHelix */
/* */
/*-------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "DISKIO.HPP"
#include "ERROR.HPP"
#include "MEMORY.HPP"
#include "SDL_BASE.HPP"
#include "XLIB.HPP"
#include "INPUT.HPP"
#include "SOUND.HPP"
#include "RAVAGE.HPP"
#include "COMPATIBILITY.HPP"
/*---------------------------------------------------------
Function:
Description:
Display Intro & Title screen.
---------------------------------------------------------*/
void title(void)
{
void *f;
Font *tiny;
char *text;
int x, y;
int size = 0;
// Load needed font & picture.
tiny = new Font("fonts\\tiny.fnt");
f = loadfile("pic\\title.pcx", &size);
text = (char *) loadfile("stuff\\reg.txt", NULL);
// Fade out and draw new screen.
fadeout(FADE_PALETTE);
showpcx(f, 20, size);
// Print text.
x = 0; y = 140;
beauty(tiny, x, y, text);
// Fade in
fadein(NULL);
//input_wait(); input_fire(); input_wait();
SDL_Delay(1500);
fadeout(FADE_PALETTE);
//render.clear(0, 0, 0);
unloadfile(text);
unloadfile(f);
delete tiny;
}
/*---------------------------------------------------------
Function:
Description:
Custom MENU definitions.
---------------------------------------------------------*/
// Prototypes of custom menu functions.
static int a_main(int, int);
static int a_quit(int, int);
static int a_options(int, int);
static int a_stuff(int, int);
static int a_tooptions(int, int);
static int a_play1(int, int);
static int a_play2(int, int);
static int a_control(int, int);
static int a_key(int, int);
static int a_joy(int, int);
static int a_sound(int, int);
static int a_graphix(int, int);
static int a_load(int, int);
static int a_save(int, int);
static int a_shop(int, int);
// -
enum Control { END, HEAD, TEXT, STEXT, ADD, ADDSUB, YES, YESNO, UPDOWN, CUSTOM, NONE };
struct Menu {
Control type; // Control Type.
const char *sname; // File name of sprites.
Sprite *spr; // Set to 0.
int x, y; // Position.
int ys; // ?
char text[255]; // Text to display.
Back *back; // Placeholder (set to 0)
int (*action)(int, int);
int fast;
};
/*
The meaning of the parameters passed to the action function.
index : Which entry in the menu structure gets message.
subindex : Which subpart of entry "index".
Special values:
index == M_INIT: Initialize menu.
index == M_KEY: Key pressed message.
index == M_JOYPAD : JOYPAD message.
*/
static Menu mainmenu[] = {
{ CUSTOM,"pic\\main.spr",0,-1,10,8,"",0,a_main,0 },
{ END,"",0,0,0,0,"",0,a_main,0 }
};
static Menu playmenu1[] = {
{ HEAD, "", 0,0,0,0, "NEW GAME",0,0,0 },
{ CUSTOM, "pic\\players.spr",0,-1,55,14,"",0,a_play1,0 },
{ END,"",0,0,0,0,"",0,a_play1,0 }
};
static Menu playmenu2[] = {
{ HEAD, "", 0,0,0,0, "2 PLAYERS",0,0,0 },
{ CUSTOM, "pic\\dif.spr",0,-1,35,14,"",0,a_play2,0 },
{ END,"",0,0,0,0,"",0,a_play2,0 }
};
static Menu quitmenu[] = {
{ YESNO , "", 0, 0, 0, 0, "QUIT",0,a_quit,0 },
{ END, "", 0, 0, 0, 0, "",0,a_quit,0 }
};
static Menu optionmenu[] = {
{ HEAD, "", 0, 0, 0, 0, "OPTIONS",0,0,0 },
{ CUSTOM, "pic\\options.spr", 0, -1, 30, 8,"",0,a_options,0 },
{ YES, "", 0, 0, 0, 0, "Back To Main Menu",0,a_options,0 },
{ END, "", 0,0,0,0,"",0,a_options,0 }
};
static Menu stuffmenu[] = {
{ HEAD, "",0,0,0,0,"STUFF",0,0,0 },
{ CUSTOM, "pic\\stuff.spr",0,-1,30,8,"",0,a_stuff,0 },
{ YES, "",0,0,0,0,"Back To Main Menu",0,a_stuff,0 },
{ END, "",0,0,0,0,"",0,a_stuff,0 }
};
static Menu controlmenu[] = {
{ HEAD, "", 0,0,0,0,"CONTROLS",0,0,0 },
{ ADD, "",0,0,29,0,"",0,a_control,0 },
{ ADD, "",0,0,47,0,"",0,a_control,0 },
{ ADD, "",0,0,65,0,"",0,a_control,0 },
{ ADD, "",0,0,83,0,"",0,a_control,0 },
{ ADD, "",0,0,101,0,"",0,a_control,0 },
{ YES, "", 0, 0, 0, 0, "To Option Menu",0,a_tooptions,0 },
{ END, "",0,0,0,0,"",0,a_control,0 }
};
static Menu keymenu[] = {
{ HEAD, "", 0, 0, 0, 0, "KEYBOARD", 0,a_key,0 },
{ TEXT, "", 0, -1, 25, 12,"Press Key for Function",0,0,0 },
{ TEXT, "", 0, 5, 50, 15, "Left:",0,0,0 },
{ TEXT, "", 0, 5, 65, 15, "Right:",0,0,0 },
{ TEXT, "", 0, 5, 80, 15, "Up:",0,0,0 },
{ TEXT, "", 0, 5, 95, 15, "Down:",0,0,0 },
{ TEXT, "", 0, 5, 110, 15, "Fire:",0,0,0 },
{ END, "",0,0,0,0,"",0,a_key,0 }
};
/*static Menu joymenu[] = {
{ HEAD,"",0,0,0,0,"JOYPAD",0,a_joy,0 },
{ TEXT,"",0,-1,60,15,"Center Pad and Press Fire.",0,0,0 },
{ TEXT,"",0,-1,70,12,"ESC aborts.",0,0,0 },
{ END,"",0,0,0,0,"",0,a_joy,0 }
};*/
static Menu joymenu[] = {
{ HEAD, "", 0, 0, 0, 0, "JOYPAD", 0,a_joy,0 },
{ TEXT, "", 0, -1, 25, 12,"Press Button for Function",0,0,0 },
{ TEXT, "", 0, 5, 50, 15, "Left:",0,0,0 },
{ TEXT, "", 0, 5, 65, 15, "Right:",0,0,0 },
{ TEXT, "", 0, 5, 80, 15, "Up:",0,0,0 },
{ TEXT, "", 0, 5, 95, 15, "Down:",0,0,0 },
{ TEXT, "", 0, 5, 110, 15, "Fire:",0,0,0 },
{ END, "",0,0,0,0,"",0,a_joy,0 }
};
static Menu soundmenu[] = {
{ HEAD, "", 0,0,0,0,"SOUND",0,0,0 },
{ ADDSUB, "",0,0,40,0,"",0,a_sound,1 },
{ ADDSUB, "",0,0,60,0,"",0,a_sound,1 },
{ ADD, "",0,0,80,0,"",0,a_sound,0 },
{ NONE, "",0,0,100,0,"",0,a_sound,1 },
{ YES, "", 0, 0, 0, 0, "To Option Menu",0,a_tooptions,0 },
{ END, "",0,0,0,0,"",0,a_sound,0 }
};
static Menu graphixmenu[] = {
{ HEAD, "", 0,0,0,0,"GRAPHICS",0,0,0 },
{ ADD, "",0,0,35,0,"",0,a_graphix,0 },
{ ADD, "",0,0,55,0,"",0,a_graphix,0 },
// { ADD, "",0,0,75,0,"",0,a_graphix,0 },
{ YES, "", 0, 0, 0, 0, "To Option Menu",0,a_tooptions,0 },
{ END, "",0,0,0,0,"",0,a_graphix,0 }
};
static Menu loadmenu[] = {
{ HEAD, "",0,0,0,0,"LOAD GAME",0,0,0 },
{ TEXT, "",0,-1,25,12,"Select Game to Load.",0,0,0 },
{ ADD, "",0,0,50,0,"",0,a_load,0 },
{ ADD, "",0,0,73,0,"",0,a_load,0 },
{ ADD, "",0,0,96,0,"",0,a_load,0 },
{ YES, "",0,0,0,0, "Back to Main Menu",0,a_load,0 },
{ END, "",0,0,0,0,"",0,a_load,0 }
};
static Menu savemenu[] = {
{ HEAD, "",0,0,0,0,"SAVE GAME",0,0,0 },
{ TEXT, "",0,-1,25,12,"Select Slot to Save Game to.",0,0,0 },
{ ADD, "",0,0,50,0,"",0,a_save,0 },
{ ADD, "",0,0,73,0,"",0,a_save,0 },
{ ADD, "",0,0,96,0,"",0,a_save,0 },
{ YES, "",0,0,0,0, "Back to Shop",0,a_save,0 },
{ END, "",0,0,0,0,"",0,a_save,0 }
};
static Menu shopmenu[] = {
{ HEAD, "",0,0,0,0, "PLAYER 1",0,0,0 }, // Must be element 0.
{ STEXT,"",0,0,22,0,"",0,0,0 },
{ ADDSUB, "",0,0,37,0,"",0,a_shop,0 },
{ ADDSUB, "",0,0,59,0,"",0,a_shop,0 },
{ ADDSUB, "",0,0,81,0,"",0,a_shop,0 },
{ UPDOWN, "",0,0,103,0,"",0,a_shop,0 },
{ CUSTOM, "pic\\save.spr",0,16,103,0,"",0,a_shop,0 },
{ YES, "",0,0,0,0, "Play Next Level",0,a_shop,0 },
{ END, "",0,0,0,0,"",0,a_shop,0 }
};
/*---------------------------------------------------------
Function Group: Menu Functions
Description:
These are functions to build and manage the various MENUs.
A menu is made of an array of Menu structures.
Each entry in the array defines another button, text or
whatsoever. A custom function is linked to all the buttons
which is being executed on a button PRESS event.
---------------------------------------------------------*/
#define DEMOX 0
#define DEMOY 0
#define DEMOXS 144 // x size of demo screen
#define DEMOYS YMAX //
#define MENUX (DEMOX+DEMOXS+6)
#define MENUY 90
#define MENUXS (XMAX-MENUX)
#define MENUYS (YMAX-MENUY)
#define MENUX1 (MENUX+MENUXS-1)
#define MENUY1 (MENUY+MENUYS-1)
// Events.
#define M_INIT 99 // Initialize menu.
#define M_KEY 98 // Key has been pressed.
#define M_JOYPAD 97 // Joystick event.
static int nowplayer; // Active player for current menu.
static GameState gsave;
static PlayerState psave; // State save for active player.
static PlayerState psave2; // State save for player not active in DEMO.
static int cheatsave; // Back up variable for cheatvalue.
static Back *menuback; // Saved menu screen back ground.
static SDLTexture demoTexture; // The texture the game demo is rendered to.
static Sprite *head; // Part of Title.
static SDLSprite sHead;
static Sprite *pointer; // Mouse pointer.
static SDLSprite sPointer;
static Back *back; // Pointer background.
static Font *blue; // Big Blue font.
static Font *tiny; // Tiny font. Used everywhere.
static Sprite *addsub; // Add/Sub buttons.
static SDLSprite sAddSub;
static Sprite *yesno; // Yes/No buttons.
static SDLSprite sYesNo;
static Menu *nowmenu; // Which menu is active now.
// Backoff menu. This menu will be built, if user presses ESC.
static Menu *backoff;
static int pointer_enabled; // RW: 1 if menu cursor is disabled.
static int keys_enabled; // RW: 1 if key events are welcome.
static int joy_enabled; // RW: 1 if joypad event are enabled.
//-------------------------------------------------------------------
// Button stuff.
//-------------------------------------------------------------------
// Button definition structure.
class Button {
int x, y; // x,y of button.
int xs, ys;
Sprite *spr; // Sprite representing this button.
SDLSprite sSpr;
int n; // Sprite frame used to display released button.
int index; // Return this value if button was pressed.
Button *next;
public:
Button(int dx, int dy, Sprite *sprite, int dn, int idx);
void up(void) { render.x_drawsprite(&sSpr, x, y, n); }
void down(void) { render.x_drawsprite(&sSpr, x, y, n + 1); }
friend Button *checkbuttons(int x0, int y0, int &index, int &subindex);
friend void destroybuttons(void);
friend void clearmenu(void);
};
static Button *anchor = 0; //Head of a list of buttons
Button::Button(int dx, int dy, Sprite *sprite, int dn, int idx)
{
x = dx; y = dy;
spr = sprite;
sSpr.load(sprite, false);
xs = spr->xs; ys = spr->ys;
n = dn*2;
index = idx;
up();
if (anchor) next = anchor; else next = 0;
anchor = this;
}
void destroybuttons(void)
{
Button *keep;
while (anchor) {
keep = anchor->next;
anchor->sSpr.destroy();
delete anchor;
anchor = keep;
}
}
// Check mouse coordinates and return number of button mouse hits.
Button *checkbuttons(int x0, int y0, int &index, int &subindex)
{
Button *b = anchor;
int dx, dy;
if (!b) {
index = -1;
return 0;
}
do {
dx = x0 - b->x; dy = y0 - b->y;
if ((dx >= 0) && (dy >= 0)) {
if ((dx < b->xs) && (dy < b->ys)) {
index = b->index; subindex = b->n / 2;
return b;
}
}
} while ((b = b->next));
index = -1;
return 0;
}
/*---------------------------------------------------------
Function group: MENUS
Description:
Build the MENU screen.
Play game demo & ask player: What's next ?
---------------------------------------------------------*/
static void addtext1(Menu &menu, const char *text1, const char *text2)
{
int x, y;
menu.back->restore();
x = MENUX + 2;
y = MENUY + menu.y + (addsub->ys-tiny->height()) / 2;
tiny->vanilla(x, y, text1, 15);
x += tiny->textlen(text1);
tiny->vanilla(x, y, text2, 12);
}
static void addtext2(Menu &menu, const char *text1, const char *text2)
{
int x, y;
menu.back->restore();
x = MENUX + 2;
y = MENUY + menu.y + (addsub->ys)/2 - tiny->height() - 1;
tiny->vanilla(x, y, text1, 15);
y += tiny->height() + 1;
tiny->vanilla(x, y, text2, 12);
}
static void addtext1dn(int x, Menu &menu, const char *text1, int color)
{
int y;
y = MENUY + menu.y + (addsub->ys)/2;
tiny->vanilla(x+MENUX, y, text1, color);
}
static void destroymenu(void)
{
if (!nowmenu) return;
destroybuttons();
while (nowmenu->type != END) {
if (nowmenu->spr) unloadfile(nowmenu->spr);
if (nowmenu->back) delete nowmenu->back;
nowmenu++;
}
menuback->restore();
}
void clearmenu(void)
{
void *f;
int size = 0;
Button *b = anchor;
f = loadfile("pic\\themenu.pcx", &size);
showpcx(f, 0, size);
unloadfile(f);
if (!b) {
return;
}
do {
b->up();
} while ((b = b->next));
return;
}
static void buildmenu(Menu *menu)
{
int index;
int x, y;
int i, n;
destroymenu();
nowmenu = menu;
// Set event handling to default.
pointer_enabled = 1;
keys_enabled = 0;
joy_enabled = 0;
index = 0;
do {
switch (menu->type) {
case HEAD:
blue->print_c(MENUX+(MENUXS+BORDER)/2, MENUY+menu->y, menu->text);
break;
case TEXT:
if (menu->x == -1)
tiny->vanilla_c(MENUX+(MENUXS+BORDER)/2, MENUY + menu->y, menu->text, menu->ys);
else
tiny->vanilla(MENUX + menu->x, MENUY + menu->y, menu->text, menu->ys);
break;
case STEXT:
y = tiny->height() + 1;
menu->back = new Back(MENUX1-7-MENUX, y);
menu->back->save(MENUX, MENUY+menu->y);
break;
case ADD:
y = tiny->height()*2 + 1;
menu->back = new Back(MENUX1-23-MENUX, y);
y = (addsub->ys - y) / 2;
new Button(MENUX1-21, MENUY+menu->y, addsub, 0, index);
anchor->up();
menu->back->save(MENUX, MENUY+menu->y+y-1);
anchor->up();
break;
case ADDSUB:
y = tiny->height()*2 + 1;
menu->back = new Back(MENUX1-27-MENUX, y);
y = (addsub->ys - y) / 2;
new Button(MENUX1-45, MENUY+menu->y, addsub, 0, index);
new Button(MENUX1-21, MENUY+menu->y, addsub, 1, index);
menu->back->save(MENUX, MENUY+menu->y+y-1);
break;
case YESNO:
blue->print_c(MENUX+(MENUXS+BORDER)/2, 180, menu->text);
new Button(MENUX+20, 205, yesno, 0, index);
new Button(XMAX-10-yesno->xs, 205, yesno, 1, index);
anchor->up();
break;
case YES:
new Button(XMAX-yesno->xs, 215, yesno, 0, index);
tiny->vanilla(XMAX-yesno->xs-tiny->textlen(menu->text)-10,
215+(yesno->ys-tiny->height())/2,
menu->text, 15);
break;
case UPDOWN:
menu->spr = (Sprite *)loadfile("pic\\updown.spr", NULL);
new Button(242, MENUY+menu->y, menu->spr, 0, index);
new Button(266, MENUY+menu->y, menu->spr, 1, index);
break;
case CUSTOM:
menu->spr = (Sprite *)loadfile(menu->sname, NULL);
n = menu->spr->frames / 2;
if (menu->x == -1)
x = MENUX + (MENUXS+BORDER-menu->spr->xs)/2;
else
x = MENUX + menu->x;
y = MENUY + menu->y;
for (i = 0; i < n; i++) {
new Button(x, y, menu->spr, i, index);
y += menu->ys + menu->spr->ys;
anchor->up();
}
break;
case END:
menu->action(M_INIT, 0);
break;
case NONE:
break;
}
if (menu->type == END) break;
menu++; index++;
} while (1);
back->invalidate();
}
/*---------------------------------------------------------
Function:
Description:
Operate menu.
Check if mouse is pressing a button and execute
"action function" on a press.
Return values:
0 : everything is allright. Go ahead.
1 : play game
2 : quit game
---------------------------------------------------------*/
int checkmenu(int mb, int x, int y)
{
static Button *last;
Button *now;
static int lindex;
static int lsindex;
int index, subindex;
int ret;
// Set up.
if (mb == -1) {
last = 0;
lindex = -1;
ret = 1;
return -1;
}
ret = 0;
if (mb) {
now = checkbuttons(x, y, index, subindex);
} else {
now = 0;
index = -1;
}
if (last) last->up();
if (now) now->down();
last = now;
if (lindex != -1) if (nowmenu[lindex].action) {
if (nowmenu[lindex].fast) ret = nowmenu[lindex].action(lindex, lsindex);
else if (!mb) {
ret = nowmenu[lindex].action(lindex, lsindex);
}
}
lindex = index;
lsindex = subindex;
return ret;
}
//-------------------------------------------------------------------
// Play one frame of the DEMO GAME.
void demo(void)
{
int dx, dy, fire;
newwave();
enemystep();
s_update();
player[nowplayer].control(dx, dy, fire);
weaponstep(nowplayer, dx * SHIPSPEED, dy * SHIPSPEED, fire);
crash(nowplayer);
if (gstate.frame < layerlength(1)) {
gstate.frame++;
movelayer(0, gstate.frame & 1);
movelayer(1, 1);
} else {
movelayer(0, 0); movelayer(1, 0);
}
//Draw game to demo texture
render.setTarget(&demoTexture);
process_objects();
drawscreen();
postprocess_objects();
render.setTarget(NULL);
}
static void initmenu(void)
{
// Allocate Menu Background backup.
menuback = new Back(MENUXS, MENUYS);
// Load menu screen.
demoTexture.loadPointer(SDL_CreateTexture(render.getBase(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, HWXMAX, YMAX), true);
clearmenu();
// Take a snapshot of the plain menu screen.
menuback->save(MENUX, MENUY);
// .. freeze overlapping part of Title.
head = (Sprite *)loadfile("pic\\ravage.spr", NULL);
sHead.load(head, false);
// Load pointer.
pointer = (Sprite *)loadfile("pic\\pointer.spr", NULL);
sPointer.load(pointer, false);
// Set mouse area.
//setmouselimits(MENUX, MENUY, MENUX+MENUXS-pointer->xs, MENUY+MENUYS-pointer->ys);
setmouselimits(-BORDER, 0, 320, 240);
// Initialize POINTER animation buffer.
back = new Back(pointer->xs, pointer->ys);
// Set events to initial values.
pointer_enabled = 1;
keys_enabled = 0;
joy_enabled = 0;
// Several buttons & fonts.
blue = new Font("fonts\\blue.fnt");
tiny = new Font("fonts\\tiny.fnt");
addsub = (Sprite *)loadfile("pic\\addsub.spr", NULL);
sAddSub.load(addsub, false);
yesno = (Sprite *)loadfile("pic\\yesno.spr", NULL);
sYesNo.load(yesno, false);
// Write version information.
#ifdef SHAREWARE
tiny->vanilla(215, 65, "shareware 1.1", 10);
#else
tiny->vanilla(215, 65, "registered 1.1", 10);
#endif
// Save current game state in case the menu is in SHOP mode.
gsave = gstate;
psave = player[nowplayer];
psave2 = player[1-nowplayer];
player[1-nowplayer].active = 0; // Deactivate unused player.
// Initialize DEMO GAME.
cheatsave = cheatlevel;
cheatlevel |= CHEAT_INVUL | CHEAT_NOMONEY;
playback_start("demo1\\demo1.rec");
player[nowplayer].control = playback_device;
gstate.nplayers = 1; gstate.difficulty = 3;
newgame(1);
newlevel("demo1\\demo1");
weapon_releaseall(nowplayer, STARTX1, STARTY);
// Start playing background music.
s_loadmod("mods\\menu.uni");
s_startmod();
// Fade In
fadein(level.palette);
}
static void shutmenu(void)
{
fadeout(FADE_ALL);
s_unloadmod();
// Housekeeping.
weapon_removeall(nowplayer);
shutlevel();
shutgame();
playback_stop();
cheatlevel = cheatsave;
// Restore Previous Saved Game State.
gstate = gsave;
player[nowplayer] = psave;
player[1-nowplayer] = psave2;
// release resources.
unloadfile(yesno);
sYesNo.destroy();
unloadfile(addsub);
sAddSub.destroy();
delete tiny;
delete blue;
delete back;
unloadfile(pointer);
sPointer.destroy();
unloadfile(head);
sHead.destroy();
demoTexture.destroy();
delete menuback;
}
static void testlimits(int &x, int &y)
{
if (x < -BORDER) x = -BORDER;
if (x > HWXMAX-pointer->xs) x = HWXMAX-pointer->xs;
if (y < 0) y = 0;
if (y > HWYMAX+BORDER-pointer->ys) y = HWYMAX+BORDER-pointer->ys;
}
/*---------------------------------------------------------
Function: menu
Description:
Build and manage menu.
mode : Menu mode (MAINMENU or SHOPMENU).
p : Build menu for PLAYER p. (Especially important for SHOPMENU)
---------------------------------------------------------*/
int menu(int mode, int p)
{
int dx, dy, db; // Accumulated cursor coordinates.
int mb;
int joy_x, joy_y, joy_fire; // Joystick values.
int x, y, b; // Mouse coordinates.
int request;
static int key_allowed;
Uint32 startTime = 0;
// Initialize menu system.
nowplayer = p;
initmenu();
nowmenu = 0; // No menu active at the moment.
strcpy(shopmenu[0].text, p ? "PLAYER 2" : "PLAYER 1");
switch (mode) {
case MAINMENU: buildmenu(mainmenu); break;
case SOUNDMENU: buildmenu(soundmenu); break;
case SHOPMENU: buildmenu(shopmenu); break;
}
// Initialize some variables.
joy_x = joy_y = joy_fire = 0;
// Initialize "checkmenu".
checkmenu(-1, 0, 0);
x = MENUX + MENUXS/2;
y = MENUY + MENUYS/2;
do {
startTime = SDL_GetTicks();
demo();
// Restore mouse pointer background.
dx = dy = mb = b = 0;
input_update();
if (joypad) {
getjoypad(joy_x, joy_y, joy_fire);
x += joy_x*4; y += joy_y*4; b += joy_fire;
}
getkeyboard(dx, dy, db); x += dx*4; y += dy*4; b += db;
if (mouse && !(dx || dy)) {
getmouse(dx, dy, mb);
if((dx || dy))
getmousexy(mb, x, y);
b += mb;
}
testlimits(x, y);
//if (mouse) setmousexy(x, y);
back->restore();
// Process events.
if (!keys) key_allowed = 1;
if (!keys_enabled) key_released = 0;
// Send KEY PRESSED message to menu.
if (!keys && key_released && key_released!=KEY_ESC) {
if (nowmenu[0].action) nowmenu[0].action(M_KEY, key_released);
key_released = 0;
}
// Send joypad messages.
if (joy_enabled && button_released != -1) {
if (nowmenu[0].action) nowmenu[0].action(M_JOYPAD, button_released);
}
// Send mouse messages.
if (pointer_enabled) {
if (request = checkmenu(b, x, y)) break;
}
// Build backoff menu if ESC has been pressed.
if (key_allowed && key[KEY_ESC] && backoff) {
buildmenu(backoff);
key_allowed = 0;
escape_wait();
}
back->save(x, y);
// Copy demo display to restricted area of screen
render.drawTexture(&demoTexture, BORDER, 0, 16, 0, 4*32 + 16, YMAX);
// Restore title logo.
render.x_drawsprite(&sHead, 100, 12, 0);
if (pointer_enabled) render.x_drawsprite(&sPointer, x, y, 0);
render.update();
while(SDL_GetTicks() - startTime < 32)
{
SDL_Delay(1);
}
} while (!quit_requested);
destroymenu();
// Shut down menu system.
shutmenu();
return quit_requested ? M_QUIT : request;
}
/*---------------------------------------------------------
Function:
Description:
---------------------------------------------------------*/
// Custom stuff.
//#pragma off (unreferenced)
static const char *stext[3] = { "None", "Some", "All" };
static const char *mtext[3] = { "Low", "Medium", "High" };
static const char *screenText[4] = { "Standard", "Fuzzy", "Warm", "Warm and Fuzzy" };
static int sfreq_now;
static int sfreq[4] = { 11025, 22050, 44100, 99999 };
static int nplayers;
static void showpicture(char *file)
{
void *f;
int size = 0;
SDLTexture *restore;
restore = render.createScreenTexture();
f = loadfile(file, &size);
fadeout(FADE_PALETTE);
render.clear(0, 0, 0);
showpcx(f, 0, size);
unloadfile(f);
fadein(NULL);
input_wait(); input_fire(); input_wait();
fadeout(FADE_PALETTE);
render.drawTexture(restore, 0, 0);
fadein(level.palette);
restore->destroy();
delete restore;
}
static void order(void)
{
void *f;
char *text;
int x, y;
int size = 0;
SDLTexture *restore = NULL;
restore = render.createScreenTexture();
f = loadfile("pic\\order.pcx", &size);
text = (char *)loadfile("stuff\\order1.txt", NULL);
fadeout(FADE_PALETTE);
render.clear(0, 0, 0);
showpcx(f, 20, size);
blue->print_c(XMAX/2, 0, "ORDER RAVAGE NOW");
x = 0; y = 30;
beauty(tiny, x, y, text);
unloadfile(text);
fadein(NULL);
input_wait(); input_fire(); input_wait();
fadeout(FADE_PALETTE);
text = (char *)loadfile("stuff\\order2.txt", NULL);
render.clear(0, 0, 0);
showpcx(f, 20, size);
blue->print_c(XMAX/2, 0, "HOW TO ORDER");
x = 0; y = 30;
beauty(tiny, x, y, text);
unloadfile(text);
fadein(NULL);
unloadfile(f);
input_wait(); input_fire(); input_wait();
fadeout(FADE_PALETTE);
render.drawTexture(restore, 0, 0);
fadein(level.palette);
restore->destroy();
delete restore;
}
static int a_main(int index, int subindex)
{
// Initialize menu.
if (index == M_INIT) {
backoff = quitmenu;
return 0;
}
switch (subindex) {
case 0: // Play
buildmenu(playmenu1);
break;
case 1: // Load game
buildmenu(loadmenu);
break;
case 2: // Option menu
buildmenu(optionmenu);
break;
case 3: // Stuff
buildmenu(stuffmenu);
break;
case 4: // Quit already ?
buildmenu(quitmenu);
break;
}
return 0;
}
static int a_quit(int index, int subindex)
{
// Initialize menu.
if (index == M_INIT) {
backoff = mainmenu;
return 0;
}
// Action part.
if (subindex==1) {
buildmenu(mainmenu);
return 0;
} else {
return M_QUIT;
}
}
static int a_options(int index, int subindex)
{
if (index == M_INIT) {
backoff = mainmenu;