From 21201ac367a0067665c0bf15ecda3a66b8a3ccc4 Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Sat, 30 Mar 2024 15:54:00 +0800 Subject: [PATCH] Tweak player jumping logic & particles when jumping --- player.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/player.c b/player.c index c71b809..5e6a95b 100644 --- a/player.c +++ b/player.c @@ -51,7 +51,7 @@ void player_DeleteEntity(System_Player *sys, uintptr_t id) { static double walkSpeed = 300.0, jumpSpeed = 800.0, dashSpeed = 1500.0; -static int airjumpCount = 1, airdashCount = 1; +static int airjumpCount = 1, airdashCount = 1, airjumpParticleCount = 10; static Duration dashLength = {.microseconds = 150000}, dashCooldown = {.microseconds = 400000}; @@ -80,7 +80,7 @@ void player_Advance(System_Player *sys, Duration deltaTime) { // Particles when dashing if (time_Since(p->lastDash).microseconds < dashLength.microseconds && dabs(p->super->position->velocity.x) > EPS) { static TimePoint lastDashEmit = {.microseconds = 0}; - static Duration cooldown = {.microseconds = 8000}; + static Duration cooldown = {.microseconds = 4000}; if (time_Since(lastDashEmit).microseconds > cooldown.microseconds) { lastDashEmit = time_Now(); Vec2 to_pos = vec2_Add(p->super->position->position, vec2(0, -p->super->hitbox->box.size.y / 2.0)); @@ -88,8 +88,8 @@ void player_Advance(System_Player *sys, Duration deltaTime) { sys->super->particle, vec2_Add(vec2_Random(-5, 5, -30, 30), to_pos), vec2(rand_DoubleRange(650, 700) * -p->faceDirection, rand_DoubleRange(-100, 100)), - 7, rand_DoubleRange(10, 16), 4, - duration_FromSeconds(rand_DoubleRange(4.0, 5.0)), &render_ModeRotate); + 7, rand_DoubleRange(14, 20), rand_DoubleRange(32, 40), + duration_FromSeconds(0), &render_ModeRotate); } } @@ -116,6 +116,13 @@ void player_Advance(System_Player *sys, Duration deltaTime) { p->storedSpeedY = -jumpSpeed; if (!p->onGround) // Took the second clause, airjumped p->jumpCount++; + // Particles fly up if on ground, down if airjumped + for (int i = 0; i < airjumpParticleCount; i++) + particle_Emit( + sys->super->particle, + vec2_Add(vec2_Random(-20, 20, -5, 5), p->super->position->position), + (p->onGround) ? vec2(rand_DoubleRange(-50, 50), -100) : vec2(0, 200), 2, rand_DoubleRange(8, 12), 20, + duration_FromSeconds(0), &render_ModeRotate); } } @@ -134,8 +141,13 @@ void player_Advance(System_Player *sys, Duration deltaTime) { p->super->position->velocity.x += p->faceDirection * dashSpeed; p->super->position->velocity.y = 0; } else { // Release the stored Y speed - p->super->position->velocity.y += p->storedSpeedY; - p->storedSpeedY = 0; + if (dabs(p->storedSpeedY) > EPS) { + if (p->super->position->velocity.y < 0 && p->super->position->velocity.y > p->storedSpeedY) + p->super->position->velocity.y += p->storedSpeedY; + else + p->super->position->velocity.y = p->storedSpeedY; + p->storedSpeedY = 0; + } }