-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathsetup.c
1319 lines (1192 loc) · 49.1 KB
/
setup.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
#include <libdragon.h>
#include <math.h>
#include "setup.h"
#include "core.h"
#include "minigame.h"
#include "results.h"
#include "menu.h"
#include "savestate.h"
/*=============================================================
=============================================================*/
#define POPTIME 0.4f
#define BLOCKSIZE 16
#define BLOCKSW (320/BLOCKSIZE)
#define BLOCKSH (240/BLOCKSIZE)
#define RECTCORNERDIST (BLOCKSIZE/1.41421356237)
#define FONTDEF_LARGE 1
#define FONTDEF_XLARGE 2
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
/*=============================================================
=============================================================*/
typedef enum {
MENU_START,
MENU_MODE,
MENU_PLAYERS,
MENU_AIDIFF,
MENU_GAMESETUP,
MENU_BLACKLIST,
MENU_DONE,
} CurrentMenu;
typedef enum {
TRANS_NONE,
TRANS_FORWARD,
TRANS_BACKWARD,
} Transition;
/*=============================================================
=============================================================*/
typedef struct {
float h; // Angle (in degrees)
float s; // 0 - 1
float v; // 0 - 1
} hsv_t;
typedef struct {
sprite_t* boxcorner;
sprite_t* boxedge;
sprite_t* boxback;
surface_t boxedgesurface;
surface_t boxbacksurface;
int cornersize;
} BoxSpriteDef;
typedef struct {
float w;
float h;
float x;
float y;
BoxSpriteDef spr;
} BoxDef;
/*=============================================================
=============================================================*/
static Transition global_transition;
static CurrentMenu global_curmenu;
static int global_selection;
static bool global_playerjoined[MAXPLAYERS];
static float global_readyprog;
static bool global_cursoractive;
static float global_cursory;
static float global_stickcooldown;
static int global_cfg_points;
static NextRound global_cfg_nextround;
static bool* global_cfg_blacklist;
static float global_fadetime;
static float global_backtime;
static float global_rotsel1;
static float global_rotsel2;
static float global_rotcursor;
static BoxSpriteDef sprdef_backbox;
static BoxSpriteDef sprdef_button;
static BoxDef* bdef_backbox_mode;
static BoxDef* bdef_backbox_plycount;
static BoxDef* bdef_backbox_aidiff;
static BoxDef* bdef_backbox_gameconfig;
static BoxDef* bdef_backbox_blacklist;
static BoxDef* bdef_button_freeplay;
static BoxDef* bdef_button_compete;
static sprite_t* spr_toybox;
static sprite_t* spr_trophy;
static sprite_t* spr_pointer;
static sprite_t* spr_robot;
static sprite_t* spr_player;
static sprite_t* spr_start;
static sprite_t* spr_a;
static sprite_t* spr_progress;
static sprite_t* spr_circlemask;
static sprite_t* spr_tick;
static sprite_t* spr_cross;
static rdpq_font_t* global_font1;
static rdpq_font_t* global_font2;
static wav64_t sfx_cursor;
static wav64_t sfx_confirm;
static wav64_t sfx_back;
static wav64_t sfx_join;
static wav64_t sfx_leave;
static xm64player_t global_music;
/*=============================================================
=============================================================*/
static void setup_draw(float deltatime);
static void drawbox(BoxDef* bd, color_t col);
static void drawprogress(int x, int y, color_t col);
static void culledges(BoxDef* back);
static void uncull(void);
static bool is_menuvisible(CurrentMenu menu);
static bool controller_isleft();
static bool controller_isright();
static bool controller_isup();
static bool controller_isdown();
static bool controller_isa();
static bool controller_isb();
static bool controller_isaheld();
static bool controller_isstartheld();
static void play_cursor_sfx();
static void play_confirm_sfx();
static void play_back_sfx();
/*=============================================================
=============================================================*/
static inline float lerp(float from, float to, float frac)
{
return from + (to - from)*frac;
}
static float elasticlerp(float from, float to, float frac)
{
const float c4 = (2*M_PI)/3;
if (frac <= 0)
return from;
if (frac >= 1)
return to;
const float ease = pow(2, -8.0f*frac)*sin((frac*8.0f - 0.75f)*c4) + 1;
return from + (to - from)*ease;
}
static float deglerp(float from, float to, float frac)
{
float delta = to - from;
if (delta > 180)
from += 360;
else if (delta < -180)
from -= 360;
from = lerp(from, to, frac);
if (from < 0)
from += 360;
return from;
}
static float clamp(float val, float min, float max)
{
if (val < min)
return min;
if (val > max)
return max;
return val;
}
static hsv_t rgb2hsv(color_t rgb)
{
hsv_t ret = {0, 0, 0};
const float r = ((float)rgb.r)/255.0f;
const float g = ((float)rgb.g)/255.0f;
const float b = ((float)rgb.b)/255.0f;
const float max = fmaxf(fmaxf(r, g), b);
const float min = fminf(fminf(r, g), b);
const float c = max - min;
// Get value
ret.v = max;
// Get saturation
if (ret.v != 0)
ret.s = c/max;
// Get hue
if (c != 0)
{
if (max == r)
ret.h = ((g - b)/c) + 0;
else if (max == g)
ret.h = ((b - r)/c) + 2;
else
ret.h = ((r - g)/c) + 4;
ret.h *= 60;
if (ret.h < 0)
ret.h += 360;
}
return ret;
}
static color_t hsv2rgb(hsv_t hsv)
{
float r, g, b;
color_t ret = {0, 0, 0, 255};
float h = hsv.h/360;
int i = h*6;
float f = h * 6 - i;
float p = hsv.v*(1 - hsv.s);
float q = hsv.v*(1 - f*hsv.s);
float t = hsv.v*(1 - (1 - f)*hsv.s);
switch (i % 6)
{
case 0: r = hsv.v; g = t; b = p; break;
case 1: r = q; g = hsv.v; b = p; break;
case 2: r = p; g = hsv.v; b = t; break;
case 3: r = p; g = q; b = hsv.v; break;
case 4: r = t; g = p; b = hsv.v; break;
default:r = hsv.v; g = p; b = q; break;
}
ret.r = r*255;
ret.g = g*255;
ret.b = b*255;
return ret;
}
static color_t lerpcolor(color_t from, color_t to, float frac)
{
hsv_t result;
hsv_t hsv_from = rgb2hsv(from);
hsv_t hsv_to = rgb2hsv(to);
result.h = deglerp(hsv_from.h, hsv_to.h, frac);
result.s = lerp(hsv_from.s, hsv_to.s, frac);
result.v = lerp(hsv_from.v, hsv_to.v, frac);
return hsv2rgb(result);
}
/*=============================================================
=============================================================*/
void setup_init()
{
const color_t plyclrs[] = {
PLAYERCOLOR_1,
PLAYERCOLOR_2,
PLAYERCOLOR_3,
PLAYERCOLOR_4,
};
global_selection = 0;
global_transition = TRANS_FORWARD;
global_curmenu = MENU_START;
global_cursoractive = false;
global_stickcooldown = 0;
for (int i=0; i<MAXPLAYERS; i++)
global_playerjoined[i] = false;
global_backtime = 0;
global_fadetime = 0;
global_cursory = 0;
global_rotsel1 = 0;
global_rotsel2 = 0;
global_rotcursor = 0;
global_readyprog = 0;
display_init(RESOLUTION_320x240, DEPTH_16_BPP, 3, GAMMA_NONE, FILTERS_RESAMPLE);
global_cfg_points = 4;
global_cfg_nextround = NR_LEAST;
global_cfg_blacklist = (bool*)malloc(sizeof(bool)*global_minigame_count);
savestate_getblacklist(global_cfg_blacklist);
bdef_backbox_mode = (BoxDef*)malloc(sizeof(BoxDef));
bdef_backbox_plycount = (BoxDef*)malloc(sizeof(BoxDef));
bdef_backbox_gameconfig = (BoxDef*)malloc(sizeof(BoxDef));
bdef_backbox_aidiff = (BoxDef*)malloc(sizeof(BoxDef));
bdef_backbox_blacklist = (BoxDef*)malloc(sizeof(BoxDef));
bdef_button_freeplay = (BoxDef*)malloc(sizeof(BoxDef));
bdef_button_compete = (BoxDef*)malloc(sizeof(BoxDef));
spr_toybox = sprite_load("rom:/core/ToyBox.rgba32.sprite");
spr_trophy = sprite_load("rom:/core/Trophy.rgba32.sprite");
spr_pointer = sprite_load("rom:/core/Pointer.rgba32.sprite");
spr_player = sprite_load("rom:/core/Controller.rgba32.sprite");
spr_robot = sprite_load("rom:/core/Robot.rgba32.sprite");
spr_tick = sprite_load("rom:/core/Tick.rgba32.sprite");
spr_cross = sprite_load("rom:/core/Cross.rgba32.sprite");
spr_start = sprite_load("rom:/core/StartButton.sprite");
spr_a = sprite_load("rom:/core/AButton.sprite");
spr_progress = sprite_load("rom:/core/CircleProgress.i8.sprite");
spr_circlemask = sprite_load("rom:/core/CircleMask.i8.sprite");
global_font1 = rdpq_font_load("rom:/squarewave_l.font64");
global_font2 = rdpq_font_load("rom:/squarewave_xl.font64");
rdpq_text_register_font(FONTDEF_LARGE, global_font1);
rdpq_text_register_font(FONTDEF_XLARGE, global_font2);
rdpq_font_style(global_font1, 1, &(rdpq_fontstyle_t){.color = RGBA32(255, 255, 255, 255)});
rdpq_font_style(global_font2, 1, &(rdpq_fontstyle_t){.color = RGBA32(255, 255, 255, 255)});
rdpq_font_style(global_font1, 2, &(rdpq_fontstyle_t){.color = RGBA32(148, 145, 8, 255)}); // Do not use hard yellow due to Tritanopia
for (int i=0; i<MAXPLAYERS; i++)
rdpq_font_style(global_font1, 3+i, &(rdpq_fontstyle_t){.color = plyclrs[i]});
sprdef_backbox.boxcorner = sprite_load("rom:/core/Box_Corner.rgba32.sprite");
sprdef_backbox.boxedge = sprite_load("rom:/core/Box_Edge.rgba32.sprite");
sprdef_backbox.boxback = sprite_load("rom:/pattern.i8.sprite");
sprdef_backbox.boxedgesurface = sprite_get_pixels(sprdef_backbox.boxedge);
sprdef_backbox.boxbacksurface = sprite_get_pixels(sprdef_backbox.boxback);
sprdef_backbox.cornersize = 16;
sprdef_button.boxcorner = sprite_load("rom:/core/Box2_Corner.rgba32.sprite");
sprdef_button.boxedge = sprite_load("rom:/core/Box2_Edge.rgba32.sprite");
sprdef_button.boxback = sprite_load("rom:/core/Box_Back.rgba32.sprite");
sprdef_button.boxedgesurface = sprite_get_pixels(sprdef_button.boxedge);
sprdef_button.boxbacksurface = sprite_get_pixels(sprdef_button.boxback);
sprdef_button.cornersize = 8;
wav64_open(&sfx_cursor, "rom:/core/cursor.wav64");
wav64_open(&sfx_confirm, "rom:/core/menu_confirm.wav64");
wav64_open(&sfx_back, "rom:/core/menu_back.wav64");
wav64_open(&sfx_join, "rom:/core/player_join.wav64");
wav64_open(&sfx_leave, "rom:/core/player_leave.wav64");
xm64player_open(&global_music, "rom:/core/Menus.xm64");
xm64player_seek(&global_music, 27, 0, 0);
xm64player_set_vol(&global_music, 0.0f);
xm64player_play(&global_music, 0);
bdef_backbox_mode->w = 0;
bdef_backbox_mode->h = 0;
bdef_backbox_mode->x = 320/2;
bdef_backbox_mode->y = 240/2;
bdef_backbox_mode->spr = sprdef_backbox;
bdef_backbox_plycount->w = 280;
bdef_backbox_plycount->h = 200;
bdef_backbox_plycount->x = bdef_backbox_plycount->w*2;
bdef_backbox_plycount->y = 240/2;
bdef_backbox_plycount->spr = sprdef_backbox;
bdef_backbox_aidiff->w = 0;
bdef_backbox_aidiff->h = 0;
bdef_backbox_aidiff->x = 320/2;
bdef_backbox_aidiff->y = 240/2;
bdef_backbox_aidiff->spr = sprdef_button;
bdef_backbox_gameconfig->w = 280;
bdef_backbox_gameconfig->h = 200;
bdef_backbox_gameconfig->x = bdef_backbox_gameconfig->w*2;
bdef_backbox_gameconfig->y = 240/2;
bdef_backbox_gameconfig->spr = sprdef_backbox;
bdef_backbox_blacklist->w = 0;
bdef_backbox_blacklist->h = 0;
bdef_backbox_blacklist->x = 320/2;
bdef_backbox_blacklist->y = 240/2;
bdef_backbox_blacklist->spr = sprdef_button;
bdef_button_freeplay->x = 0;
bdef_button_freeplay->y = 0;
bdef_button_freeplay->w = 128;
bdef_button_freeplay->h = 40;
bdef_button_freeplay->spr = sprdef_button;
bdef_button_compete->x = 0;
bdef_button_compete->y = 0;
bdef_button_compete->w = 128;
bdef_button_compete->h = 40;
bdef_button_compete->spr = sprdef_button;
}
void setup_loop(float deltatime)
{
int maxselect = 0;
// Handle controls
if (global_stickcooldown > 0)
global_stickcooldown -= deltatime;
switch (global_curmenu)
{
case MENU_START:
{
if (global_transition == TRANS_FORWARD && bdef_backbox_mode->w >= 270)
{
global_selection = 0;
global_cursoractive = true;
global_transition = TRANS_NONE;
global_curmenu = MENU_MODE;
global_cursory = bdef_button_freeplay->y - 12;
}
break;
}
case MENU_MODE:
{
maxselect = 2;
if (global_transition == TRANS_BACKWARD && bdef_backbox_mode->x > 150)
{
global_selection = 0;
global_cursoractive = true;
global_transition = TRANS_NONE;
global_cursory = bdef_button_freeplay->y - 12;
}
else if (global_cursoractive)
{
if (controller_isa())
{
if (global_selection == 0)
global_cfg_nextround = NR_FREEPLAY;
else
global_cfg_nextround = NR_LEAST;
global_curmenu = MENU_PLAYERS;
global_transition = TRANS_FORWARD;
global_cursoractive = false;
play_confirm_sfx();
}
}
break;
}
case MENU_PLAYERS:
{
maxselect = 0;
if (global_transition == TRANS_FORWARD && bdef_backbox_plycount->x <= 170)
{
global_cursoractive = true;
global_transition = TRANS_NONE;
}
else if (global_transition == TRANS_BACKWARD && bdef_backbox_aidiff->w != 0)
{
if (bdef_backbox_aidiff->w < 32)
{
bdef_backbox_aidiff->w = 0;
bdef_backbox_aidiff->h = 0;
global_cursoractive = true;
global_transition = TRANS_NONE;
}
}
else if (global_transition == TRANS_BACKWARD && bdef_backbox_plycount->x >= 150)
{
global_cursoractive = true;
global_transition = TRANS_NONE;
}
if (global_cursoractive)
{
int count = 0;
for (int i=0; i<MAXPLAYERS; i++)
if (joypad_get_buttons_pressed(i).start)
{
global_playerjoined[i] = !global_playerjoined[i];
if (global_playerjoined[i]) {
wav64_play(&sfx_join, 29);
} else {
wav64_play(&sfx_leave, 28);
}
}
for (int i=0; i<MAXPLAYERS; i++)
if (global_playerjoined[i])
count++;
if (count > 0 && controller_isaheld())
{
global_readyprog += deltatime;
if (global_readyprog >= 1)
{
global_readyprog = 0;
if (count != 4)
{
global_curmenu = MENU_AIDIFF;
global_selection = 1;
global_transition = TRANS_FORWARD;
global_cursoractive = false;
}
else
{
global_curmenu = MENU_GAMESETUP;
global_transition = TRANS_FORWARD;
global_cursoractive = false;
}
core_set_playercount(global_playerjoined);
play_confirm_sfx();
}
}
else
global_readyprog = 0;
if (controller_isb())
{
global_cursoractive = false;
global_curmenu = MENU_MODE;
global_transition = TRANS_BACKWARD;
play_back_sfx();
}
}
break;
}
case MENU_AIDIFF:
{
maxselect = 3;
if (global_transition == TRANS_FORWARD && bdef_backbox_aidiff->w > 100)
{
global_cursoractive = true;
global_selection = 1;
global_transition = TRANS_NONE;
}
if (global_cursoractive)
{
if (controller_isa())
{
core_set_aidifficulty(global_selection);
global_curmenu = MENU_GAMESETUP;
global_transition = TRANS_FORWARD;
global_cursoractive = false;
play_confirm_sfx();
}
else if (controller_isb())
{
global_curmenu = MENU_PLAYERS;
global_transition = TRANS_BACKWARD;
global_cursoractive = false;
play_back_sfx();
}
}
break;
}
case MENU_GAMESETUP:
{
if (global_cfg_nextround != NR_FREEPLAY)
maxselect = 3;
else
maxselect = 1;
if (global_transition == TRANS_FORWARD && bdef_backbox_gameconfig->x <= 170)
{
global_cursoractive = true;
global_selection = 0;
global_transition = TRANS_NONE;
bdef_backbox_aidiff->w = 0;
bdef_backbox_aidiff->h = 0;
}
else if (global_transition == TRANS_BACKWARD && bdef_backbox_blacklist->w > 1 && bdef_backbox_blacklist->w < 32)
{
bdef_backbox_blacklist->w = 0;
bdef_backbox_blacklist->h = 0;
global_cursoractive = true;
if (global_cfg_nextround != NR_FREEPLAY)
global_selection = 2;
else
global_selection = 0;
global_transition = TRANS_NONE;
}
if (global_cursoractive)
{
if (controller_isa() || controller_isright())
{
if (global_cfg_nextround != NR_FREEPLAY && global_selection == 0)
{
global_cfg_points++;
if (global_cfg_points > 7)
global_cfg_points = 1;
play_cursor_sfx();
}
else if (global_selection == 1)
{
global_cfg_nextround++;
if (global_cfg_nextround > NR_RANDOMGAME)
global_cfg_nextround = NR_LEAST;
play_cursor_sfx();
}
else if ((global_cfg_nextround != NR_FREEPLAY && global_selection == 2) || (global_cfg_nextround == NR_FREEPLAY && global_selection == 0))
{
global_cursoractive = false;
global_readyprog = 0;
global_curmenu = MENU_BLACKLIST;
global_transition = TRANS_FORWARD;
play_confirm_sfx();
}
}
else if (controller_isleft())
{
if (global_selection == 0)
{
global_cfg_points--;
if (global_cfg_points < 1)
global_cfg_points = 7;
play_cursor_sfx();
}
else if (global_selection == 1)
{
if (global_cfg_nextround == NR_LEAST)
global_cfg_nextround = NR_RANDOMGAME;
else
global_cfg_nextround--;
play_cursor_sfx();
}
}
else if (controller_isb())
{
global_readyprog = 0;
global_cursoractive = false;
global_curmenu = MENU_PLAYERS;
global_transition = TRANS_BACKWARD;
play_back_sfx();
}
else if (controller_isstartheld())
{
global_readyprog += deltatime;
if (global_readyprog >= 1)
{
global_readyprog = 0;
global_curmenu = MENU_DONE;
global_transition = TRANS_FORWARD;
global_cursoractive = false;
play_confirm_sfx();
}
}
else
global_readyprog = 0;
}
break;
}
case MENU_BLACKLIST:
{
maxselect = global_minigame_count;
if (bdef_backbox_blacklist->w > 200 && global_transition == TRANS_FORWARD)
{
global_selection = 0;
global_cursoractive = true;
global_transition = TRANS_NONE;
}
if (global_cursoractive)
{
if (controller_isa() || controller_isright())
{
global_cfg_blacklist[global_selection] = !global_cfg_blacklist[global_selection];
play_cursor_sfx();
}
else if (controller_isleft())
{
global_cfg_blacklist[global_selection] = !global_cfg_blacklist[global_selection];
play_cursor_sfx();
}
else if (controller_isb())
{
bool availablegame = false;
for (int i=0; i<global_minigame_count; i++)
{
if (global_cfg_blacklist[i] == false)
{
availablegame = true;
break;
}
}
if (availablegame)
{
global_curmenu = MENU_GAMESETUP;
global_transition = TRANS_BACKWARD;
global_cursoractive = false;
play_back_sfx();
}
}
}
break;
}
case MENU_DONE:
{
if (global_fadetime > 0.0f)
{
global_fadetime -= deltatime;
xm64player_set_vol(&global_music, clamp(global_fadetime, 0, 1));
if (global_fadetime < 0)
{
results_set_points_to_win(global_cfg_points);
core_set_nextround(global_cfg_nextround);
core_set_curchooser(PLAYER_1);
savestate_setblacklist(global_cfg_blacklist);
savestate_save(true);
menu_reset();
core_level_changeto(LEVEL_MINIGAMESELECT);
}
}
break;
}
default: break;
}
// Handle animations and transitions
if (is_menuvisible(MENU_MODE))
{
bdef_backbox_mode->w = elasticlerp(0, 280, global_backtime - POPTIME);
bdef_backbox_mode->h = elasticlerp(0, 200, global_backtime - POPTIME);
if (global_curmenu == MENU_PLAYERS && global_transition == TRANS_FORWARD)
bdef_backbox_mode->x = lerp(bdef_backbox_mode->x, -bdef_backbox_mode->w, 7*deltatime);
else
bdef_backbox_mode->x = lerp(bdef_backbox_mode->x, 320/2, 7*deltatime);
if (global_selection == 0)
{
global_rotsel1 = lerp(global_rotsel1, sin(global_backtime*2)/3, 10*deltatime);
global_rotsel2 = lerp(global_rotsel2, 0, 10*deltatime);
global_cursory = lerp(global_cursory, bdef_button_freeplay->y - 12, 10*deltatime);
}
else
{
global_rotsel1 = lerp(global_rotsel1, 0, 10*deltatime);
global_rotsel2 = lerp(global_rotsel2, sin(global_backtime*2)/3, 10*deltatime);
global_cursory = lerp(global_cursory, bdef_button_compete->y - 12, 10*deltatime);
}
}
if (is_menuvisible(MENU_PLAYERS))
{
if (global_curmenu == MENU_PLAYERS)
bdef_backbox_plycount->x = lerp(bdef_backbox_plycount->x, 320/2, 7*deltatime);
else if (global_curmenu == MENU_MODE && global_transition == TRANS_BACKWARD)
bdef_backbox_plycount->x = lerp(bdef_backbox_plycount->x, 320+bdef_backbox_mode->w, 7*deltatime);
else if (global_curmenu == MENU_GAMESETUP && global_transition == TRANS_FORWARD)
bdef_backbox_plycount->x = lerp(bdef_backbox_plycount->x, -bdef_backbox_mode->w, 7*deltatime);
}
if (is_menuvisible(MENU_AIDIFF))
{
if (global_curmenu == MENU_AIDIFF && global_transition != TRANS_BACKWARD)
{
bdef_backbox_aidiff->w = lerp(bdef_backbox_aidiff->w, 128, 10*deltatime);
bdef_backbox_aidiff->h = lerp(bdef_backbox_aidiff->h, 128, 10*deltatime);
}
else
{
bdef_backbox_aidiff->w = lerp(bdef_backbox_aidiff->w, 0, 10*deltatime);
bdef_backbox_aidiff->h = lerp(bdef_backbox_aidiff->h, 0, 10*deltatime);
}
}
if (is_menuvisible(MENU_GAMESETUP))
{
if (global_curmenu == MENU_GAMESETUP && global_transition != TRANS_BACKWARD)
bdef_backbox_gameconfig->x = lerp(bdef_backbox_gameconfig->x, 320/2, 7*deltatime);
else if (global_curmenu == MENU_PLAYERS && global_transition == TRANS_BACKWARD)
bdef_backbox_gameconfig->x = lerp(bdef_backbox_gameconfig->x, 320+bdef_backbox_mode->w, 7*deltatime);
else if (global_curmenu == MENU_DONE && global_transition == TRANS_FORWARD)
{
bdef_backbox_gameconfig->w = lerp(bdef_backbox_gameconfig->w, 0, (1.0f*3)*deltatime);
bdef_backbox_gameconfig->h = lerp(bdef_backbox_gameconfig->h, 0, (0.8f*3)*deltatime);
}
}
if (is_menuvisible(MENU_BLACKLIST))
{
if (global_curmenu == MENU_BLACKLIST && global_transition != TRANS_BACKWARD)
{
bdef_backbox_blacklist->w = lerp(bdef_backbox_blacklist->w, 250, 10*deltatime);
bdef_backbox_blacklist->h = lerp(bdef_backbox_blacklist->h, 128, 10*deltatime);
}
else
{
bdef_backbox_blacklist->w = lerp(bdef_backbox_blacklist->w, 0, 10*deltatime);
bdef_backbox_blacklist->h = lerp(bdef_backbox_blacklist->h, 0, 10*deltatime);
}
}
// Handle parenting of objects to the main backbox
bdef_button_freeplay->x = bdef_backbox_mode->x;
bdef_button_freeplay->y = bdef_backbox_mode->y - 26;
bdef_button_compete->x = bdef_backbox_mode->x;
bdef_button_compete->y = bdef_backbox_mode->y + 26;
bdef_backbox_aidiff->x = bdef_backbox_plycount->x;
bdef_backbox_aidiff->y = bdef_backbox_plycount->y;
bdef_backbox_blacklist->x = bdef_backbox_gameconfig->x;
bdef_backbox_blacklist->y = bdef_backbox_gameconfig->y;
// Handle cursor selection change
if (global_cursoractive)
{
if (controller_isdown())
{
global_selection++;
if (global_selection >= maxselect)
global_selection = 0;
play_cursor_sfx();
}
else if (controller_isup())
{
global_selection--;
if (global_selection < 0)
global_selection = maxselect-1;
play_cursor_sfx();
}
}
// Draw the scene
setup_draw(deltatime);
}
void setup_draw(float deltatime)
{
const float backspeed = 0.3f;
const color_t backcolors[] = {
{255, 150, 150, 255},
{255, 255, 150, 255},
{150, 255, 150, 255},
{150, 255, 255, 255},
{150, 150, 255, 255},
{255, 150, 255, 255},
};
rdpq_blitparms_t bp_freeplay = {.cx=16,.cy=16};
rdpq_blitparms_t bp_compete = {.cx=16,.cy=16};
int ccurr, cnext;
// Increase background animation time
global_backtime += deltatime;
ccurr = ((int)(global_backtime*backspeed)) % (sizeof(backcolors)/sizeof(backcolors[0]));
cnext = (ccurr + 1) % (sizeof(backcolors)/sizeof(backcolors[0]));
// Begin drawing
surface_t* disp = display_get();
rdpq_attach(disp, NULL);
// Draw the background
rdpq_set_mode_standard();
rdpq_mode_combiner(RDPQ_COMBINER_FLAT);
rdpq_mode_blender(RDPQ_BLENDER_MULTIPLY);
rdpq_set_prim_color(lerpcolor(backcolors[ccurr], backcolors[cnext], global_backtime*backspeed - floor(global_backtime*backspeed)));
rdpq_fill_rectangle(0, 0, 320, 240);
// Draw menu sprites
if (is_menuvisible(MENU_MODE))
{
// Draw the container box
drawbox(bdef_backbox_mode, (color_t){255, 255, 255, 255});
culledges(bdef_backbox_mode);
// Draw option buttons
drawbox(bdef_button_freeplay, (color_t){200, 255, 200, 255});
drawbox(bdef_button_compete, (color_t){255, 255, 200, 255});
rdpq_set_prim_color((color_t){255, 255, 255, 255});
// Draw button sprites
if (global_selection == 0)
bp_freeplay.theta = global_rotsel1;
else
bp_compete.theta = global_rotsel2;
//rdpq_mode_filter(FILTER_BILINEAR);
rdpq_sprite_blit(spr_toybox, bdef_button_freeplay->x + 40, bdef_button_freeplay->y, &bp_freeplay);
rdpq_sprite_blit(spr_trophy, bdef_button_compete->x + 40, bdef_button_compete->y, &bp_compete);
// Pointer
if (global_cursoractive)
{
global_rotcursor = lerp(global_rotcursor, cos(global_backtime*4)*8, 10*deltatime);
rdpq_sprite_blit(spr_pointer, bdef_button_freeplay->x - bdef_button_freeplay->w + 28 + global_rotcursor, global_cursory, NULL);
}
rdpq_text_print(&(rdpq_textparms_t){.char_spacing=1, .style_id=1, .width=320, .align=ALIGN_CENTER}, FONTDEF_XLARGE, bdef_backbox_mode->x-320/2, bdef_backbox_mode->y-64, "I want to play:");
rdpq_text_print(&(rdpq_textparms_t){.char_spacing=1, .style_id=1}, FONTDEF_LARGE, bdef_button_freeplay->x - 54, bdef_button_freeplay->y+4, "For fun!");
rdpq_text_print(&(rdpq_textparms_t){.char_spacing=1, .style_id=1}, FONTDEF_LARGE, bdef_button_compete->x - 54, bdef_button_compete->y+4, "For glory!");
uncull();
}
if (is_menuvisible(MENU_PLAYERS))
{
int playernum = 0;
const int sprsize = 32;
const int padding = 16;
drawbox(bdef_backbox_plycount, (color_t){255, 255, 255, 255});
for (int i=0; i<MAXPLAYERS; i++)
{
if (global_playerjoined[i])
rdpq_sprite_blit(spr_player, bdef_backbox_plycount->x +16 - (sprsize+padding)*2 + padding/2 + (sprsize+padding)*i, bdef_backbox_plycount->y, &(rdpq_blitparms_t){.cx=16, .cy=16, .scale_x=1+sin(global_backtime*15)/10, .scale_y=1+cos(global_backtime*15)/10});
else
rdpq_sprite_blit(spr_robot, bdef_backbox_plycount->x - (sprsize+padding)*2 + padding/2 + (sprsize+padding)*i, bdef_backbox_plycount->y-24, NULL);
}
rdpq_sprite_blit(spr_start, bdef_backbox_plycount->x - 48, bdef_backbox_plycount->y - 77, NULL);
rdpq_text_print(&(rdpq_textparms_t){.width=320, .align=ALIGN_CENTER}, FONTDEF_XLARGE, bdef_backbox_plycount->x - 320/2, bdef_backbox_plycount->y-64, "Press to join / quit");
for (int i=0; i<MAXPLAYERS; i++)
{
if (global_playerjoined[i])
{
playernum++;
drawprogress(bdef_backbox_plycount->x - 84, bdef_backbox_plycount->y + 48, RGBA32(255, 0, 0, 255));
rdpq_sprite_blit(spr_a, bdef_backbox_plycount->x - 76, bdef_backbox_plycount->y+56, NULL);
rdpq_text_printf(&(rdpq_textparms_t){.width=34, .align=ALIGN_CENTER, .style_id=2+playernum}, FONTDEF_LARGE, bdef_backbox_plycount->x - (sprsize+padding)*2 + padding/2 + (sprsize+padding)*i, bdef_backbox_plycount->y-30, "P%d", playernum);
}
else
rdpq_text_print(&(rdpq_textparms_t){.width=34, .align=ALIGN_CENTER, .style_id=0}, FONTDEF_LARGE, bdef_backbox_plycount->x - (sprsize+padding)*2 + padding/2 + (sprsize+padding)*i, bdef_backbox_plycount->y-30, "CPU");
if (playernum > 0)
rdpq_text_print(&(rdpq_textparms_t){.width=320, .align=ALIGN_CENTER}, FONTDEF_LARGE, bdef_backbox_plycount->x - 320/2, bdef_backbox_plycount->y+68, "Hold when everyone is ready");
}
if (is_menuvisible(MENU_AIDIFF))
{
drawbox(bdef_backbox_aidiff, (color_t){255, 255, 255, 255});
culledges(bdef_backbox_aidiff);
rdpq_set_prim_color(RGBA32(255, 255, 0, 255));
rdpq_text_print(&(rdpq_textparms_t){.width=128, .align=ALIGN_CENTER, .char_spacing=1, .style_id=1}, FONTDEF_LARGE, bdef_backbox_aidiff->x - 64, bdef_backbox_aidiff->y - 40, "AI Difficulty");
rdpq_text_print(&(rdpq_textparms_t){.width=128, .align=ALIGN_CENTER, .char_spacing=1, .style_id=((global_selection == 0) ? 2 : 1)}, FONTDEF_LARGE, bdef_backbox_aidiff->x - 64, bdef_backbox_aidiff->y - 10 + 24*0, "Easy");
rdpq_text_print(&(rdpq_textparms_t){.width=128, .align=ALIGN_CENTER, .char_spacing=1, .style_id=((global_selection == 1) ? 2 : 1)}, FONTDEF_LARGE, bdef_backbox_aidiff->x - 64, bdef_backbox_aidiff->y - 10 + 24*1, "Medium");
rdpq_text_print(&(rdpq_textparms_t){.width=128, .align=ALIGN_CENTER, .char_spacing=1, .style_id=((global_selection == 2) ? 2 : 1)}, FONTDEF_LARGE, bdef_backbox_aidiff->x - 64, bdef_backbox_aidiff->y - 10 + 24*2, "Hard");
uncull();
}
}
if (is_menuvisible(MENU_GAMESETUP))
{
int increment = 0;
const char* options[] = {
" Least Points",
" Round Robin",
" Random Player",
" Random Game",
};
// Draw the container box
drawbox(bdef_backbox_gameconfig, (color_t){255, 255, 255, 255});
if (global_curmenu == MENU_DONE)
culledges(bdef_backbox_gameconfig);
drawprogress(bdef_backbox_gameconfig->x - 28 - 8, bdef_backbox_gameconfig->y + 60 - 8, RGBA32(0, 0, 255, 255));
rdpq_sprite_blit(spr_start, bdef_backbox_gameconfig->x - 28, bdef_backbox_gameconfig->y+60, NULL);
if (global_curmenu == MENU_DONE)
uncull();
if (global_curmenu == MENU_DONE)
culledges(bdef_backbox_gameconfig);
// Draw text
rdpq_text_print(&(rdpq_textparms_t){.char_spacing=1, .style_id=1, .width=320, .align=ALIGN_CENTER}, FONTDEF_XLARGE, bdef_backbox_gameconfig->x-320/2, bdef_backbox_gameconfig->y-64, "Game Setup");
if (global_cfg_nextround != NR_FREEPLAY)
{
rdpq_text_printf(&(rdpq_textparms_t){.char_spacing=1, .style_id=((global_cursoractive && global_selection == 0) ? 2 : 1)}, FONTDEF_LARGE, bdef_backbox_gameconfig->x-100, bdef_backbox_gameconfig->y - 40 + increment, "Points to win: %d", global_cfg_points);
increment += 30;
rdpq_text_print(&(rdpq_textparms_t){.char_spacing=1, .style_id=((global_cursoractive && global_selection == 1) ? 2 : 1)}, FONTDEF_LARGE, bdef_backbox_gameconfig->x-100, bdef_backbox_gameconfig->y - 40 + increment, "Who chooses next round: ");
increment += 15;
rdpq_text_print(&(rdpq_textparms_t){.char_spacing=1, .style_id=((global_cursoractive && global_selection == 1) ? 2 : 1)}, FONTDEF_LARGE, bdef_backbox_gameconfig->x-100, bdef_backbox_gameconfig->y - 40 + increment, options[global_cfg_nextround]);
increment += 30;
}
rdpq_text_print(&(rdpq_textparms_t){.char_spacing=1, .style_id=((global_cursoractive && ((global_selection == 2 && global_cfg_nextround != NR_FREEPLAY) || (global_selection == 0 && global_cfg_nextround == NR_FREEPLAY))) ? 2 : 1)}, FONTDEF_LARGE, bdef_backbox_gameconfig->x-100, bdef_backbox_gameconfig->y - 40 + increment, "Modify minigame blacklist");
rdpq_text_print(&(rdpq_textparms_t){.char_spacing=1, .style_id=1, .width=320, .align=ALIGN_CENTER}, FONTDEF_LARGE, bdef_backbox_gameconfig->x-320/2, bdef_backbox_gameconfig->y+72, "Hold to finish");
if (global_curmenu == MENU_DONE)
uncull();
}
if (is_menuvisible(MENU_BLACKLIST))
{
const int maxelems = 5;
static int scrolltop = 0;
static int scrollbot = maxelems-1;
int j = 0;
if (global_selection > (scrolltop+maxelems-1))
{
scrollbot = global_selection;
scrolltop = scrollbot - (maxelems-1);
}
else if (global_selection < scrolltop)
{
scrolltop = global_selection;
scrollbot = scrolltop + (maxelems-1);
}
drawbox(bdef_backbox_blacklist, (color_t){255, 255, 255, 255});
culledges(bdef_backbox_blacklist);
rdpq_set_prim_color(RGBA32(255, 255, 0, 255));
for (int i=scrolltop; i<scrolltop+maxelems; i++)
{
rdpq_text_print(&(rdpq_textparms_t){.width=200, .char_spacing=1, .style_id=((global_cursoractive && global_selection == i) ? 2 : 1)}, FONTDEF_LARGE, bdef_backbox_blacklist->x - 89, bdef_backbox_blacklist->y - 40+j*20, global_minigame_list[i].definition.gamename);
j++;
}
rdpq_set_mode_standard();
rdpq_mode_blender(RDPQ_BLENDER_MULTIPLY);
j=0;
for (int i=scrolltop; i<scrolltop+maxelems; i++)
{
sprite_t* target = spr_tick;
if (global_cfg_blacklist[i])
target = spr_cross;
rdpq_sprite_blit(target, bdef_backbox_blacklist->x - 115, bdef_backbox_blacklist->y - 52+j*20, NULL);
j++;
}
uncull();