-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayer.cpp
More file actions
569 lines (512 loc) · 23.4 KB
/
Copy pathPlayer.cpp
File metadata and controls
569 lines (512 loc) · 23.4 KB
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
#include "Player.h"
#include "Effects.h"
#include "SpriteManager.h"
#include <algorithm>
#include <cmath>
void Player::ResetForNewGame() {
pos = {240, 560};
lives = 3;
bombs = 3;
score = 0;
weaponLevel = 1;
weapon = WeaponType::Vulcan;
invulnerable = false;
invulnTimer = 0.0f;
shootTimer_ = 0.0f;
isDemo = false;
triggerBomb_ = false;
animationTime = 0.0f;
tilt_ = 0.0f;
muzzleFlashTimer_ = 0.0f;
recoilOffset_ = 0.0f;
recoilVel_ = 0.0f;
scaleY_ = 1.0f;
scaleYVel_ = 0.0f;
heat_ = 0.0f;
pointerControlActive_ = false;
pointerIdleTimer_ = 0.0f;
positionCount_ = 0;
for (int i = 0; i < 8; ++i) pastPositions_[i] = pos;
}
void Player::ResetAfterHit() {
pos = {240, 560};
invulnerable = true;
invulnTimer = 2.0f;
weaponLevel = std::max(1, weaponLevel - 1);
triggerBomb_ = false;
tilt_ = 0.0f;
muzzleFlashTimer_ = 0.0f;
recoilOffset_ = 0.0f;
recoilVel_ = 0.0f;
scaleY_ = 1.0f;
scaleYVel_ = 0.0f;
heat_ = 0.0f;
pointerControlActive_ = false;
pointerIdleTimer_ = 0.0f;
positionCount_ = 0;
for (int i = 0; i < 8; ++i) pastPositions_[i] = pos;
}
void Player::Update(float dt, Effects& effects, const std::vector<Enemy>& enemies, const std::vector<Bullet>& enemyBullets) {
Vector2 dir{0, 0};
if (isDemo) {
// Simple AI logic
float targetX = 240.0f;
const Enemy* closestEnemy = nullptr;
float minDist = 999999.0f;
for (const auto& e : enemies) {
if (!e.active) continue;
float dy = pos.y - e.pos.y;
if (dy > 0) { // Enemy is above player
float dist = std::abs(e.pos.x - pos.x) + dy;
if (dist < minDist) {
minDist = dist;
closestEnemy = &e;
}
}
}
if (closestEnemy) {
targetX = closestEnemy->pos.x;
}
// Steer horizontally to target
if (pos.x < targetX - 6.0f) dir.x += 1.0f;
else if (pos.x > targetX + 6.0f) dir.x -= 1.0f;
// Try to hover around y = 520
if (pos.y < 500.0f) dir.y += 0.5f;
else if (pos.y > 540.0f) dir.y -= 0.5f;
// Dodge bullets
bool bulletVeryClose = false;
for (const auto& b : enemyBullets) {
if (!b.active) continue;
float dx = pos.x - b.pos.x;
float dy = pos.y - b.pos.y;
float distSq = dx * dx + dy * dy;
if (distSq < 96.0f * 96.0f) {
float dist = std::sqrt(distSq);
if (dist > 0.001f) {
float force = (96.0f - dist) / 96.0f;
dir.x += (dx / dist) * force * 3.2f;
dir.y += (dy / dist) * force * 3.2f;
}
if (distSq < 38.0f * 38.0f) {
bulletVeryClose = true;
}
}
}
// Trigger bomb if in severe danger
if (bulletVeryClose && bombs > 0 && !invulnerable) {
triggerBomb_ = true;
}
} else {
// Keyboard movement
if (controlLayout == 0) {
if (IsKeyDown(KEY_LEFT)) dir.x -= 1;
if (IsKeyDown(KEY_RIGHT)) dir.x += 1;
if (IsKeyDown(KEY_UP)) dir.y -= 1;
if (IsKeyDown(KEY_DOWN)) dir.y += 1;
} else {
if (IsKeyDown(KEY_A)) dir.x -= 1;
if (IsKeyDown(KEY_D)) dir.x += 1;
if (IsKeyDown(KEY_W)) dir.y -= 1;
if (IsKeyDown(KEY_S)) dir.y += 1;
}
// Gamepad movement
if (IsGamepadAvailable(0)) {
float gdx = GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X);
float gdy = GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_Y);
if (std::abs(gdx) > 0.2f) dir.x += gdx;
if (std::abs(gdy) > 0.2f) dir.y += gdy;
if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_LEFT_FACE_LEFT)) dir.x -= 1;
if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_LEFT_FACE_RIGHT)) dir.x += 1;
if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_LEFT_FACE_UP)) dir.y -= 1;
if (IsGamepadButtonDown(0, GAMEPAD_BUTTON_LEFT_FACE_DOWN)) dir.y += 1;
}
}
int touchCount = GetTouchPointCount();
bool mousePointerDown = IsMouseButtonDown(MOUSE_BUTTON_LEFT);
bool touchPointerDown = touchCount == 1;
bool pointerDown = !isDemo && (mousePointerDown || touchPointerDown);
Vector2 pointerPos = mousePointerDown ? GetMousePosition() : (touchPointerDown ? GetTouchPosition(0) : pos);
bool pointerSteering = pointerDown && pointerPos.y > 86.0f;
bool pointerApplied = false;
if (pointerSteering) {
pointerControlActive_ = true;
pointerIdleTimer_ = 0.0f;
Vector2 target = { pointerPos.x, pointerPos.y - 74.0f };
target.x = std::clamp(target.x, 26.0f, 454.0f);
target.y = std::clamp(target.y, 92.0f, 586.0f);
Vector2 delta = { target.x - pos.x, target.y - pos.y };
float dist = std::sqrt(delta.x * delta.x + delta.y * delta.y);
if (dist > 0.85f) {
float responsiveness = dist > 96.0f ? 33.0f : 25.0f;
float blend = 1.0f - std::exp(-responsiveness * dt);
Vector2 step = { delta.x * blend, delta.y * blend };
float stepLen = std::sqrt(step.x * step.x + step.y * step.y);
float maxStep = (dist > 96.0f ? 520.0f : 430.0f) * dt;
if (stepLen > maxStep && stepLen > 0.001f) {
step.x = step.x / stepLen * maxStep;
step.y = step.y / stepLen * maxStep;
stepLen = maxStep;
}
pos.x = std::clamp(pos.x + step.x, 28.0f, 452.0f);
pos.y = std::clamp(pos.y + step.y, 92.0f, 586.0f);
if (stepLen > 0.001f) {
dir.x = step.x / stepLen;
dir.y = step.y / stepLen;
}
pointerApplied = true;
} else {
dir = {0.0f, 0.0f};
pointerApplied = true;
}
} else if (!pointerDown && pointerControlActive_) {
pointerIdleTimer_ += dt;
if (pointerIdleTimer_ > 0.20f) pointerControlActive_ = false;
}
if (dir.x != 0 || dir.y != 0) {
float len = std::sqrt(dir.x * dir.x + dir.y * dir.y);
dir.x /= len; dir.y /= len;
}
bool focusMode = !isDemo && (IsKeyDown(KEY_LEFT_SHIFT) || (IsGamepadAvailable(0) && (IsGamepadButtonDown(0, GAMEPAD_BUTTON_RIGHT_TRIGGER_1) || IsGamepadButtonDown(0, GAMEPAD_BUTTON_LEFT_TRIGGER_1))));
if (!pointerApplied) {
float speed = focusMode ? 158.0f : 268.0f;
pos.x = std::clamp(pos.x + dir.x * speed * dt, 28.0f, 452.0f);
pos.y = std::clamp(pos.y + dir.y * speed * dt, 92.0f, 586.0f);
}
shootTimer_ = std::max(0.0f, shootTimer_ - dt);
animationTime += dt;
if (invulnerable) {
invulnTimer -= dt;
if (invulnTimer <= 0.0f) { invulnerable = false; invulnTimer = 0.0f; }
}
// Update coordinates history for ghost trails
for (int i = 7; i > 0; --i) {
pastPositions_[i] = pastPositions_[i - 1];
}
pastPositions_[0] = pos;
if (positionCount_ < 8) positionCount_++;
// Momentum-Based Banking (exponential drag interpolation)
float targetTilt = dir.x * 2.18f;
float tiltSpeed = (dir.x == 0.0f) ? 26.0f : 19.0f;
float tiltBlend = 1.0f - std::exp(-tiltSpeed * dt);
tilt_ += (targetTilt - tilt_) * tiltBlend;
if (muzzleFlashTimer_ > 0.0f) {
muzzleFlashTimer_ -= dt;
}
// Physical Spring-Damper Recoil Physics
// Recoil offset spring system (target: 0.0f)
float recoilK = 300.0f;
float recoilDamping = 31.0f;
float recoilForce = -recoilK * recoilOffset_ - recoilDamping * recoilVel_;
recoilVel_ += recoilForce * dt;
recoilOffset_ += recoilVel_ * dt;
recoilOffset_ = std::min(recoilOffset_, 5.5f);
if (recoilOffset_ < 0.0f) {
recoilOffset_ = 0.0f;
recoilVel_ = 0.0f;
}
// scaleY_ spring system (target: 1.0f)
float scaleK = 455.0f;
float scaleDamping = 28.0f;
float scaleForce = -scaleK * (scaleY_ - 1.0f) - scaleDamping * scaleYVel_;
scaleYVel_ += scaleForce * dt;
scaleY_ += scaleYVel_ * dt;
scaleY_ = std::clamp(scaleY_, 0.88f, 1.08f);
// Decay wing vent heat
heat_ = std::max(0.0f, heat_ - 1.8f * dt);
if (heat_ > 0.2f && GetRandomValue(0, 100) < (int)(heat_ * 38)) {
effects.Spark({ pos.x - 14.0f + GetRandomValue(-2, 2), pos.y + 2.0f }, ORANGE, {dir.x * -100.0f, 40.0f});
effects.Spark({ pos.x + 14.0f + GetRandomValue(-2, 2), pos.y + 2.0f }, ORANGE, {dir.x * -100.0f, 40.0f});
}
// Spawn procedural vectored engine exhaust particles
if (GetRandomValue(0, 100) < 32) {
Color thrusterColor = focusMode ? SKYBLUE : (GetRandomValue(0, 1) == 0 ? ORANGE : GOLD);
// Calculate dynamic vectored exhaust direction based on ship movement and roll tilt
// Plumes tilt opposite to movement direction and banking angle
float tiltExhaustX = -tilt_ * 30.0f - dir.x * 50.0f;
float exhaustY = focusMode ? 32.0f : (dir.y < 0.0f ? 110.0f : 68.0f);
// Asymmetric plume speeds depending on left/right banking
float leftThrustMult = 1.0f;
float rightThrustMult = 1.0f;
if (dir.x < 0.0f) { rightThrustMult = 1.35f; leftThrustMult = 0.65f; }
else if (dir.x > 0.0f) { leftThrustMult = 1.35f; rightThrustMult = 0.65f; }
if (dir.y < 0.0f) { leftThrustMult *= 1.25f; rightThrustMult *= 1.25f; }
effects.EngineExhaust({ pos.x - 6.0f, pos.y + 9.0f }, thrusterColor, { tiltExhaustX - 10.0f, exhaustY * leftThrustMult });
effects.EngineExhaust({ pos.x + 6.0f, pos.y + 9.0f }, thrusterColor, { tiltExhaustX + 10.0f, exhaustY * rightThrustMult });
}
}
void Player::TryShoot(std::vector<Bullet>& bullets) {
bool shootPressed = isDemo || IsWindowFocused();
if (!shootPressed) {
if (controlLayout == 0) {
shootPressed = IsKeyDown(KEY_Z) || IsKeyDown(KEY_SPACE);
} else {
shootPressed = IsKeyDown(KEY_J) || IsKeyDown(KEY_SPACE);
}
if (IsGamepadAvailable(0)) {
shootPressed = shootPressed || IsGamepadButtonDown(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN) || IsGamepadButtonDown(0, GAMEPAD_BUTTON_RIGHT_FACE_LEFT);
}
}
if (!shootPressed || shootTimer_ > 0.0f) return;
int level = std::clamp(weaponLevel, 1, 4);
if (weapon == WeaponType::Vulcan) {
recoilVel_ += 88.0f;
scaleYVel_ -= 4.8f;
heat_ = std::min(1.0f, heat_ + 0.05f);
muzzleFlashTimer_ = 0.04f;
shootTimer_ = 0.098f;
bullets.emplace_back(Vector2{pos.x, pos.y - 18}, Vector2{0, -520}, 4, 1, BulletOwner::Player, YELLOW);
if (level >= 2) {
bullets.emplace_back(Vector2{pos.x - 10, pos.y - 10}, Vector2{-65, -500}, 4, 1, BulletOwner::Player, GOLD);
bullets.emplace_back(Vector2{pos.x + 10, pos.y - 10}, Vector2{65, -500}, 4, 1, BulletOwner::Player, GOLD);
}
if (level >= 4) {
bullets.emplace_back(Vector2{pos.x - 16, pos.y}, Vector2{-130, -470}, 4, 1, BulletOwner::Player, ORANGE);
bullets.emplace_back(Vector2{pos.x + 16, pos.y}, Vector2{130, -470}, 4, 1, BulletOwner::Player, ORANGE);
}
} else if (weapon == WeaponType::Plasma) {
recoilVel_ += 270.0f;
scaleYVel_ -= 15.5f;
heat_ = std::min(1.0f, heat_ + 0.20f);
muzzleFlashTimer_ = 0.08f;
shootTimer_ = 0.16f;
bullets.emplace_back(Vector2{pos.x, pos.y - 20}, Vector2{0, -390}, 8 + level, 2, BulletOwner::Player, SKYBLUE);
if (level >= 2) {
bullets.emplace_back(Vector2{pos.x - 18, pos.y - 8}, Vector2{-90, -345}, 7, 1, BulletOwner::Player, BLUE);
bullets.emplace_back(Vector2{pos.x + 18, pos.y - 8}, Vector2{90, -345}, 7, 1, BulletOwner::Player, BLUE);
}
} else {
recoilVel_ += 166.0f;
scaleYVel_ -= 9.5f;
heat_ = std::min(1.0f, heat_ + 0.12f);
muzzleFlashTimer_ = 0.06f;
shootTimer_ = 0.20f;
bullets.emplace_back(Vector2{pos.x, pos.y - 18}, Vector2{0, -440}, 4, 1, BulletOwner::Player, LIME);
bullets.emplace_back(Vector2{pos.x - 15, pos.y}, Vector2{-45, -260}, 6, 2, BulletOwner::Player, GREEN, true);
if (level >= 3) bullets.emplace_back(Vector2{pos.x + 15, pos.y}, Vector2{45, -260}, 6, 2, BulletOwner::Player, GREEN, true);
}
}
bool Player::BombPressed() const {
bool bombPressed = false;
if (isDemo) {
bombPressed = triggerBomb_;
} else {
if (controlLayout == 0) {
bombPressed = IsKeyPressed(KEY_X);
} else {
bombPressed = IsKeyPressed(KEY_K);
}
if (IsGamepadAvailable(0)) {
bombPressed = bombPressed || IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT);
}
static bool twoFingerWasDown = false;
bool twoFingerDown = GetTouchPointCount() >= 2;
bombPressed = bombPressed || IsMouseButtonPressed(MOUSE_BUTTON_RIGHT) || (twoFingerDown && !twoFingerWasDown);
twoFingerWasDown = twoFingerDown;
}
return bombPressed;
}
bool Player::TryBomb() {
if (!BombPressed() || bombs <= 0) return false;
--bombs;
invulnerable = true;
invulnTimer = 1.1f;
triggerBomb_ = false;
return true;
}
void Player::NextWeapon() {
if (weapon == WeaponType::Vulcan) weapon = WeaponType::Plasma;
else if (weapon == WeaponType::Plasma) weapon = WeaponType::Missile;
else weapon = WeaponType::Vulcan;
}
void Player::UpgradeWeapon() { weaponLevel = std::min(4, weaponLevel + 1); }
const char* Player::WeaponName() const {
if (weapon == WeaponType::Vulcan) return "VULCAN";
if (weapon == WeaponType::Plasma) return "PLASMA";
return "MISSILE";
}
void Player::Draw(bool debug) const {
bool blink = invulnerable && ((int)(invulnTimer * 12) % 2 == 0);
Vector2 drawPos = { pos.x, pos.y + recoilOffset_ };
Color tint = WHITE;
if (invulnerable && invulnTimer > 1.2f) {
// Glitch state visual offset & red shift
drawPos.x += (float)GetRandomValue(-20, 20) / 10.0f;
tint = (GetRandomValue(0, 1) == 0) ? Color{255, 60, 60, 255} : Color{255, 255, 255, 120};
}
// 1. Engine thrusters plume flickering
bool focusMode = !isDemo && (IsKeyDown(KEY_LEFT_SHIFT) || (IsGamepadAvailable(0) && (IsGamepadButtonDown(0, GAMEPAD_BUTTON_RIGHT_TRIGGER_1) || IsGamepadButtonDown(0, GAMEPAD_BUTTON_LEFT_TRIGGER_1))));
float plumeBase = 1.0f + 0.35f * std::sin(animationTime * 48.0f);
float leftPlumeScale = plumeBase;
float rightPlumeScale = plumeBase;
float dx = 0.0f;
float dy = 0.0f;
if (positionCount_ >= 2) {
dx = pos.x - pastPositions_[1].x;
dy = pos.y - pastPositions_[1].y;
}
if (dy < -0.1f) {
leftPlumeScale *= 1.35f;
rightPlumeScale *= 1.35f;
} else if (dy > 0.1f) {
leftPlumeScale *= 0.6f;
rightPlumeScale *= 0.6f;
}
if (dx < -0.1f) {
rightPlumeScale *= 1.3f;
leftPlumeScale *= 0.7f;
} else if (dx > 0.1f) {
leftPlumeScale *= 1.3f;
rightPlumeScale *= 0.7f;
}
if (focusMode) {
leftPlumeScale *= 0.75f;
rightPlumeScale *= 0.75f;
}
float tiltOffset = -tilt_ * 3.2f;
if (!blink) {
Color plumeColor1 = focusMode ? Color{0, 150, 255, 148} : Color{78, 214, 255, 168};
Color plumeColor2 = focusMode ? Color{100, 220, 255, 205} : Color{190, 126, 255, 205};
Color glowColor = focusMode ? SKYBLUE : Color{82, 230, 255, 255};
// Emissive engine exhaust bloom (additive circular gradients)
BeginBlendMode(BLEND_ADDITIVE);
DrawCircleGradient((int)(drawPos.x - 6.0f), (int)(drawPos.y + 11.0f), 10.5f * leftPlumeScale, Fade(glowColor, 0.34f), Fade(BLACK, 0.0f));
DrawCircleGradient((int)(drawPos.x + 6.0f), (int)(drawPos.y + 11.0f), 10.5f * rightPlumeScale, Fade(glowColor, 0.34f), Fade(BLACK, 0.0f));
EndBlendMode();
// Draw left nozzle plume
DrawTriangle(
{drawPos.x - 6.0f, drawPos.y + 11.0f},
{drawPos.x - 6.0f + tiltOffset, drawPos.y + 11.0f + 14.0f * leftPlumeScale},
{drawPos.x - 4.0f, drawPos.y + 11.0f},
plumeColor1
);
DrawTriangle(
{drawPos.x - 5.5f, drawPos.y + 11.0f},
{drawPos.x - 5.5f + tiltOffset, drawPos.y + 11.0f + 8.0f * leftPlumeScale},
{drawPos.x - 4.5f, drawPos.y + 11.0f},
plumeColor2
);
// Draw right nozzle plume
DrawTriangle(
{drawPos.x + 6.0f, drawPos.y + 11.0f},
{drawPos.x + 4.0f, drawPos.y + 11.0f},
{drawPos.x + 6.0f + tiltOffset, drawPos.y + 11.0f + 14.0f * rightPlumeScale},
plumeColor1
);
DrawTriangle(
{drawPos.x + 5.5f, drawPos.y + 11.0f},
{drawPos.x + 4.5f, drawPos.y + 11.0f},
{drawPos.x + 5.5f + tiltOffset, drawPos.y + 11.0f + 8.0f * rightPlumeScale},
plumeColor2
);
}
// 1b. Ghost afterimage trails
float moveSq = dx * dx + dy * dy;
if (!blink && !focusMode && moveSq > 1.2f) {
BeginBlendMode(BLEND_ADDITIVE);
for (int i = 1; i < 4; ++i) {
int idx = i * 2;
if (idx >= positionCount_) break;
Vector2 ghostPos = pastPositions_[idx];
float speedAlpha = std::clamp(moveSq / 20.0f, 0.35f, 1.0f);
float alpha = (0.23f - (float)i * 0.055f) * speedAlpha;
if (alpha <= 0.0f) continue;
SpriteId spriteId = SpriteId::PlayerIdle;
if (tilt_ < -1.1f) spriteId = SpriteId::PlayerLeft;
else if (tilt_ < -0.3f) spriteId = SpriteId::PlayerSoftLeft;
else if (tilt_ > 1.1f) spriteId = SpriteId::PlayerRight;
else if (tilt_ > 0.3f) spriteId = SpriteId::PlayerSoftRight;
Texture2D tex = SpriteManager::Instance().GetTexture(spriteId);
if (tex.id != 0) {
Rectangle src = { 0, 0, (float)tex.width, (float)tex.height };
Rectangle dest = { ghostPos.x, ghostPos.y + recoilOffset_, (float)tex.width * 1.5f, (float)tex.height * 1.5f * scaleY_ };
Vector2 origin = { (float)tex.width * 1.5f / 2.0f, (float)tex.height * 1.5f * scaleY_ / 2.0f };
Color trailColor = Fade(i == 1 ? Color{88, 226, 255, 255} : Color{174, 116, 255, 255}, alpha);
SpriteManager::Instance().DrawRect(spriteId, src, dest, origin, 0.0f, trailColor);
DrawLineEx({ghostPos.x, ghostPos.y + 8.0f}, {ghostPos.x - 11.0f, ghostPos.y + 20.0f}, 1.4f, Fade(Color{88, 226, 255, 255}, alpha * 0.75f));
DrawLineEx({ghostPos.x, ghostPos.y + 8.0f}, {ghostPos.x + 11.0f, ghostPos.y + 20.0f}, 1.4f, Fade(Color{174, 116, 255, 255}, alpha * 0.75f));
}
}
EndBlendMode();
}
// 2. Render Player Ship Sprite with 5 Banking States and Recoil Squash
if (!blink) {
SpriteId spriteId = SpriteId::PlayerIdle;
if (tilt_ < -1.1f) spriteId = SpriteId::PlayerLeft;
else if (tilt_ < -0.3f) spriteId = SpriteId::PlayerSoftLeft;
else if (tilt_ > 1.1f) spriteId = SpriteId::PlayerRight;
else if (tilt_ > 0.3f) spriteId = SpriteId::PlayerSoftRight;
Texture2D tex = SpriteManager::Instance().GetTexture(spriteId);
if (tex.id != 0) {
Rectangle src = { 0, 0, (float)tex.width, (float)tex.height };
Rectangle dest = { drawPos.x, drawPos.y, (float)tex.width * 1.5f, (float)tex.height * 1.5f * scaleY_ };
Vector2 origin = { (float)tex.width * 1.5f / 2.0f, (float)tex.height * 1.5f * scaleY_ / 2.0f };
SpriteManager::Instance().DrawRect(spriteId, src, dest, origin, 0.0f, tint);
}
// Additive glowing canopy cockpit lighting
BeginBlendMode(BLEND_ADDITIVE);
float pulseCyan = 0.5f + 0.5f * std::sin(animationTime * 12.0f);
Vector2 canopyPos = { drawPos.x, drawPos.y - 9.0f * scaleY_ };
DrawCircleGradient((int)canopyPos.x, (int)canopyPos.y, 6.0f + 2.5f * pulseCyan, Fade(SKYBLUE, 0.55f * (0.6f + 0.4f * pulseCyan)), Fade(BLACK, 0.0f));
DrawCircleV(canopyPos, 2.0f, Fade(WHITE, 0.7f));
EndBlendMode();
// Low-health critical warning pulse
if (lives == 1) {
float alertPulse = 0.5f + 0.5f * std::sin(animationTime * 16.0f);
DrawCircleLines((int)drawPos.x, (int)drawPos.y, 22.0f, Fade(RED, alertPulse * 0.7f));
}
}
// 3. Render Muzzle Flashes
if (muzzleFlashTimer_ > 0.0f) {
SpriteId flashId = SpriteId::MuzzleVulcan;
if (weapon == WeaponType::Plasma) flashId = SpriteId::MuzzlePlasma;
else if (weapon == WeaponType::Missile) flashId = SpriteId::MuzzleMissile;
int level = std::clamp(weaponLevel, 1, 4);
if (weapon == WeaponType::Vulcan) {
SpriteManager::Instance().Draw(flashId, {drawPos.x, drawPos.y - 18}, 0.0f, 1.2f);
if (level >= 2) {
SpriteManager::Instance().Draw(flashId, {drawPos.x - 10, drawPos.y - 10}, -15.0f, 1.0f);
SpriteManager::Instance().Draw(flashId, {drawPos.x + 10, drawPos.y - 10}, 15.0f, 1.0f);
}
if (level >= 4) {
SpriteManager::Instance().Draw(flashId, {drawPos.x - 16, drawPos.y}, -30.0f, 1.0f);
SpriteManager::Instance().Draw(flashId, {drawPos.x + 16, drawPos.y}, 30.0f, 1.0f);
}
} else if (weapon == WeaponType::Plasma) {
SpriteManager::Instance().Draw(flashId, {drawPos.x, drawPos.y - 20}, 0.0f, 1.4f);
if (level >= 2) {
SpriteManager::Instance().Draw(flashId, {drawPos.x - 18, drawPos.y - 8}, -20.0f, 1.1f);
SpriteManager::Instance().Draw(flashId, {drawPos.x + 18, drawPos.y - 8}, 20.0f, 1.1f);
}
} else { // Missile
SpriteManager::Instance().Draw(flashId, {drawPos.x, drawPos.y - 18}, 0.0f, 1.2f);
SpriteManager::Instance().Draw(flashId, {drawPos.x - 15, drawPos.y}, -10.0f, 1.0f);
if (level >= 3) {
SpriteManager::Instance().Draw(flashId, {drawPos.x + 15, drawPos.y}, 10.0f, 1.0f);
}
}
}
// 4. Render Invulnerability Shield Bubble (with electric arcing)
if (invulnerable) {
float scale = 1.35f + 0.12f * std::sin(animationTime * 20.0f);
SpriteManager::Instance().Draw(SpriteId::ShieldBubble, drawPos, animationTime * 180.0f, scale, Fade(SKYBLUE, 0.75f));
// Additive electric shimmer rings and arcs
BeginBlendMode(BLEND_ADDITIVE);
float pulseRadius = 14.0f + 16.0f * fmodf(animationTime * 1.5f, 1.0f);
DrawCircleLines((int)drawPos.x, (int)drawPos.y, pulseRadius, Fade(SKYBLUE, 1.0f - (pulseRadius - 14.0f) / 16.0f));
for (int i = 0; i < 3; ++i) {
float angle1 = (float)GetRandomValue(0, 360) * DEG2RAD;
float angle2 = angle1 + (float)GetRandomValue(20, 50) * DEG2RAD;
float r = spriteRadius * (1.1f + 0.2f * std::sin(animationTime * 35.0f));
Vector2 p1 = { drawPos.x + std::cos(angle1) * r, drawPos.y + std::sin(angle1) * r };
Vector2 p2 = { drawPos.x + std::cos(angle2) * r, drawPos.y + std::sin(angle2) * r };
DrawLineV(p1, p2, Fade(WHITE, 0.75f));
}
EndBlendMode();
}
// Always render small visible red hitbox point
DrawCircleV(drawPos, hitRadius, RED);
if (debug) {
DrawCircleLines((int)pos.x, (int)pos.y, spriteRadius, GREEN);
DrawCircleLines((int)pos.x, (int)pos.y, hitRadius, RED);
}
}