-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstage00.c
2569 lines (2094 loc) · 99.9 KB
/
stage00.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 <assert.h>
#include <nusys.h>
#include "backgroundbuffers.h"
#include "constants.h"
#include "cutscene.h"
#include "cutscene_backgrounds/backgroundlookup.h"
#include "dialogue.h"
#include "displaytext.h"
#include "main.h"
#include "gameaudio.h"
#include "gamemath.h"
#include "graphic.h"
#include "mapdata.h"
#include "maps/maplookup.h"
#include "monsters.h"
#include "nustdfuncs.h"
#include "audio/bgm/sequence/tracknumbers.h"
#include "segmentinfo.h"
#include "sixtwelve.h"
#include "sixtwelve_helpers.h"
#include "stagekeys.h"
#include "board.h"
#include "pieces.h"
#include "audio/sfx/sfx.h"
static float gameplayTimePassed;
static u8 hasStartedMusic;
// TODO: break some of this into its own file later
typedef void (*MonsterUpdateCall)(int index);
static Vec2 positions[NUMBER_OF_INGAME_ENTITIES];
static Vec2 velocities[NUMBER_OF_INGAME_ENTITIES];
static u8 isActive[NUMBER_OF_INGAME_ENTITIES];
static int health[NUMBER_OF_INGAME_ENTITIES];
static float orientations[NUMBER_OF_INGAME_ENTITIES];
static float radiiSquared[NUMBER_OF_INGAME_ENTITIES];
static float knockbackTimesRemaining[NUMBER_OF_INGAME_ENTITIES];
static u8 isKnockingBackStates[NUMBER_OF_INGAME_ENTITIES];
static u8 lineOfSightVisible[NUMBER_OF_INGAME_ENTITIES];
static MonsterUpdateCall updateFunctions[NUMBER_OF_INGAME_ENTITIES];
static Gfx* renderCommands[NUMBER_OF_INGAME_ENTITIES];
static Mtx monsterSpecificTransforms[NUMBER_OF_INGAME_ENTITIES];
static u32 monsterState[NUMBER_OF_INGAME_ENTITIES][2];
static u8 monsterHurtSound[NUMBER_OF_INGAME_ENTITIES];
// TODO: be brave and combine this with the other positions
#define PROJECTILE_RADIUS 0.037f
#define PROJECTILE_RADIUS_SQ (PROJECTILE_RADIUS * PROJECTILE_RADIUS)
static Vec2 projectilePositions[NUMBER_OF_PROJECTILES];
static u8 projectileActive[NUMBER_OF_PROJECTILES];
static Vec2 projectileVelocity[NUMBER_OF_PROJECTILES];
// The player is always index zero; the remaining are monsters
#define playerPosition (positions[0])
#define playerVelocity (velocities[0])
#define playerOrientation (orientations[0])
#define playerHealth (health[0])
#define isPlayerKnockingBack (isKnockingBackStates[0])
#define playerKnockbackTimeRemaining (knockbackTimesRemaining[0])
#define playerRadiusSquared (radiiSquared[0])
static float playerPortraitStep;
static u8 portraitIndex;
static u8 hudBackgroundColor[3];
static float cosCameraRot;
static float sinCameraRot;
#define TRANSITION_DURATION 1.7f
#define NOT_TRANSITIONING 0
#define TRANSITIONING_IN 1
#define TRANSITIONING_OUT 2
static u8 transitioningState;
static float transitionTime;
// Returns the index if successful, returns -1 if not
int tryToSpawnAProjectile(const Vec2* position, const Vec2* velocity) {
for (int i = 0; i < NUMBER_OF_PROJECTILES; i++) {
if (projectileActive[i]) {
continue;
}
projectileActive[i] = 1;
projectilePositions[i] = *position;
projectileVelocity[i] = *velocity;
return i;
}
return -1;
}
#define OGRE_WALK_SPEED 1.9f
#define OGRE_MIN_NOTICE_TIME 0.7f
#define OGRE_FOV 0.15f
#define OGRE_CHASING_FOV 0.08f
void updateOgre(int index) {
if (isKnockingBackStates[index]) {
return;
}
float* ogreTime = (float*)(&monsterState[index][1]);
Vec2 directionToPlayer = { playerPosition.x - positions[index].x, playerPosition.y - positions[index].y };
normalize(&(directionToPlayer));
Vec2 ourDirection = { cosf(orientations[index] - M_PI_2), sinf(orientations[index] - M_PI_2) };
normalize(&ourDirection);
int canSeePlayer = lineOfSightVisible[index] && (dotProduct(&ourDirection, &directionToPlayer) > (lineOfSightVisible[index] ? OGRE_CHASING_FOV : OGRE_FOV));
if (!canSeePlayer) {
velocities[index].x = 0.f;
velocities[index].y = 0.f;
if (monsterState[index][0]) {
playSound(SFX_38_OGRE_WHAT);
}
monsterState[index][0] = 0;
*ogreTime = 0.f;
} else {
*ogreTime += deltaTimeSeconds;
}
if ((monsterState[index][0] == 0) && canSeePlayer && (*ogreTime > OGRE_MIN_NOTICE_TIME)) {
playSound(SFX_17_OGRE_GRUNT);
monsterState[index][0] = 1;
}
if (monsterState[index][0] == 0) {
const float t = sinf(gameplayTimePassed * 3.f) * 0.0425f;
guScale(&(monsterSpecificTransforms[index]), 1.f, 1.f, 1.f + t);
} else {
const float t = sinf(gameplayTimePassed * 14.f) ;
guRotateRPY(&(monsterSpecificTransforms[index]), t * 10.f, t * 6.f, 0.f);
orientations[index] = lerpAngle(orientations[index], nu_atan2(directionToPlayer.y, directionToPlayer.x) + M_PI_2, 2.9f * deltaTimeSeconds);
velocities[index] = (Vec2){ cosf(orientations[index] - M_PI_2), sinf(orientations[index] - M_PI_2) };
velocities[index].x *= OGRE_WALK_SPEED;
velocities[index].y *= OGRE_WALK_SPEED;
}
if (isPlayerKnockingBack) {
velocities[index].x = 0.f;
velocities[index].y = 0.f;
}
}
#define TOAD_WALK_SPEED 2.1616f
void updateToad(int index) {
if (isKnockingBackStates[index]) {
return;
}
const float t = sinf(gameplayTimePassed * 14.f) ;
guRotateRPY(&(monsterSpecificTransforms[index]), t * 20.f, t * 6.f, 0.f);
int shouldChangeDirections = 0;
Vec2 checkPoint = positions[index];
if (velocities[index].x > 0.f) {
checkPoint.x += 0.25f;
} else {
checkPoint.x -= 0.25f;
}
if ((checkPoint.x <= 0.01f) || (checkPoint.x > (BOARD_WIDTH - 0.01f))) {
shouldChangeDirections = 1;
}
if (isSpaceOccupiedButIgnoreMovingPieces((int)(checkPoint.x), (int)(checkPoint.y)) > -1) {
shouldChangeDirections = 1;
}
if (shouldChangeDirections) {
velocities[index].x *= -1;
orientations[index] = M_PI_2 * (velocities[index].x < 0.f ? -1.f : 1.f);
}
}
#define SNAKE_FIRE_RATE 2.f
#define SNAKE_SHOT_SPEED 0.9f
#define SNAKE_TURN_SPEED 1.714f
void updateSnake(int index) {
if (isKnockingBackStates[index]) {
return;
}
if (!(lineOfSightVisible[index])) {
return;
}
float* snakeTimePassed = (float*)(monsterState[index]);
*snakeTimePassed += deltaTimeSeconds;
// Having the snake move is very fun but also terrifying
Vec2 directionToPlayer = { playerPosition.x - positions[index].x, playerPosition.y - positions[index].y };
normalize(&(directionToPlayer));
orientations[index] = lerpAngle(orientations[index], nu_atan2(directionToPlayer.y, directionToPlayer.x) + M_PI_2, SNAKE_TURN_SPEED * deltaTimeSeconds);
if ((*snakeTimePassed) > SNAKE_FIRE_RATE) {
(*snakeTimePassed) = 0.f;
const Vec2 firingDirection = (Vec2){ cosf(orientations[index] - M_PI_2) * SNAKE_SHOT_SPEED, sinf(orientations[index] - M_PI_2) * SNAKE_SHOT_SPEED};
tryToSpawnAProjectile(&(positions[index]), &firingDirection);
}
}
#define JUMPER_GOING_RIGHT 0
#define JUMPER_GOING_DOWN 1
#define JUMPER_GOING_LEFT 2
#define JUMPER_GOING_UP 3
#define JUMPER_WALK_SPEED 3.0161f
void updateJumper(int index) {
if (isKnockingBackStates[index]) {
return;
}
u8* jumperDir = (u8*)(monsterState[index]);
Vec2 checkPoint = positions[index];
switch (*jumperDir) {
case JUMPER_GOING_RIGHT:
checkPoint.x += 0.25f;
break;
case JUMPER_GOING_DOWN:
checkPoint.y += 0.25f;
break;
case JUMPER_GOING_LEFT:
checkPoint.x -= 0.25f;
break;
default:
checkPoint.y -= 0.25f;
break;
}
int shouldChangeDirections = 0;
if ((checkPoint.x <= 0.01f) || (checkPoint.x > (BOARD_WIDTH - 0.01f))) {
shouldChangeDirections = 1;
}
if ((checkPoint.y <= 0.01f) || (checkPoint.y > (BOARD_HEIGHT - 0.01f))) {
shouldChangeDirections = 1;
}
if ((!shouldChangeDirections) && (isSpaceOccupiedButIgnoreMovingPieces((int)(checkPoint.x), (int)(checkPoint.y)) > -1)) {
shouldChangeDirections = 1;
}
if (shouldChangeDirections) {
switch (*jumperDir) {
case JUMPER_GOING_RIGHT:
*jumperDir = JUMPER_GOING_DOWN;
velocities[index] = (Vec2){ 0.f, JUMPER_WALK_SPEED };
break;
case JUMPER_GOING_DOWN:
*jumperDir = JUMPER_GOING_LEFT;
velocities[index] = (Vec2){ -JUMPER_WALK_SPEED, 0.f };
break;
case JUMPER_GOING_LEFT:
*jumperDir = JUMPER_GOING_UP;
velocities[index] = (Vec2){ 0.f, -JUMPER_WALK_SPEED };
break;
default:
*jumperDir = JUMPER_GOING_RIGHT;
velocities[index] = (Vec2){ JUMPER_WALK_SPEED, 0.f };
break;
}
}
guRotate(&(monsterSpecificTransforms[index]), gameplayTimePassed * 300.f, 0.f, 0.f, 1.f);
}
#define SHADOW_QUEEN_MOVE_SPEED 4.5f
#define SHADOW_QUEEN_FIRE_PERIOD 1.45f
#define SHADOW_QUEEN_FIRE_PERIOD_LOW_HP 1.25f
#define SHADOW_QUEEN_PROJETILE_SPEED 1.3f
void updateShadowQueen(int index) {
const Vec2* ourPosition = &(positions[index]);
Vec2 playerDirectionToBoardCenter = { (((float)BOARD_WIDTH) * 0.5f) - playerPosition.x, (((float)BOARD_HEIGHT) * 0.5f ) - playerPosition.y };
normalize(&playerDirectionToBoardCenter);
Vec2 ourTargetLocation = { (playerDirectionToBoardCenter.x * BOARD_WIDTH * 0.4f) + (((float)BOARD_WIDTH) * 0.5f), (playerDirectionToBoardCenter.y * BOARD_HEIGHT * 0.4f) + (((float)BOARD_HEIGHT) * 0.5f ) };
if (health[index] <= 2) {
ourTargetLocation.x = (playerPosition.x - (sinCameraRot * 1.51f));
ourTargetLocation.y = (playerPosition.y + (cosCameraRot * 1.51f));
health[index] = 2;
}
Vec2* ourVelocity = &(velocities[index]);
if (distanceSq(ourPosition, &ourTargetLocation) > (1.f * 1.f)) {
ourVelocity->x = ourTargetLocation.x - ourPosition->x;
ourVelocity->y = ourTargetLocation.y - ourPosition->y;
normalize(ourVelocity);
ourVelocity->x *= SHADOW_QUEEN_MOVE_SPEED;
ourVelocity->y *= SHADOW_QUEEN_MOVE_SPEED;
} else {
ourVelocity->x *= 0.93f;
ourVelocity->y *= 0.93f;
if (health[index] <= 2) {
if (monsterState[index][1] == 0) {
monsterState[index][1] = 1;
startDialogue("itsover");
} else if (dialogueState == DIALOGUE_STATE_OFF) {
transitioningState = TRANSITIONING_OUT;
transitionTime = 0.f;
}
}
}
orientations[index] = lerpAngle(orientations[index], nu_atan2(playerPosition.y - ourPosition->y, playerPosition.x - ourPosition->x) + M_PI_2, 0.11f);
if ((pieceData[0].type == ROOK) && (health[index] == 4) && (!(isKnockingBackStates[index]))) {
pieceData[0].type = BISHOP;
pieceData[0].renderCommands = bishop_commands;
pieceData[0].legalCheck = bishopLegalMove;
pieceData[0].displayName = "BISHOP";
playSoundAtDoublePitch(SFX_08_CONFIRM_MOVE);
} else if ((pieceData[0].type == BISHOP) && (health[index] == 3) && (!(isKnockingBackStates[index]))) {
pieceData[0].type = QUEEN;
pieceData[0].renderCommands = queen_commands;
pieceData[0].legalCheck = queenLegalMove;
pieceData[0].displayName = "QUEEN";
playSoundAtDoublePitch(SFX_08_CONFIRM_MOVE);
}
if (isKnockingBackStates[index] || health[index] <= 2 ) {
return;
}
// If we've made it here, update our fire rate time
float* timePassed = (float*)(monsterState[index]);
*timePassed += deltaTimeSeconds;
if (*timePassed > (health[index] >= 3 ? SHADOW_QUEEN_FIRE_PERIOD : SHADOW_QUEEN_FIRE_PERIOD_LOW_HP)) {
*timePassed = 0.f;
const Vec2 firingDirection = (Vec2){ cosf(orientations[index] - M_PI_2) * SHADOW_QUEEN_PROJETILE_SPEED, sinf(orientations[index] - M_PI_2) * SHADOW_QUEEN_PROJETILE_SPEED};
tryToSpawnAProjectile(&(positions[index]), &firingDirection);
}
}
#define PLAYER_HEIGHT_ABOVE_GROUND 0.26f
#define PLAYER_WALK_SPEED 3.f
#define PLAYER_TURN_SPEED 3.f
#define PLAYER_MAX_HEALTH 5
#define INV_MAX_HEALTH (1.f / PLAYER_MAX_HEALTH)
#define CHESS_PIECE_RADIUS 0.5f
#define CHESS_PIECE_RADIUS_SQ (CHESS_PIECE_RADIUS * CHESS_PIECE_RADIUS)
#define KNOCKBACK_SPEED 7.5f
#define PLAYER_KNOCKBACK_TIME 0.216f
#define KNOCKBACK_TIME 0.416f
#define PLAYER_RADIUS 0.25f
#define PUZZLE_GLYPH_ROTATION_SPEED 64.f
static Pos2 puzzleSpaceSpots[MAX_NUMBER_OF_PUZZLE_SPACES];
static u32 numberOfPuzzleSpaces;
static float puzzleGlyphRotation;
static float cursorRotation;
#define FADE_OUT_TIME 1.f
#define GAME_STATE_ACTIVE 0
#define GAME_STATE_PLAYER_WINS 1
#define GAME_STATE_PLAYER_LOSES 2
static u8 gameState;
static float gameStateTime;
static float playerHealthDisplay;
static int lineOfSightCheckIndex;
#define BOARD_CONTROL_NO_SELECTED 0
#define BOARD_CONTROL_PIECE_SELECTED 1
static u32 boardControlState;
static u8 legalDestinationState[NUMBER_OF_BOARD_CELLS];
static Pos2 chessboardSpotHighlighted;
static int pieceInFrontOfPlayer;
static int selectedPiece;
static u8 isStagePaused;
#define NUMBER_OF_PAUSE_MENU_ITEMS 3
static u8 pauseMenuIndex;
static const char* pauseItems[NUMBER_OF_PAUSE_MENU_ITEMS] = {
"RESUME",
"RETRY FLOOR",
"LEVEL SELECT"
};
static u8 downPressed;
static u8 upPressed;
static u8 stickInDeadzone;
#define TIME_BANNER_ONSCREEN 3.f
static const char* bannerMessageText;
static float bannerMessageTime;
#define VERTS_PER_FLOOR_TILE 4
#define NUMBER_OF_FLOOR_VERTS (NUMBER_OF_BOARD_CELLS * VERTS_PER_FLOOR_TILE)
static Vtx floorVerts[NUMBER_OF_FLOOR_VERTS];
static u8 floorTexture[TMEM_SIZE_BYTES] __attribute__((aligned(8)));
static u8 hudIconsTexture[TMEM_SIZE_BYTES] __attribute__((aligned(8)));
static u8 hudNoiseBackgroundsTextre[TMEM_SIZE_BYTES] __attribute__((aligned(8)));
static u8 hudZattPortraits[48 * 48 * 2 * 4] __attribute__((aligned(8)));
#define NUMBER_OF_HUD_BACKGROUND_TILES 16
static u32 hudBackgroundTextureIndex;
#define INV_BOARD_WIDTH (1.f / (float)BOARD_WIDTH)
#define INV_BOARD_HEIGHT (1.f / (float)BOARD_HEIGHT)
#define VERT_BUFFER_SIZE 64
#define COMMANDS_END_DL_SIZE 1
static Gfx floorDL[(NUMBER_OF_BOARD_CELLS * 2) + COMMANDS_END_DL_SIZE];
static char floorStartBanner[32];
static Vtx wallVerts[((BOARD_WIDTH * 2) + (BOARD_HEIGHT * 2)) * VERTS_PER_FLOOR_TILE];
static Gfx wallDL[(BOARD_WIDTH * 2) + (BOARD_HEIGHT * 2) + 4 + COMMANDS_END_DL_SIZE];
const char* highlightedPieceText;
static Vtx puzzleSpaceVerts[] = {
{ -1, -1, 0, 0, 97 << 5, 0 << 5, 0x5B, 0xff, 0xff, 0xff },
{ 1, -1, 0, 0, 128 << 5, 0 << 5, 0x5B, 0xff, 0xff, 0xff },
{ 1, 1, 0, 0, 128 << 5, 32 << 5, 0x5B, 0xff, 0xff, 0xff },
{ -1, 1, 0, 0, 97 << 5, 32 << 5, 0x5B, 0xff, 0xff, 0xff },
};
#define NO_TUTORIAL_ACTIVE 0
#define TUTORIAL_STEP_HIGHLIGHT_PAWN 1
#define TUTORIAL_STEP_SELECT_PAWN 2
#define TUTORIAL_STEP_MOVE_CURSOR 3
#define TUTORIAL_STEP_CONFIRM_MOVE 4
#define TUTORIAL_STEP_FINISH_BOARD 5
u8 tutorialState;
const char* tutorialStepStrings[] = {
"TUT0",
"Get close to the pawn to touch it.",
"Press A to select the pawn.",
"Use the C buttons to move the cursor to\nthe legal space in front of it.",
"Press A to confirm the move.",
"Good work! Move the pawn onto the magic\ncircle."
};
static Gfx renderPuzzleSpaceCommands[] = {
gsSPVertex(puzzleSpaceVerts, 16, 0),
gsSP2Triangles(0, 1, 2, 0, 0, 2, 3, 0),
gsSPEndDisplayList()
};
int isPointLOSToTorch(const Vec2* pos, const Vec2* torchPos) {
for (int i = 0; i < 16; i++) {
Vec2 spot = { lerp(pos->x, torchPos->x, (float)i / 16.f), lerp(pos->y, torchPos->y, (float)i / 16.f) };
int occupiedSpaceIndex = isSpaceOccupied((int)(spot.x), (int)(spot.y));
if ((occupiedSpaceIndex > -1) && (pieceData[occupiedSpaceIndex].type == WALL)) {
return 0;
}
}
return 1;
}
// As described here:
// https://www.rapidtables.com/convert/color/hsv-to-rgb.html
void hsvToRGB(u32 degrees, float s, float v, u8* rgbResult) {
const float c = s * v;
const float x = c * ( 1.f - fabsf( ((float)(((int)(((float)degrees) / 60.f)) % 2)) - 1.f ) );
const float m = v - c;
float r = 0.f;
float g = 0.f;
float b = 0.f;
if (degrees < 60) {
r = c;
g = x;
b = 0;
} else if (degrees < 120) {
r = x;
g = c;
b = 0;
} else if (degrees < 180) {
r = 0;
g = c;
b = x;
} else if (degrees < 240) {
r = 0;
g = x;
b = c;
} else if (degrees < 300) {
r = x;
g = 0;
b = c;
} else {
r = c;
g = 0;
b = x;
}
rgbResult[0] = (u8)((r + m) * 255.f);
rgbResult[1] = (u8)((g + m) * 255.f);
rgbResult[2] = (u8)((b + m) * 255.f);
}
// TODO: let us customize/randomize the textures for this on init time
void generateFloorTiles() {
Gfx* commands = floorDL;
Vtx* verts = floorVerts;
Vtx* lastLoad = verts;
const Vec2 torchPoints[4] = { { -1.f, -1.f }, { BOARD_WIDTH + 1.f, -1.f }, { BOARD_WIDTH + 1.f, BOARD_HEIGHT + 1.f }, { -1.f, BOARD_HEIGHT + 1.f } };
gDPPipeSync(commands++);
for (int i = 0; i < NUMBER_OF_BOARD_CELLS; i++) {
const int x = (i % BOARD_WIDTH);
const int y = (i / BOARD_WIDTH);
u8 mod[4] = {0, 0, 0, 0};
const Vec2 boardPoints[4] = { {x + 0, y + 0}, { x + 1, y + 0 }, { x + 1, y + 1 }, { x + 0, y + 1 } };
for (int i = 2; i < 4; i++) {
for (int j = 2; j < 4; j++) {
int pointHasLOSToTorch = isPointLOSToTorch(&(boardPoints[i]), &(torchPoints[j]));
if (!pointHasLOSToTorch) {
mod[i] += 0x18;
}
}
}
if (tileIsDark(x, y)) {
*(verts++) = (Vtx){ x + 0, y + 0, 0, 0, 0 << 5, 0 << 5, 0x33- (mod[0] >> 2), 0x33- (mod[0] >> 2), 0x88 - ((i / BOARD_WIDTH) * 14) - (mod[0] >> 2), 0xff };
*(verts++) = (Vtx){ x + 1, y + 0, 0, 0, 32 << 5, 0 << 5, 0x33- (mod[1] >> 2), 0x33- (mod[1] >> 2), 0x88 - ((i / BOARD_WIDTH) * 14) - (mod[1] >> 2), 0xff };
*(verts++) = (Vtx){ x + 1, y + 1, 0, 0, 32 << 5, 32 << 5, 0x33- (mod[2] >> 2), 0x33- (mod[2] >> 2), 0x88 - ((i / BOARD_WIDTH) * 14) - (mod[2] >> 2), 0xff };
*(verts++) = (Vtx){ x + 0, y + 1, 0, 0, 0 << 5, 32 << 5, 0x33- (mod[3] >> 2), 0x33- (mod[3] >> 2), 0x88 - ((i / BOARD_WIDTH) * 14) - (mod[3] >> 2), 0xff };
} else {
*(verts++) = (Vtx){ x + 0, y + 0, 0, 0, 0 << 5, 0 << 5, 0xbf - mod[0], 0xbf - mod[0], 0xbf - (y * 15)- (mod[0]), 0xff };
*(verts++) = (Vtx){ x + 1, y + 0, 0, 0, 32 << 5, 0 << 5, 0xbf - mod[1], 0xbf - mod[1], 0xbf - (y * 15)- (mod[1]), 0xff };
*(verts++) = (Vtx){ x + 1, y + 1, 0, 0, 32 << 5, 32 << 5, 0xbf - mod[2], 0xbf - mod[2], 0xbf - (y * 15)- (mod[2]), 0xff };
*(verts++) = (Vtx){ x + 0, y + 1, 0, 0, 0 << 5, 32 << 5, 0xbf - mod[3], 0xbf - mod[3], 0xbf - (y * 15)- (mod[3]), 0xff };
}
if ((verts - lastLoad) >= VERT_BUFFER_SIZE) {
gSPVertex(commands++, &(lastLoad[0]), VERT_BUFFER_SIZE, 0);
for (int j = 0; j < VERT_BUFFER_SIZE; j += 4) {
gSP2Triangles(commands++, j + 0, j + 1, j + 2, 0, j + 0, j + 2, j + 3, 0);
}
lastLoad = verts;
}
}
gSPEndDisplayList(commands++);
}
#define WALL_HEIGHT 1
// TODO: let us customize/randomize the textures for this on init time
void generateWalls() {
Gfx* commands = wallDL;
Vtx* verts = wallVerts;
Vtx* lastLoad = verts;
u8 wallRgb[3] = { 0, 0, 0 };
hsvToRGB((216 + (currentLevel * 75)) % 360, 0.35f, 0.42f, wallRgb);
for (int i = 0; i < BOARD_WIDTH; i++) {
*(verts++) = (Vtx){ i + 1, 0, 0, 0, 64 << 5, 0 << 5, wallRgb[0], wallRgb[1], wallRgb[2], 0xff };
*(verts++) = (Vtx){ i + 0, 0, 0, 0, 96 << 5, 0 << 5, wallRgb[0], wallRgb[1], wallRgb[2], 0xff };
*(verts++) = (Vtx){ i + 0, 0, WALL_HEIGHT, 0, 96 << 5, 32 << 5, wallRgb[0], wallRgb[1], wallRgb[2], 0xff };
*(verts++) = (Vtx){ i + 1, 0, WALL_HEIGHT, 0, 64 << 5, 32 << 5, wallRgb[0], wallRgb[1], wallRgb[2], 0xff };
}
gSPVertex(commands++, &(lastLoad[0]), (BOARD_WIDTH * 4), 0);
for (int j = 0; j < (BOARD_WIDTH * 4); j += 4) {
gSP2Triangles(commands++, j + 0, j + 1, j + 2, 0, j + 0, j + 2, j + 3, 0);
}
lastLoad = verts;
for (int i = 0; i < BOARD_WIDTH; i++) {
*(verts++) = (Vtx){ i + 0, BOARD_HEIGHT, 0, 0, 64 << 5, 0 << 5, wallRgb[0], wallRgb[1], wallRgb[2], 0xff };
*(verts++) = (Vtx){ i + 1, BOARD_HEIGHT, 0, 0, 96 << 5, 0 << 5, wallRgb[0], wallRgb[1], wallRgb[2], 0xff };
*(verts++) = (Vtx){ i + 1, BOARD_HEIGHT, WALL_HEIGHT, 0, 96 << 5, 32 << 5, wallRgb[0], wallRgb[1], wallRgb[2], 0xff };
*(verts++) = (Vtx){ i + 0, BOARD_HEIGHT, WALL_HEIGHT, 0, 64 << 5, 32 << 5, wallRgb[0], wallRgb[1], wallRgb[2], 0xff };
}
gSPVertex(commands++, &(lastLoad[0]), (BOARD_WIDTH * 4), 0);
for (int j = 0; j < (BOARD_WIDTH * 4); j += 4) {
gSP2Triangles(commands++, j + 0, j + 1, j + 2, 0, j + 0, j + 2, j + 3, 0);
}
lastLoad = verts;
for (int i = 0; i < BOARD_HEIGHT; i++) {
*(verts++) = (Vtx){ 0, i + 0, 0, 0, 64 << 5, 0 << 5, wallRgb[0], wallRgb[1], wallRgb[2], 0xff };
*(verts++) = (Vtx){ 0, i + 1, 0, 0, 96 << 5, 0 << 5, wallRgb[0], wallRgb[1], wallRgb[2], 0xff };
*(verts++) = (Vtx){ 0, i + 1, WALL_HEIGHT, 0, 96 << 5, 32 << 5, wallRgb[0], wallRgb[1], wallRgb[2], 0xff };
*(verts++) = (Vtx){ 0, i + 0, WALL_HEIGHT, 0, 64 << 5, 32 << 5, wallRgb[0], wallRgb[1], wallRgb[2], 0xff };
}
gSPVertex(commands++, &(lastLoad[0]), (BOARD_HEIGHT * 4), 0);
for (int j = 0; j < (BOARD_HEIGHT * 4); j += 4) {
gSP2Triangles(commands++, j + 0, j + 1, j + 2, 0, j + 0, j + 2, j + 3, 0);
}
lastLoad = verts;
for (int i = 0; i < BOARD_HEIGHT; i++) {
*(verts++) = (Vtx){ BOARD_WIDTH, i + 1, 0, 0, 64 << 5, 0 << 5, wallRgb[0], wallRgb[1], wallRgb[2], 0xff };
*(verts++) = (Vtx){ BOARD_WIDTH, i + 0, 0, 0, 96 << 5, 0 << 5, wallRgb[0], wallRgb[1], wallRgb[2], 0xff };
*(verts++) = (Vtx){ BOARD_WIDTH, i + 0, WALL_HEIGHT, 0, 96 << 5, 32 << 5, wallRgb[0], wallRgb[1], wallRgb[2], 0xff };
*(verts++) = (Vtx){ BOARD_WIDTH, i + 1, WALL_HEIGHT, 0, 64 << 5, 32 << 5, wallRgb[0], wallRgb[1], wallRgb[2], 0xff };
}
gSPVertex(commands++, &(lastLoad[0]), (BOARD_HEIGHT * 4), 0);
for (int j = 0; j < (BOARD_HEIGHT * 4); j += 4) {
gSP2Triangles(commands++, j + 0, j + 1, j + 2, 0, j + 0, j + 2, j + 3, 0);
}
lastLoad = verts;
gSPEndDisplayList(commands++);
}
void generateTopOfTheTowerWalls() {
Gfx* commands = wallDL;
Vtx* verts = wallVerts;
Vtx* lastLoad = verts;
for (int i = 0; i < BOARD_WIDTH; i++) {
*(verts++) = (Vtx){ i + 1, 0, 0, 0, 64 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff };
*(verts++) = (Vtx){ i + 0, 0, 0, 0, 96 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff };
*(verts++) = (Vtx){ i + 0,-1, 0, 0, 96 << 5, 32 << 5, 0x8d, 0x5a, 0x8a, 0xff };
*(verts++) = (Vtx){ i + 1,-1, 0, 0, 64 << 5, 32 << 5, 0x8d, 0x5a, 0x8a, 0xff };
}
gSPVertex(commands++, &(lastLoad[0]), (BOARD_WIDTH * 4), 0);
for (int j = 0; j < (BOARD_WIDTH * 4); j += 4) {
gSP2Triangles(commands++, j + 0, j + 1, j + 2, 0, j + 0, j + 2, j + 3, 0);
}
lastLoad = verts;
for (int i = 0; i < BOARD_WIDTH; i++) {
*(verts++) = (Vtx){ i + 0, BOARD_HEIGHT, 0, 0, 64 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff };
*(verts++) = (Vtx){ i + 1, BOARD_HEIGHT, 0, 0, 96 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff };
*(verts++) = (Vtx){ i + 1, BOARD_HEIGHT + 1, 0, 0, 96 << 5, 32 << 5, 0x8d, 0x5a, 0x8a, 0xff };
*(verts++) = (Vtx){ i + 0, BOARD_HEIGHT + 1, 0, 0, 64 << 5, 32 << 5, 0x8d, 0x5a, 0x8a, 0xff };
}
gSPVertex(commands++, &(lastLoad[0]), (BOARD_WIDTH * 4), 0);
for (int j = 0; j < (BOARD_WIDTH * 4); j += 4) {
gSP2Triangles(commands++, j + 0, j + 1, j + 2, 0, j + 0, j + 2, j + 3, 0);
}
lastLoad = verts;
for (int i = 0; i < BOARD_HEIGHT; i++) {
*(verts++) = (Vtx){ 0, i + 0, 0, 0, 64 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff };
*(verts++) = (Vtx){ 0, i + 1, 0, 0, 96 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff };
*(verts++) = (Vtx){-1, i + 1, 0, 0, 96 << 5, 32 << 5, 0x8d, 0x5a, 0x8a, 0xff };
*(verts++) = (Vtx){-1, i + 0, 0, 0, 64 << 5, 32 << 5, 0x8d, 0x5a, 0x8a, 0xff };
}
gSPVertex(commands++, &(lastLoad[0]), (BOARD_HEIGHT * 4), 0);
for (int j = 0; j < (BOARD_HEIGHT * 4); j += 4) {
gSP2Triangles(commands++, j + 0, j + 1, j + 2, 0, j + 0, j + 2, j + 3, 0);
}
lastLoad = verts;
for (int i = 0; i < BOARD_HEIGHT; i++) {
*(verts++) = (Vtx){ BOARD_WIDTH, i + 1, 0, 0, 64 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff };
*(verts++) = (Vtx){ BOARD_WIDTH, i + 0, 0, 0, 96 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff };
*(verts++) = (Vtx){ BOARD_WIDTH + 1, i + 0, 0, 0, 96 << 5, 32 << 5, 0x8d, 0x5a, 0x8a, 0xff };
*(verts++) = (Vtx){ BOARD_WIDTH + 1, i + 1, 0, 0, 64 << 5, 32 << 5, 0x8d, 0x5a, 0x8a, 0xff };
}
gSPVertex(commands++, &(lastLoad[0]), (BOARD_HEIGHT * 4), 0);
for (int j = 0; j < (BOARD_HEIGHT * 4); j += 4) {
gSP2Triangles(commands++, j + 0, j + 1, j + 2, 0, j + 0, j + 2, j + 3, 0);
}
lastLoad = verts;
gSPEndDisplayList(commands++);
}
#define TOP_BACKING_COLOR0 0x40
#define MID_BACKING_COLOR0 0x20
#define BOTTOM_BACKING_COLOR0 0x00
static Vtx HUDBackgroundVerts[] = {
{ 0, 0, 0, 0, ACTION_SAFE_HORIZONTAL << 5, 0 << 5, TOP_BACKING_COLOR0, TOP_BACKING_COLOR0, TOP_BACKING_COLOR0, 0xff },
{ SCREEN_WD, 0, 0, 0, (SCREEN_WD - ACTION_SAFE_HORIZONTAL) << 5, 0 << 5, TOP_BACKING_COLOR0, TOP_BACKING_COLOR0, TOP_BACKING_COLOR0, 0xff },
{ SCREEN_WD, ACTION_SAFE_VERTICAL, 0, 0, (SCREEN_WD - ACTION_SAFE_HORIZONTAL) << 5, (ACTION_SAFE_VERTICAL) << 5, MID_BACKING_COLOR0, MID_BACKING_COLOR0, MID_BACKING_COLOR0, 0xff },
{ 0, ACTION_SAFE_VERTICAL, 0, 0, ACTION_SAFE_HORIZONTAL << 5, (ACTION_SAFE_VERTICAL) << 5, MID_BACKING_COLOR0, MID_BACKING_COLOR0, MID_BACKING_COLOR0, 0xff },
{ 0, 0, 0, 0, 0 << 5, 0 << 5, MID_BACKING_COLOR0, MID_BACKING_COLOR0, MID_BACKING_COLOR0, 0xff },
{ ACTION_SAFE_HORIZONTAL, 0, 0, 0, 16 << 5, 0 << 5, MID_BACKING_COLOR0, MID_BACKING_COLOR0, MID_BACKING_COLOR0, 0xff },
{ ACTION_SAFE_HORIZONTAL, SCREEN_HT, 0, 0, 16 << 5, SCREEN_HT << 5, MID_BACKING_COLOR0, MID_BACKING_COLOR0, MID_BACKING_COLOR0, 0xff },
{ 0, SCREEN_HT, 0, 0, 0 << 5, SCREEN_HT << 5, MID_BACKING_COLOR0, MID_BACKING_COLOR0, MID_BACKING_COLOR0, 0xff },
{ SCREEN_WD - ACTION_SAFE_HORIZONTAL, 0, 0, 0, 0 << 5, 0 << 5, MID_BACKING_COLOR0, MID_BACKING_COLOR0, MID_BACKING_COLOR0, 0xff },
{ SCREEN_WD , 0, 0, 0, 16 << 5, 0 << 5, MID_BACKING_COLOR0, MID_BACKING_COLOR0, MID_BACKING_COLOR0, 0xff },
{ SCREEN_WD , SCREEN_HT, 0, 0, 16 << 5, SCREEN_HT << 5, MID_BACKING_COLOR0, MID_BACKING_COLOR0, MID_BACKING_COLOR0, 0xff },
{ SCREEN_WD - ACTION_SAFE_HORIZONTAL, SCREEN_HT, 0, 0, 0 << 5, SCREEN_HT << 5, MID_BACKING_COLOR0, MID_BACKING_COLOR0, MID_BACKING_COLOR0, 0xff },
{ 0, SCREEN_HT - 80, 0, 0, 0 << 5, (SCREEN_HT - 80) << 5, MID_BACKING_COLOR0, MID_BACKING_COLOR0, MID_BACKING_COLOR0, 0xff },
{ SCREEN_WD, SCREEN_HT - 80, 0, 0, SCREEN_WD << 5, (SCREEN_HT - 80) << 5, MID_BACKING_COLOR0, MID_BACKING_COLOR0, MID_BACKING_COLOR0, 0xff },
{ SCREEN_WD, SCREEN_HT, 0, 0, SCREEN_WD << 5, SCREEN_HT << 5, BOTTOM_BACKING_COLOR0, BOTTOM_BACKING_COLOR0, BOTTOM_BACKING_COLOR0, 0xff },
{ 0, SCREEN_HT, 0, 0, 0 << 5, SCREEN_HT << 5, BOTTOM_BACKING_COLOR0, BOTTOM_BACKING_COLOR0, BOTTOM_BACKING_COLOR0, 0xff },
};
static Gfx renderHudBackgroundCommands[] = {
gsSPVertex(HUDBackgroundVerts, 16, 0),
gsSP2Triangles(4, 6, 5, 0, 4, 7, 6, 0),
gsSP2Triangles(8, 10, 9, 0, 8, 11, 10, 0),
gsSP2Triangles(12, 14, 13, 0, 12, 15, 14, 0),
gsSP2Triangles(0, 2, 1, 0, 0, 3, 2, 0),
gsSPEndDisplayList()
};
static Vtx RedHUDBackgroundVerts[] = {
{ 0, 0, 0, 0, ACTION_SAFE_HORIZONTAL << 5, 0 << 5, TOP_BACKING_COLOR0, 0x00, 0x00, 0xff },
{ SCREEN_WD, 0, 0, 0, (SCREEN_WD - ACTION_SAFE_HORIZONTAL) << 5, 0 << 5, TOP_BACKING_COLOR0, 0x00, 0x00, 0xff },
{ SCREEN_WD, ACTION_SAFE_VERTICAL, 0, 0, (SCREEN_WD - ACTION_SAFE_HORIZONTAL) << 5, (ACTION_SAFE_VERTICAL) << 5, MID_BACKING_COLOR0, 0x00, 0x00, 0xff },
{ 0, ACTION_SAFE_VERTICAL, 0, 0, ACTION_SAFE_HORIZONTAL << 5, (ACTION_SAFE_VERTICAL) << 5, MID_BACKING_COLOR0, 0x00, 0x00, 0xff },
{ 0, 0, 0, 0, 0 << 5, 0 << 5, MID_BACKING_COLOR0, 0x00, 0x00, 0xff },
{ ACTION_SAFE_HORIZONTAL, 0, 0, 0, 16 << 5, 0 << 5, MID_BACKING_COLOR0, 0x00, 0x00, 0xff },
{ ACTION_SAFE_HORIZONTAL, SCREEN_HT, 0, 0, 16 << 5, SCREEN_HT << 5, MID_BACKING_COLOR0, 0x00, 0x00, 0xff },
{ 0, SCREEN_HT, 0, 0, 0 << 5, SCREEN_HT << 5, MID_BACKING_COLOR0, 0x00, 0x00, 0xff },
{ SCREEN_WD - ACTION_SAFE_HORIZONTAL, 0, 0, 0, 0 << 5, 0 << 5, MID_BACKING_COLOR0, 0x00, 0x00, 0xff },
{ SCREEN_WD , 0, 0, 0, 16 << 5, 0 << 5, MID_BACKING_COLOR0, 0x00, 0x00, 0xff },
{ SCREEN_WD , SCREEN_HT, 0, 0, 16 << 5, SCREEN_HT << 5, MID_BACKING_COLOR0, 0x00, 0x00, 0xff },
{ SCREEN_WD - ACTION_SAFE_HORIZONTAL, SCREEN_HT, 0, 0, 0 << 5, SCREEN_HT << 5, MID_BACKING_COLOR0, 0x00, 0x00, 0xff },
{ 0, SCREEN_HT - 80, 0, 0, 0 << 5, (SCREEN_HT - 80) << 5, MID_BACKING_COLOR0, 0x00, 0x00, 0xff },
{ SCREEN_WD, SCREEN_HT - 80, 0, 0, SCREEN_WD << 5, (SCREEN_HT - 80) << 5, MID_BACKING_COLOR0, 0x00, 0x00, 0xff },
{ SCREEN_WD, SCREEN_HT, 0, 0, SCREEN_WD << 5, SCREEN_HT << 5, BOTTOM_BACKING_COLOR0, 0x00, 0x00, 0xff },
{ 0, SCREEN_HT, 0, 0, 0 << 5, SCREEN_HT << 5, BOTTOM_BACKING_COLOR0, 0x00, 0x00, 0xff },
};
static Gfx renderRedHudBackgroundCommands[] = {
gsSPVertex(RedHUDBackgroundVerts, 16, 0),
gsSP2Triangles(4, 6, 5, 0, 4, 7, 6, 0),
gsSP2Triangles(8, 10, 9, 0, 8, 11, 10, 0),
gsSP2Triangles(12, 14, 13, 0, 12, 15, 14, 0),
gsSP2Triangles(0, 2, 1, 0, 0, 3, 2, 0),
gsSPEndDisplayList()
};
#define HUD_CELL_WIDTH 16
#define HUD_CELL_HEIGHT 10
#define HUD_CHESSBOARD_WIDTH (HUD_CELL_WIDTH * BOARD_WIDTH)
#define HUD_CHESSBOARD_HEIGHT (BOARD_HEIGHT * HUD_CELL_HEIGHT)
#define HUD_CHESSBOARD_X (SCREEN_WD - HUD_CHESSBOARD_WIDTH - TITLE_SAFE_HORIZONTAL)
#define HUD_CHESSBOARD_Y (SCREEN_HT - HUD_CHESSBOARD_HEIGHT - TITLE_SAFE_VERTICAL)
static Vtx onscreenChessboardVerts[NUMBER_OF_FLOOR_VERTS];
static Gfx onscreenChessboardCommands[(NUMBER_OF_BOARD_CELLS * 2) + COMMANDS_END_DL_SIZE];
void generateHUDChessboard() {
Gfx* commands = onscreenChessboardCommands;
Vtx* verts = onscreenChessboardVerts;
Vtx* lastLoad = verts;
for (int i = 0; i < NUMBER_OF_BOARD_CELLS; i++) {
const int x = ((i % BOARD_WIDTH) * HUD_CELL_WIDTH) + HUD_CHESSBOARD_X;
const int y = HUD_CHESSBOARD_HEIGHT - ((i / BOARD_WIDTH) * HUD_CELL_HEIGHT) + HUD_CHESSBOARD_Y;
if (tileIsDark(i % BOARD_WIDTH, i / BOARD_WIDTH)) {
*(verts++) = (Vtx){ x + 0 , y + 0 , 0, 0, 0 << 5, 0 << 5, 0x60, 0x60, 0x91 - ((i / BOARD_WIDTH) * 10), 0xff };
*(verts++) = (Vtx){ x + HUD_CELL_WIDTH, y + 0 , 0, 0, 32 << 5, 0 << 5, 0x60, 0x60, 0x91 - ((i / BOARD_WIDTH) * 10), 0xff };
*(verts++) = (Vtx){ x + HUD_CELL_WIDTH, y - HUD_CELL_HEIGHT, 0, 0, 32 << 5, 32 << 5, 0x60, 0x60, 0x91 - ((i / BOARD_WIDTH) * 10), 0xff };
*(verts++) = (Vtx){ x + 0 , y - HUD_CELL_HEIGHT, 0, 0, 0 << 5, 32 << 5, 0x60, 0x60, 0x91 - ((i / BOARD_WIDTH) * 10), 0xff };
} else {
*(verts++) = (Vtx){ x + 0 , y + 0 , 0, 0, 0 << 5, 0 << 5, 0xbf, 0xbf, 0xbf - ((i / BOARD_WIDTH) * 12), 0xff };
*(verts++) = (Vtx){ x + HUD_CELL_WIDTH, y + 0 , 0, 0, 32 << 5, 0 << 5, 0xbf, 0xbf, 0xbf - ((i / BOARD_WIDTH) * 12), 0xff };
*(verts++) = (Vtx){ x + HUD_CELL_WIDTH, y - HUD_CELL_HEIGHT, 0, 0, 32 << 5, 32 << 5, 0xbf, 0xbf, 0xbf - ((i / BOARD_WIDTH) * 12), 0xff };
*(verts++) = (Vtx){ x + 0 , y - HUD_CELL_HEIGHT, 0, 0, 0 << 5, 32 << 5, 0xbf, 0xbf, 0xbf - ((i / BOARD_WIDTH) * 12), 0xff };
}
if ((verts - lastLoad) >= VERT_BUFFER_SIZE) {
gSPVertex(commands++, &(lastLoad[0]), VERT_BUFFER_SIZE, 0);
for (int j = 0; j < VERT_BUFFER_SIZE; j += 4) {
gSP2Triangles(commands++, j + 0, j + 1, j + 2, 0, j + 0, j + 2, j + 3, 0);
}
lastLoad = verts;
}
}
gSPEndDisplayList(commands++);
}
static Vtx decorVerts[] = {
{ -4, -1, 2, 0, 64 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 0, -1, 2, 0, 96 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 0, -1, 1, 0, 96 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ -4, -1, 1, 0, 64 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 0, -1, 2, 0, 64 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 4, -1, 2, 0, 96 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 4, -1, 1, 0, 96 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 0, -1, 1, 0, 64 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 4, -1, 2, 0, 64 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 8, -1, 2, 0, 96 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 8, -1, 1, 0, 96 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 4, -1, 1, 0, 64 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 8, -1, 2, 0, 64 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 12, -1, 2, 0, 96 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 12, -1, 1, 0, 96 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 8, -1, 1, 0, 64 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 0, 9, 2, 0, 96 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ -4, 9, 2, 0, 64 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ -4, 9, 1, 0, 64 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 0, 9, 1, 0, 96 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 4, 9, 2, 0, 96 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 0, 9, 2, 0, 64 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 0, 9, 1, 0, 64 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 4, 9, 1, 0, 96 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 8, 9, 2, 0, 96 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 4, 9, 2, 0, 64 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 4, 9, 1, 0, 64 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 8, 9, 1, 0, 96 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 12, 9, 2, 0, 96 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 8, 9, 2, 0, 64 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 8, 9, 1, 0, 64 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 12, 9, 1, 0, 96 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 9, -1, 2, 0, 64 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 9, 0, 2, 0, 96 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 9, 0, 1, 0, 96 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 9, -1, 1, 0, 64 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 9, 0, 2, 0, 64 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 9, 4, 2, 0, 96 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 9, 4, 1, 0, 96 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 9, 0, 1, 0, 64 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 9, 4, 2, 0, 64 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 9, 8, 2, 0, 96 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 9, 8, 1, 0, 96 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 9, 4, 1, 0, 64 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 9, 8, 2, 0, 64 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 9, 9, 2, 0, 96 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ 9, 9, 1, 0, 96 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ 9, 8, 1, 0, 64 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ -1, 0, 2, 0, 96 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ -1, -1, 2, 0, 64 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ -1, -1, 1, 0, 64 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ -1, 0, 1, 0, 96 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ -1, 4, 2, 0, 96 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ -1, 0, 2, 0, 64 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ -1, 0, 1, 0, 64 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ -1, 4, 1, 0, 96 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ -1, 8, 2, 0, 96 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ -1, 4, 2, 0, 64 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ -1, 4, 1, 0, 64 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ -1, 8, 1, 0, 96 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ -1, 9, 2, 0, 96 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ -1, 8, 2, 0, 64 << 5, 0 << 5, 0x99, 0x42, 0x8C, 0xff },
{ -1, 8, 1, 0, 64 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
{ -1, 9, 1, 0, 96 << 5, 32 << 5, 0x38, 0x18, 0x33, 0xff },
};
static Gfx decorCommands[] = {
gsSPVertex(decorVerts, 64, 0),
gsSP2Triangles(0, 1, 2, 0, 0, 2, 3, 0),
gsSP2Triangles(4, 5, 6, 0, 4, 6, 7, 0),
gsSP2Triangles(8, 9,10, 0, 8, 10,11, 0),
gsSP2Triangles(12, 13,14, 0,12,14,15, 0),
gsSP2Triangles( 0 + 16, 1 + 16, 2 + 16, 0, 0 + 16, 2 + 16, 3 + 16, 0),
gsSP2Triangles( 4 + 16, 5 + 16, 6 + 16, 0, 4 + 16, 6 + 16, 7 + 16, 0),
gsSP2Triangles( 8 + 16, 9 + 16, 10 + 16, 0, 8 + 16, 10 + 16, 11 + 16, 0),
gsSP2Triangles(12 + 16, 13 + 16, 14 + 16, 0, 12 + 16, 14 + 16, 15 + 16, 0),
gsSP2Triangles( 0 + 32, 1 + 32, 2 + 32, 0, 0 + 32, 2 + 32, 3 + 32, 0),
gsSP2Triangles( 4 + 32, 5 + 32, 6 + 32, 0, 4 + 32, 6 + 32, 7 + 32, 0),
gsSP2Triangles( 8 + 32, 9 + 32, 10 + 32, 0, 8 + 32, 10 + 32, 11 + 32, 0),
gsSP2Triangles(12 + 32, 13 + 32, 14 + 32, 0, 12 + 32, 14 + 32, 15 + 32, 0),
gsSP2Triangles( 0 + 48, 1 + 48, 2 + 48, 0, 0 + 48, 2 + 48, 3 + 48, 0),
gsSP2Triangles( 4 + 48, 5 + 48, 6 + 48, 0, 4 + 48, 6 + 48, 7 + 48, 0),
gsSP2Triangles( 8 + 48, 9 + 48, 10 + 48, 0, 8 + 48, 10 + 48, 11 + 48, 0),
gsSP2Triangles(12 + 48, 13 + 48, 14 + 48, 0, 12 + 48, 14 + 48, 15 + 48, 0),
gsSPEndDisplayList()
};
static Vtx fireVerts[] = {
{ -1, 1, 2, 0, 50 << 5, 0 << 5, 0xff, 0xb2, 0x10, 0xff },
{ 1, -1, 2, 0, 63 << 5, 0 << 5, 0xff, 0xb2, 0x10, 0xff },
{ 1, -1, 0, 0, 63 << 5, 12 << 5, 0xac, 0x4c, 0x00, 0xff },
{ -1, 1, 0, 0, 50 << 5, 12 << 5, 0xac, 0x4c, 0x00, 0xff },
{ 1, BOARD_HEIGHT + 1, 2, 0, 63 << 5, 12 << 5, 0xff, 0xb2, 0x10, 0xff },
{ -1, BOARD_HEIGHT , 2, 0, 50 << 5, 12 << 5, 0xff, 0xb2, 0x10, 0xff },
{ -1, BOARD_HEIGHT , 0, 0, 50 << 5, 24 << 5, 0xac, 0x4c, 0x00, 0xff },
{ 1, BOARD_HEIGHT + 1, 0, 0, 63 << 5, 24 << 5, 0xac, 0x4c, 0x00, 0xff },
{ BOARD_WIDTH + 1, BOARD_HEIGHT , 2, 0, 50 << 5, 0 << 5, 0xff, 0xb2, 0x10, 0xff },
{ BOARD_WIDTH , BOARD_HEIGHT + 1, 2, 0, 63 << 5, 0 << 5, 0xff, 0xb2, 0x10, 0xff },
{ BOARD_WIDTH , BOARD_HEIGHT + 1, 0, 0, 63 << 5, 12 << 5, 0xac, 0x4c, 0x00, 0xff },
{ BOARD_WIDTH + 1, BOARD_HEIGHT , 0, 0, 50 << 5, 12 << 5, 0xac, 0x4c, 0x00, 0xff },
{ BOARD_WIDTH , -1, 2, 0, 50 << 5, 12 << 5, 0xff, 0xb2, 0x10, 0xff },
{ BOARD_WIDTH + 1, 1, 2, 0, 63 << 5, 12 << 5, 0xff, 0xb2, 0x10, 0xff },
{ BOARD_WIDTH + 1, 1, 0, 0, 63 << 5, 24 << 5, 0xac, 0x4c, 0x00, 0xff },
{ BOARD_WIDTH , -1, 0, 0, 50 << 5, 24 << 5, 0xac, 0x4c, 0x00, 0xff },
};
static Vtx fireVerts2[] = {
{ -1, 1, 2, 0, 50 << 5, 12 << 5, 0xff, 0xb2, 0x10, 0xff },
{ 1, -1, 2, 0, 63 << 5, 12 << 5, 0xff, 0xb2, 0x10, 0xff },
{ 1, -1, 0, 0, 63 << 5, 24 << 5, 0xac, 0x4c, 0x00, 0xff },
{ -1, 1, 0, 0, 50 << 5, 24 << 5, 0xac, 0x4c, 0x00, 0xff },
{ 1, BOARD_HEIGHT + 1, 2, 0, 63 << 5, 0 << 5, 0xff, 0xb2, 0x10, 0xff },
{ -1, BOARD_HEIGHT , 2, 0, 50 << 5, 0 << 5, 0xff, 0xb2, 0x10, 0xff },
{ -1, BOARD_HEIGHT , 0, 0, 50 << 5, 12 << 5, 0xac, 0x4c, 0x00, 0xff },
{ 1, BOARD_HEIGHT + 1, 0, 0, 63 << 5, 12 << 5, 0xac, 0x4c, 0x00, 0xff },
{ BOARD_WIDTH + 1, BOARD_HEIGHT , 2, 0, 50 << 5, 12 << 5, 0xff, 0xb2, 0x10, 0xff },
{ BOARD_WIDTH , BOARD_HEIGHT + 1, 2, 0, 63 << 5, 12 << 5, 0xff, 0xb2, 0x10, 0xff },
{ BOARD_WIDTH , BOARD_HEIGHT + 1, 0, 0, 63 << 5, 24 << 5, 0xac, 0x4c, 0x00, 0xff },
{ BOARD_WIDTH + 1, BOARD_HEIGHT , 0, 0, 50 << 5, 24 << 5, 0xac, 0x4c, 0x00, 0xff },
{ BOARD_WIDTH , -1, 2, 0, 50 << 5, 0 << 5, 0xff, 0xb2, 0x10, 0xff },
{ BOARD_WIDTH + 1, 1, 2, 0, 63 << 5, 0 << 5, 0xff, 0xb2, 0x10, 0xff },
{ BOARD_WIDTH + 1, 1, 0, 0, 63 << 5, 12 << 5, 0xac, 0x4c, 0x00, 0xff },
{ BOARD_WIDTH , -1, 0, 0, 50 << 5, 12 << 5, 0xac, 0x4c, 0x00, 0xff },
};
static Gfx fireCommands[] = {
// gsSP2Triangles(0, 1, 2, 0, 0, 2, 3, 0),
gsSP2Triangles(4, 5, 6, 0, 4, 6, 7, 0),
gsSP2Triangles(8, 9,10, 0, 8,10,11, 0),
// gsSP2Triangles(12,13,14, 0,12,14,15, 0),
gsSPEndDisplayList()
};
static Vtx topPillarVerts[] = {
{ -1, -1, 1, 0, 64 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff },
{ 0, -1, 0, 0, 96 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff },
{ 0, -1, 0, 0, 96 << 5, 32 << 5, 0x6d, 0x5a, 0x6a, 0xff },
{ 0, 0, 0, 0, 64 << 5, 32 << 5, 0x6d, 0x5a, 0x6a, 0xff },
{ -1, 0, 0, 0, 96 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff },
{ -1, -1, 1, 0, 64 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff },
{ 0, 0, 0, 0, 64 << 5, 32 << 5, 0x6d, 0x5a, 0x6a, 0xff },
{ -1, 0, 0, 0, 96 << 5, 32 << 5, 0x6d, 0x5a, 0x6a, 0xff },
{ BOARD_WIDTH + 0, -1, 0, 0, 96 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff },
{ BOARD_WIDTH + 1, -1, 1, 0, 64 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff },
{ BOARD_WIDTH + 0, 0, 0, 0, 64 << 5, 32 << 5, 0x6d, 0x5a, 0x6a, 0xff },
{ BOARD_WIDTH + 0, -1, 0, 0, 96 << 5, 32 << 5, 0x6d, 0x5a, 0x6a, 0xff },
{ BOARD_WIDTH + 1, -1, 1, 0, 64 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff },
{ BOARD_WIDTH + 1, 0, 0, 0, 96 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff },
{ BOARD_WIDTH + 1, 0, 0, 0, 96 << 5, 32 << 5, 0x6d, 0x5a, 0x6a, 0xff },
{ BOARD_WIDTH + 0, 0, 0, 0, 64 << 5, 32 << 5, 0x6d, 0x5a, 0x6a, 0xff },
{ 0, BOARD_HEIGHT + 1, 0, 0, 96 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff },
{ -1, BOARD_HEIGHT + 1, 1, 0, 64 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff },
{ 0, BOARD_HEIGHT + 0, 0, 0, 64 << 5, 32 << 5, 0x6d, 0x5a, 0x6a, 0xff },
{ 0, BOARD_HEIGHT + 1, 0, 0, 96 << 5, 32 << 5, 0x6d, 0x5a, 0x6a, 0xff },
{ -1, BOARD_HEIGHT + 1, 1, 0, 64 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff },
{ -1, BOARD_HEIGHT + 0, 0, 0, 96 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff },
{ -1, BOARD_HEIGHT + 0, 0, 0, 96 << 5, 32 << 5, 0x6d, 0x5a, 0x6a, 0xff },
{ 0, BOARD_HEIGHT + 0, 0, 0, 64 << 5, 32 << 5, 0x6d, 0x5a, 0x6a, 0xff },
{ BOARD_WIDTH + 1, BOARD_HEIGHT + 1, 1, 0, 64 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff },
{ BOARD_WIDTH + 0, BOARD_HEIGHT + 1, 0, 0, 96 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff },
{ BOARD_WIDTH + 0, BOARD_HEIGHT + 1, 0, 0, 96 << 5, 32 << 5, 0x6d, 0x5a, 0x6a, 0xff },
{ BOARD_WIDTH + 0, BOARD_HEIGHT + 0, 0, 0, 64 << 5, 32 << 5, 0x6d, 0x5a, 0x6a, 0xff },
{ BOARD_WIDTH + 1, BOARD_HEIGHT + 0, 0, 0, 96 << 5, 0 << 5, 0x8d, 0x5a, 0x8a, 0xff },