generated from raysan5/raylib-gamejam-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstribun.c
4925 lines (3938 loc) · 134 KB
/
stribun.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
/*******************************************************************************************
*
* raylib gamejam template
*
* Template originally created with raylib 4.5-dev, last time updated with raylib 5.0
*
* Template licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2022-2023 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
#include "raymath.h"
#include "rlgl.h"
#if defined(PLATFORM_WEB)
#define CUSTOM_MODAL_DIALOGS
#include <emscripten/emscripten.h>
#endif
#define FLOAT_MAX 340282346638528859811704183484516925440.0f
#if defined(PLATFORM_DESKTOP)
#define GLSL_VERSION 330
#else // PLATFORM_ANDROID, PLATFORM_WEB
#define GLSL_VERSION 100
#endif
#define RLIGHTS_IMPLEMENTATION
#include "rlights.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <assert.h>
#define SUPPORT_LOG_INFO
#if defined(SUPPORT_LOG_INFO)
#define LOG(...) printf(__VA_ARGS__)
#else
#define LOG(...)
#endif
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
static bool seenTutorial = false;
static bool esdf = false;
typedef enum {
BOSS_INTRODUCTION_BEGINNING,
BOSS_INTRODUCTION_FOCUS,
BOSS_INTRODUCTION_INFO,
} BossIntroductionStage;
static BossIntroductionStage introductionStage = {0};
typedef enum {
GAME_MAIN_MENU,
GAME_TUTORIAL,
GAME_BOSS_INTRODUCTION,
GAME_BOSS,
GAME_BOSS_DEAD,
GAME_PLAYER_DEAD,
GAME_STATS,
} GameState;
static bool isGamePaused = false;
static Vector2 cameraIntroductionTarget = {0};
static Music mainMenuMusic = {0};
static Music bossMarineMusic = {0};
static GameState gameState = GAME_MAIN_MENU;
#define SPRITES_SCALE 3.5
static Texture2D sprites = {0};
typedef enum {
DIRECTION_UP = 0b0001,
DIRECTION_DOWN = 0b0010,
DIRECTION_LEFT = 0b0100,
DIRECTION_RIGHT = 0b1000,
} Direction;
#define PLAYER_HITBOX_RADIUS 24
#define PLAYER_DASH_COOLDOWN 0.55f
#define PLAYER_MOVEMENT_SPEED 6
typedef enum {
PERK_RANDOM_SIZED_BULLETS = 0b0000000001,
PERK_MORE_SPREAD = 0b0000000010,
PERK_HOMING = 0b0000000100,
PERK_STRONG_DASH = 0b0000001000,
PERK_DOUBLE_DAMAGE = 0b0000010000,
PERK_LESS_HP_MORE_DAMAGE = 0b0000100000,
PERK_SLOW_BUT_STEADY = 0b0001000000,
PERK_FAST_BULLETS = 0b0010000000,
PERK_DOUBLE_HP = 0b0100000000,
PERK_GLASS_CANON = 0b1000000000,
} Perk;
typedef struct {
Vector2 position;
int health;
float fireCooldown;
float dashCooldown;
Direction movementDirection;
Vector2 movementDelta;
Vector2 dashDelta;
float dashReactivationEffectAlpha;
int bulletSpread;
bool isInvincible;
float iframeTimer;
Perk perks;
} Player;
typedef struct {
float time;
int kills;
} PlayerStats;
static PlayerStats playerStats = {0};
#define MAX_BOUNDING_CIRCLES 3
typedef struct {
Vector2 position;
float radius;
} Circle;
static Rectangle bossMarineRect = {
.x = 0,
.y = 35,
.width = 71,
.height = 71,
};
static Rectangle bossMarineWeaponRect = {
.x = 76,
.y = 61,
.width = 85,
.height = 37,
};
static Vector2 bossMarineInitialWeaponOffset = {
.x = 14 * SPRITES_SCALE,
.y = 6 * SPRITES_SCALE,
};
#define BOSS_MARINE_MAX_HEALTH 512
#define BOSS_MARINE_NAME "Uziel Enkidas"
#define BOSS_MARINE_BOUNDING_CIRCLES 12
typedef enum {
BOSS_MARINE_SINUS_SHOOTING,
BOSS_MARINE_SHOOTING,
BOSS_MARINE_SHOTGUNNING,
BOSS_MARINE_BOUNCING_WAVES,
BOSS_MARINE_NOT_SHOOTING,
} BossMarineAttack;
typedef struct {
Vector2 position;
int health;
/* positions are relative */
Circle boundingCircles[BOSS_MARINE_BOUNDING_CIRCLES];
float horizontalFlip;
Circle processedBoundingCircles[BOSS_MARINE_BOUNDING_CIRCLES];
Vector2 bulletOrigin;
float weaponAngle;
Vector2 weaponOffset;
float walkingDirection;
bool isWalking;
BossMarineAttack currentAttack;
float attackTimer;
float weaponAngleOffset;
float fireCooldown;
} BossMarine;
BossMarine bossMarine = {0};
#define BOSS_BALL_NAME "Rigor Mortis"
#define BOSS_BALL_MAX_HEALTH (1024 + 512)
static Shader bossBallLightingShader = {0};
static Model bossBallModel = {0};
static Texture2D bossBallTexture = {0};
static Light bossBallLight = {0};
static Camera bossBallCamera = {0};
static Music bossBallMusic = {0};
static Sound bossBallTurretSound = {0};
static Sound bossBallLaserChargingSound = {0};
static Sound bossBallRocketSound = {0};
static Sound bossBallDeath = {0};
static RenderTexture2D bossBallTarget = {0};
static RenderTexture2D bossBallTargetScreen = {0};
#define BOSS_BALL_HITBOX_RADIUS 180
#define BOSS_BALL_MOVE_SPEED 5
#define BOSS_BALL_WEAPONS 8
typedef enum {
BOSS_BALL_WEAPON_TURRET,
BOSS_BALL_WEAPON_LASER,
BOSS_BALL_WEAPON_ROCKET_LAUNCHER,
BOSS_BALL_WEAPON_COUNT,
BOSS_BALL_WEAPON_NONE,
} BossBallWeaponType;
Rectangle bossBallWeaponRects[BOSS_BALL_WEAPON_COUNT] = {
[BOSS_BALL_WEAPON_TURRET] = {288, 19, 43, 47},
[BOSS_BALL_WEAPON_LASER] = {395, 4, 25, 41},
[BOSS_BALL_WEAPON_ROCKET_LAUNCHER] = {343, 7, 43, 61},
};
static Rectangle bossBallChargedLaserRect = {422, 4, 25, 41};
float bossBallWeaponHitboxRadiuses[BOSS_BALL_WEAPON_COUNT] = {
[BOSS_BALL_WEAPON_TURRET] = 70.0f,
[BOSS_BALL_WEAPON_LASER] = 50.0f,
[BOSS_BALL_WEAPON_ROCKET_LAUNCHER] = 60.0f,
};
#define LASER_WIDTH 2048
#define LASER_HEIGHT 69
static Shader laserShader = {0};
static int laserShaderTime = {0};
static RenderTexture2D laserTexture = {0};
typedef struct {
BossBallWeaponType type;
bool seesPlayer;
float fireCooldown;
float attackTimer;
bool isDisconnected;
Vector2 position;
float angle;
float angleOffset;
bool isWalking;
float standingWalkingTimer;
float walkingDirection;
float chargeLevel;
Vector2 bulletOrigin;
Vector2 bulletOrigin2;
float laserLength;
Music soundEffect;
float attackCooldown;
} BossBallWeapon;
typedef struct {
Vector2 position;
int health;
Vector2 targetPosition;
Vector2 startingPosition;
float standingStilTimer;
Vector3 rotationAxis;
float angle;
float weaponAngleOffset;
float weaponAngleTargetOffset;
float playerInsideDeadZoneTimer;
BossBallWeapon weapons[BOSS_BALL_WEAPONS];
} BossBall;
static BossBall bossBall = {0};
typedef enum {
BOSS_MARINE,
BOSS_BALL,
} BossType;
BossType currentBoss = BOSS_MARINE;
#define BACKGROUND_PARALLAX_OFFSET 16
static const int screenWidth = 1280;
static const int screenHeight = 720;
static Shader arenaBorderShader = {0};
static int arenaBorderTime = 0;
static Shader stars = {0};
static int starsTime = 0;
static int starsDom = 0;
static Shader dashTrailShader = {0};
static int dashTrailShaderAlpha = {0};
static int dashTrailShaderColor = {0};
static Camera2D camera = {0};
#define LEVEL_WIDTH 1536
#define LEVEL_HEIGHT 1536
static const Vector2 level = {
.x = LEVEL_WIDTH,
.y = LEVEL_HEIGHT,
};
static const Vector2 background = {
.x = (float)LEVEL_WIDTH * 1.5,
.y = (float)LEVEL_HEIGHT * 1.5,
};
static RenderTexture2D target = {0};
static Texture2D nebulaNoise = {0};
#define BIG_ASS_ASTEROID_SCALE 15
static Rectangle bigAssAsteroidRect = {
.x = 121,
.y = 0,
.width = 35,
.height = 29,
};
static Vector2 bigAssAsteroidPosition = {0};
static float bigAssAsteroidAngle = 0;
static Vector2 bigAssAsteroidPositionDelta = {0};
static float bigAssAsteroidAngleDelta = 0;
static Rectangle mouseCursorRect = {
.x = 175,
.y = 0,
.width = 17,
.height = 17,
};
static Rectangle playerHealthOverlayMaskRect = {
.x = 16,
.y = 0,
.width = 15,
.height = 16,
};
static Shader playerHealthOverlayShader = {0};
static int playerHealthOverlayHealth = 0;
static Texture2D playerHealthMaskTexture = {0};
static Shader pixelationShader = {0};
static int pixelationShaderPixelSize = {0};
static Rectangle playerRect = {
.x = 0,
.y = 16,
.width = 17,
.height = 19,
};
typedef struct {
Rectangle textureRect;
int boundingCirclesLen;
/* NOTE: positions are relative to the center of the texture */
Circle boundingCircles[MAX_BOUNDING_CIRCLES];
} AsteroidSprite;
static const AsteroidSprite asteroidSprites[] = {
{
.textureRect = {
.x = 34,
.y = 0,
.width = 19,
.height = 19,
},
.boundingCirclesLen = 1,
.boundingCircles = {
{
.position = {0, 0},
.radius = 9,
}
},
},
{
.textureRect = {
.x = 55,
.y = 0,
.width = 35,
.height = 25,
},
.boundingCirclesLen = 3,
.boundingCircles = {
{
.position = {6, -2},
.radius = 11,
},
{
.position = {4, 7},
.radius = 5,
},
{
.position = {-6, 1},
.radius = 12,
}
}
},
{
.textureRect = {
.x = 91,
.y = 0,
.width = 27,
.height = 25,
},
.boundingCirclesLen = 1,
.boundingCircles = {
{
.position = {0, 0},
.radius = 13,
}
}
}
};
typedef struct {
const AsteroidSprite * sprite;
float angle;
float angleDelta;
Vector2 position;
Vector2 delta;
Circle processedBoundingCircles[MAX_BOUNDING_CIRCLES];
bool launchedByPlayer;
} Asteroid;
#define MIN_ASTEROIDS 4
#define MAX_ASTEROIDS 10
static Asteroid asteroids[MAX_ASTEROIDS] = {0};
static int asteroidsLen = 0;
static Vector2 mouseCursor = {0};
static Player player = {0};
static float time = 0;
static Sound playerDeathSound = {0};
static Sound dashSoundEffect = {0};
static Sound playerShot = {0};
static Sound beep = {0};
static Sound hit = {0};
static Sound buttonFocusEffect = {0};
static Sound borderActivation = {0};
static Sound bossMarineShotgunSound = {0};
static Sound bossMarineGunshotSound = {0};
typedef enum {
PROJECTILE_NONE,
PROJECTILE_REGULAR,
PROJECTILE_SQUARED,
} ProjectileType;
typedef struct {
ProjectileType type;
union {
float radius;
Vector2 size;
};
Vector2 delta;
Vector2 origin;
float angle;
bool willBeDestroyed;
float destructionTimer;
bool isHurtfulForPlayer;
bool isHurtfulForBoss;
int damage;
Color inside;
Color outside;
float lifetime;
bool canBounce;
bool homesOntoPlayer;
} Projectile;
#define PROJECTILES_MAX 1024
static Projectile projectiles[PROJECTILES_MAX] = {0};
#define MAX_PLAYER_HEALTH maxPlayerHealth()
int maxPlayerHealth(void) {
int base = 8;
if (player.perks & PERK_GLASS_CANON) {
base /= 4;
}
if (player.perks & PERK_DOUBLE_HP) {
base *= 2;
}
return base;
}
#define MOUSE_SENSITIVITY 0.7f
void bossBallUpdateShader(void) {
SetShaderValue(bossBallLightingShader,
bossBallLightingShader.locs[SHADER_LOC_VECTOR_VIEW],
&bossBallCamera.position,
SHADER_UNIFORM_VEC3);
UpdateLightValues(bossBallLightingShader, bossBallLight);
}
float mod(float v, float max) {
if (v > max) {
return fmodf(v, max);
}
if (v < 0) {
return max - fmodf(v, max);
}
return v;
}
float angleBetweenPoints(Vector2 p1, Vector2 p2) {
Vector2 d = Vector2Subtract(p1, p2);
float dist = sqrt((d.x * d.x) + (d.y * d.y));
float alpha = asin(d.x / dist) * RAD2DEG;
if (d.y > 0) {
alpha = copysignf(180 - fabsf(alpha), alpha);
}
alpha += 180;
return alpha;
}
void checkForCollisionsBetweenAsteroids(int i, int k) {
for (int bi = 0; bi < asteroids[i].sprite->boundingCirclesLen; bi++) {
Vector2 ipos = Vector2Add(asteroids[i].position,
asteroids[i].processedBoundingCircles[bi].position);
for (int bk = 0; bk < asteroids[k].sprite->boundingCirclesLen; bk++) {
Vector2 kpos = Vector2Add(asteroids[k].position,
asteroids[k].processedBoundingCircles[bk].position);
float distance = Vector2Distance(kpos, ipos);
float radiusSum =
(asteroids[k].processedBoundingCircles[bk].radius +
asteroids[i].processedBoundingCircles[bi].radius);
if (distance < radiusSum) {
float angle = angleBetweenPoints(kpos, ipos) *
DEG2RAD;
float offsetDistance = distance - radiusSum;
Vector2 offset = Vector2Rotate((Vector2) {0, offsetDistance}, angle);
asteroids[i].position = Vector2Add(asteroids[i].position, offset);
asteroids[i].delta = Vector2Add(asteroids[i].delta, offset);
asteroids[k].delta = Vector2Subtract(asteroids[k].delta, offset);
asteroids[i].launchedByPlayer = false;
asteroids[k].launchedByPlayer = true;
return;
}
}
}
}
void checkForCollisionsBetweenAsteroidsAndBorders(void) {
Vector2 normalDown = {0, 1};
Vector2 normalUp = {0, -1};
Vector2 normalRight = {1, 0};
Vector2 normalLeft = {-1, 0};
for (int i = 0; i < asteroidsLen; i++) {
for (int j = 0; j < asteroids[i].sprite->boundingCirclesLen; j++) {
Vector2 pos = Vector2Add(asteroids[i].position,
asteroids[i].processedBoundingCircles[j].position);
float r = asteroids[i].processedBoundingCircles[j].radius;
if ((pos.y - r) <= 0) {
asteroids[i].delta = Vector2Reflect(asteroids[i].delta, normalDown);
asteroids[i].launchedByPlayer = false;
break;
}
if ((pos.x - r) <= 0) {
asteroids[i].delta = Vector2Reflect(asteroids[i].delta, normalRight);
asteroids[i].launchedByPlayer = false;
break;
}
if ((pos.y + r) >= LEVEL_HEIGHT - 1) {
asteroids[i].delta = Vector2Reflect(asteroids[i].delta, normalUp);
asteroids[i].launchedByPlayer = false;
break;
}
if ((pos.x + r) >= LEVEL_WIDTH - 1) {
asteroids[i].delta = Vector2Reflect(asteroids[i].delta, normalLeft);
asteroids[i].launchedByPlayer = false;
break;
}
}
}
}
void updateAsteroids(void) {
for (int i = 0; i < asteroidsLen; i++) {
for (int k = 0; k < asteroidsLen; k++) {
if (k == i) {
continue;
}
checkForCollisionsBetweenAsteroids(i, k);
}
asteroids[i].position = Vector2Add(asteroids[i].position, asteroids[i].delta);
float properAngle = asteroids[i].angle + 180;
asteroids[i].angle = mod(properAngle + asteroids[i].angleDelta, 360) - 180;
for (int j = 0; j < asteroids[i].sprite->boundingCirclesLen; j++) {
asteroids[i].processedBoundingCircles[j].position =
Vector2Rotate(asteroids[i].sprite->boundingCircles[j].position,
asteroids[i].angle * DEG2RAD);
asteroids[i].processedBoundingCircles[j].position =
Vector2Scale(asteroids[i].processedBoundingCircles[j].position, SPRITES_SCALE);
asteroids[i].processedBoundingCircles[j].radius =
asteroids[i].sprite->boundingCircles[j].radius * SPRITES_SCALE;
}
}
checkForCollisionsBetweenAsteroidsAndBorders();
}
Projectile *push_projectile(void) {
for (int i = 0; i < PROJECTILES_MAX; i++) {
if (projectiles[i].type == PROJECTILE_NONE) {
return &projectiles[i];
}
}
return NULL;
}
static Vector2 lookingDirection = {0};
static Vector2 screenMouseLocation = {0};
float playerLookingAngle(void) {
static const Vector2 up = {
.x = 0,
.y = -1,
};
float angle = Vector2Angle(up, lookingDirection) * RAD2DEG;
return angle;
}
void bossMarineCheckCollisions(bool sendAsteroidsFlying) {
for (int i = 0; i < BOSS_MARINE_BOUNDING_CIRCLES; i++) {
Vector2 bcPos = Vector2Add(bossMarine.processedBoundingCircles[i].position,
bossMarine.position);
float r = bossMarine.processedBoundingCircles[i].radius;
for (int ai = 0; ai < asteroidsLen; ai++) {
for (int abi = 0; abi < asteroids[ai].sprite->boundingCirclesLen; abi++) {
Vector2 pos =
Vector2Add(asteroids[ai].processedBoundingCircles[abi].position,
asteroids[ai].position);
float distance = Vector2Distance(pos, bcPos);
float radiusSum =
(asteroids[ai].processedBoundingCircles[abi].radius + r);
if (distance < radiusSum) {
if (asteroids[ai].launchedByPlayer) {
#define ASTEROID_BASE_DAMAGE 4
float damageMultiplier = Vector2Length(asteroids[ai].delta);
bossMarine.health = (int)Clamp(bossMarine.health - (damageMultiplier * ASTEROID_BASE_DAMAGE),
0.0f,
BOSS_MARINE_MAX_HEALTH);
asteroids[ai].launchedByPlayer = false;
}
float angle = angleBetweenPoints(bcPos, asteroids[ai].position) * DEG2RAD;
float offsetDistance = distance - radiusSum;
Vector2 asteroidOffset = Vector2Rotate((Vector2) {0, offsetDistance}, angle);
asteroids[ai].position = Vector2Add(asteroids[ai].position, asteroidOffset);
if (sendAsteroidsFlying) {
asteroids[ai].delta = Vector2Add(asteroids[ai].delta, Vector2Scale(asteroidOffset, 0.5));
}
}
}
}
}
}
void bossMarineUpdateWeapon(void) {
Vector2 weaponOffset = (Vector2) {
.x = bossMarine.horizontalFlip * bossMarine.weaponOffset.x,
.y = bossMarine.weaponOffset.y,
};
bossMarine.weaponAngle =
angleBetweenPoints(Vector2Add(bossMarine.position,
weaponOffset),
player.position) - 90;
if (bossMarine.horizontalFlip == -1) {
bossMarine.weaponAngle += 180;
}
bossMarine.weaponAngle += bossMarine.weaponAngleOffset;
Vector2 bulletOrigin = Vector2Rotate((Vector2) {
.x = bossMarine.horizontalFlip * ((bossMarineWeaponRect.width / 2) * SPRITES_SCALE),
.y = -6 * SPRITES_SCALE,
}, bossMarine.weaponAngle * DEG2RAD);
bossMarine.bulletOrigin = Vector2Add(weaponOffset, bulletOrigin);
}
void bossMarineWalk(void) {
float playerBossAngle = angleBetweenPoints(player.position,
bossMarine.position);
#define BOSS_MARINE_SPEED 4
#define BOSS_MARINE_MIN_PLAYER_DISTANCE 200
#define BOSS_MARINE_MAX_PLAYER_DISTANCE 400
float playerBossDistance = Vector2Distance(player.position,
bossMarine.position);
Vector2 delta = Vector2Rotate((Vector2) {0, -BOSS_MARINE_SPEED},
playerBossAngle * DEG2RAD);
if (playerBossDistance < BOSS_MARINE_MIN_PLAYER_DISTANCE) {
bossMarine.position = Vector2Add(bossMarine.position, Vector2Scale(delta, 2));
} else if (playerBossDistance > BOSS_MARINE_MAX_PLAYER_DISTANCE && bossMarine.isWalking) {
bossMarine.position = Vector2Add(bossMarine.position, Vector2Scale(delta, -1));
} else if (bossMarine.isWalking) {
float angle = bossMarine.walkingDirection * BOSS_MARINE_SPEED;
Vector2 diff = Vector2Subtract(bossMarine.position, player.position);
diff = Vector2Rotate(diff, angle * DEG2RAD);
bossMarine.position = Vector2Lerp(bossMarine.position, Vector2Add(diff, player.position), 0.1f);
}
}
#define BOSS_MARINE_BASE_DAMAGE 1
#define BOSS_MARINE_PROJECTILE_RADIUS 13
#define BOSS_MARINE_PROJECTILE_SPEED 25.0f
void bossMarineShoot(float speedMultiplier,
float cooldown,
float spread,
Sound *sound,
float lifetime,
bool willBounce,
Color inside,
Color outside) {
if (bossMarine.fireCooldown > 0.0f) {
return;
}
Projectile *new_projectile = push_projectile();
if (new_projectile == NULL) {
return;
}
*new_projectile = (Projectile) {
.type = PROJECTILE_REGULAR,
.isHurtfulForBoss = false,
.isHurtfulForPlayer = true,
.damage = BOSS_MARINE_BASE_DAMAGE,
.origin = Vector2Add(bossMarine.position, bossMarine.bulletOrigin),
.radius = BOSS_MARINE_PROJECTILE_RADIUS,
.delta = Vector2Rotate(Vector2Scale((Vector2) {bossMarine.horizontalFlip, 0}, BOSS_MARINE_PROJECTILE_SPEED * speedMultiplier),
(bossMarine.weaponAngle + spread) * DEG2RAD),
.angle = 0,
.inside = inside,
.outside = outside,
.lifetime = lifetime,
.canBounce = willBounce,
};
bossMarine.fireCooldown = cooldown;
if (sound) {
PlaySound(*sound);
}
}
static bool bossMarineAttacks[BOSS_MARINE_NOT_SHOOTING] = {0};
void bossMarineAttack(void) {
bossMarine.attackTimer -= GetFrameTime();
bossMarine.fireCooldown -= GetFrameTime();
if (bossMarine.attackTimer <= 0.0f) {
bossMarine.isWalking = (bool)GetRandomValue(0, 1);
if (bossMarine.currentAttack == BOSS_MARINE_NOT_SHOOTING) {
int c = 0;
for (int i = 0; i < BOSS_MARINE_NOT_SHOOTING; i++) {
if (bossMarineAttacks[i]) {
c++;
}
}
if (c == BOSS_MARINE_NOT_SHOOTING) {
memset(bossMarineAttacks, 0, sizeof(bossMarineAttacks));
}
BossMarineAttack a = 0;
do {
a = GetRandomValue(BOSS_MARINE_SINUS_SHOOTING,
BOSS_MARINE_BOUNCING_WAVES);
} while (bossMarineAttacks[a]);
bossMarineAttacks[a] = true;
bossMarine.currentAttack = a;
bossMarine.attackTimer = (float)GetRandomValue(3, 7);
} else {
bossMarine.currentAttack = BOSS_MARINE_NOT_SHOOTING;
bossMarine.attackTimer = (float)GetRandomValue(1, 10) / 10.0f;
}
bossMarine.weaponAngleOffset = 0;
}
switch (bossMarine.currentAttack) {
case BOSS_MARINE_SINUS_SHOOTING: {
bossMarine.weaponAngleOffset = sin(time * 4) * 30 * bossMarine.horizontalFlip;
bossMarineUpdateWeapon();
bossMarineShoot(0.3f, 0.04f, 0, &bossMarineGunshotSound, 10, false, MAROON, GOLD);
} break;
case BOSS_MARINE_NOT_SHOOTING: {
bossMarineUpdateWeapon();
} break;
case BOSS_MARINE_SHOOTING: {
bossMarineUpdateWeapon();
bossMarineShoot(0.5f, 0.06f, (float)GetRandomValue(-30, 30), &bossMarineGunshotSound, 10, false, MAROON, GOLD);
} break;
case BOSS_MARINE_SHOTGUNNING: {
bossMarineUpdateWeapon();
if (bossMarine.fireCooldown > 0.0f) {
break;
}
for (int i = 0; i < 30; i++) {
(void) i;
float spread = (float)GetRandomValue(-30, 30);
float speed = (float)GetRandomValue(5, 10) / 10.0f * 0.8f;
Projectile *new_projectile = push_projectile();
if (new_projectile == NULL) {
return;
}
*new_projectile = (Projectile) {
.type = PROJECTILE_SQUARED,
.isHurtfulForBoss = false,
.isHurtfulForPlayer = true,
.damage = BOSS_MARINE_BASE_DAMAGE,
.origin = Vector2Add(bossMarine.position, bossMarine.bulletOrigin),
.size = (Vector2) {
.x = BOSS_MARINE_PROJECTILE_RADIUS * 2,
.y = BOSS_MARINE_PROJECTILE_RADIUS * 4,
},
.delta = Vector2Rotate(Vector2Scale((Vector2) {bossMarine.horizontalFlip, 0},
BOSS_MARINE_PROJECTILE_SPEED * speed),
(bossMarine.weaponAngle + spread) * DEG2RAD),
.angle = (bossMarine.weaponAngle + spread + 90),
.inside = MAROON,
.outside = GOLD,
.lifetime = 5.0f,
.canBounce = false,
};
}
PlaySound(bossMarineShotgunSound);
bossMarine.fireCooldown = (float)GetRandomValue(5, 10) / 10.0f;
} break;
case BOSS_MARINE_BOUNCING_WAVES: {
bossMarineUpdateWeapon();
if (bossMarine.fireCooldown > 0.0f) {
break;
}
for (int i = -40; i < 40; i += 2) {
float spread = (float)i;
bossMarineShoot(0.7f,
0,
spread,
NULL,
4.0f,
true,
GOLD,
MAROON);
}
PlaySound(bossMarineShotgunSound);
bossMarine.fireCooldown = (float)GetRandomValue(7, 10) / 10.0f;
} break;
};
}
void updateBossMarine(void) {
if (bossMarine.health <= 0) {
PauseMusicStream(bossMarineMusic);
playerStats.kills += 1;
gameState = GAME_BOSS_DEAD;
for (int i = 0; i < PROJECTILES_MAX; i++) {
if (projectiles[i].type != PROJECTILE_NONE) {
projectiles[i].willBeDestroyed = true;
projectiles[i].destructionTimer = 0.02f;
}
}
return;
}
bossMarine.horizontalFlip =
(player.position.x < bossMarine.position.x)
? -1
: 1;
for (int i = 0; i < BOSS_MARINE_BOUNDING_CIRCLES; i++) {
bossMarine.processedBoundingCircles[i] = bossMarine.boundingCircles[i];
bossMarine.processedBoundingCircles[i].position.x *= bossMarine.horizontalFlip;
}
bossMarineCheckCollisions(true);
bossMarineWalk();
bossMarineAttack();
Vector2 minPos = Vector2Scale((Vector2){bossMarineRect.width / 2, bossMarineRect.width / 2},
SPRITES_SCALE);
Vector2 maxPos = Vector2Subtract((Vector2) {LEVEL_WIDTH, LEVEL_HEIGHT},
minPos);
bossMarine.position = Vector2Clamp(bossMarine.position, minPos, maxPos);
}
void updateMouse(void) {