Tweak player jumping logic & particles when jumping

This commit is contained in:
Edgaru089 2024-03-30 15:54:00 +08:00
parent 203f54f76c
commit 21201ac367

View File

@ -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 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}; static Duration dashLength = {.microseconds = 150000}, dashCooldown = {.microseconds = 400000};
@ -80,7 +80,7 @@ void player_Advance(System_Player *sys, Duration deltaTime) {
// Particles when dashing // Particles when dashing
if (time_Since(p->lastDash).microseconds < dashLength.microseconds && dabs(p->super->position->velocity.x) > EPS) { if (time_Since(p->lastDash).microseconds < dashLength.microseconds && dabs(p->super->position->velocity.x) > EPS) {
static TimePoint lastDashEmit = {.microseconds = 0}; static TimePoint lastDashEmit = {.microseconds = 0};
static Duration cooldown = {.microseconds = 8000}; static Duration cooldown = {.microseconds = 4000};
if (time_Since(lastDashEmit).microseconds > cooldown.microseconds) { if (time_Since(lastDashEmit).microseconds > cooldown.microseconds) {
lastDashEmit = time_Now(); lastDashEmit = time_Now();
Vec2 to_pos = vec2_Add(p->super->position->position, vec2(0, -p->super->hitbox->box.size.y / 2.0)); 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, sys->super->particle,
vec2_Add(vec2_Random(-5, 5, -30, 30), to_pos), vec2_Add(vec2_Random(-5, 5, -30, 30), to_pos),
vec2(rand_DoubleRange(650, 700) * -p->faceDirection, rand_DoubleRange(-100, 100)), vec2(rand_DoubleRange(650, 700) * -p->faceDirection, rand_DoubleRange(-100, 100)),
7, rand_DoubleRange(10, 16), 4, 7, rand_DoubleRange(14, 20), rand_DoubleRange(32, 40),
duration_FromSeconds(rand_DoubleRange(4.0, 5.0)), &render_ModeRotate); duration_FromSeconds(0), &render_ModeRotate);
} }
} }
@ -116,6 +116,13 @@ void player_Advance(System_Player *sys, Duration deltaTime) {
p->storedSpeedY = -jumpSpeed; p->storedSpeedY = -jumpSpeed;
if (!p->onGround) // Took the second clause, airjumped if (!p->onGround) // Took the second clause, airjumped
p->jumpCount++; 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,9 +141,14 @@ void player_Advance(System_Player *sys, Duration deltaTime) {
p->super->position->velocity.x += p->faceDirection * dashSpeed; p->super->position->velocity.x += p->faceDirection * dashSpeed;
p->super->position->velocity.y = 0; p->super->position->velocity.y = 0;
} else { // Release the stored Y speed } else { // Release the stored Y speed
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; p->super->position->velocity.y += p->storedSpeedY;
else
p->super->position->velocity.y = p->storedSpeedY;
p->storedSpeedY = 0; p->storedSpeedY = 0;
} }
}
// Check OnGround again // Check OnGround again