Particles when dashing
This commit is contained in:
parent
dcca8a348a
commit
8db8e52819
@ -35,7 +35,7 @@ static void _particle_AdvancePart(System_Particle *sys, Particle *p, Duration de
|
||||
Vec2 delta = vec2_Scale(p->vec, duration_Seconds(deltaTime));
|
||||
p->pos = vec2_Add(p->pos, delta);
|
||||
// Move slower
|
||||
Vec2 delta_vec = vec2_Scale(p->vec, -p->vec_friction);
|
||||
Vec2 delta_vec = vec2_Scale(p->vec, -p->vec_friction * duration_Seconds(deltaTime));
|
||||
p->vec = vec2_Add(p->vec, delta_vec);
|
||||
}
|
||||
|
||||
|
42
player.c
42
player.c
@ -8,6 +8,7 @@
|
||||
#include "render_util.h"
|
||||
#include "types.h"
|
||||
#include "util/assert.h"
|
||||
#include "util/rand.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
@ -53,8 +54,6 @@ static double walkSpeed = 300.0, jumpSpeed = 800.0, dashSpeed = 1500.0;
|
||||
static int airjumpCount = 1, airdashCount = 1;
|
||||
static Duration dashLength = {.microseconds = 150000}, dashCooldown = {.microseconds = 400000};
|
||||
|
||||
static Duration emitCooldown = {.microseconds = 200000};
|
||||
static TimePoint lastEmit;
|
||||
|
||||
void player_Advance(System_Player *sys, Duration deltaTime) {
|
||||
if (!sys->player)
|
||||
@ -66,6 +65,34 @@ void player_Advance(System_Player *sys, Duration deltaTime) {
|
||||
if (p->faceDirection != 1 && p->faceDirection != -1)
|
||||
p->faceDirection = 1; // Face right by default
|
||||
|
||||
// Particles
|
||||
static Duration emitCooldown = {.microseconds = 150000};
|
||||
static TimePoint lastEmit = {};
|
||||
if (time_Since(lastEmit).microseconds > emitCooldown.microseconds) {
|
||||
lastEmit = time_Now();
|
||||
Vec2 to_pos = vec2_Add(p->super->position->position, vec2(0, -p->super->hitbox->box.size.y));
|
||||
particle_Emit(
|
||||
sys->super->particle,
|
||||
vec2_Add(vec2_Random(-20, 20, -10, 10), to_pos),
|
||||
vec2(0, -100), 2, 6, 6,
|
||||
duration_FromSeconds(0), &render_ModeDefault);
|
||||
}
|
||||
// Particles when dashing
|
||||
if (time_Since(p->lastDash).microseconds < dashLength.microseconds && dabs(p->super->position->velocity.x) > EPS) {
|
||||
static TimePoint lastDashEmit = {};
|
||||
static Duration cooldown = {.microseconds = 10000};
|
||||
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));
|
||||
particle_Emit(
|
||||
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), 3,
|
||||
duration_FromSeconds(rand_DoubleRange(1.5, 2.0)), &render_ModeInverse);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double targetVecX = 0.0;
|
||||
// Move left/right
|
||||
@ -115,15 +142,4 @@ void player_Advance(System_Player *sys, Duration deltaTime) {
|
||||
// Check OnGround again
|
||||
if (dabs(sys->player->super->position->velocity.y) > EPS)
|
||||
sys->player->onGround = false;
|
||||
|
||||
|
||||
// Particles
|
||||
if (time_Since(lastEmit).microseconds > emitCooldown.microseconds) {
|
||||
lastEmit = time_Now();
|
||||
particle_Emit(
|
||||
sys->super->particle,
|
||||
vec2_Add(p->super->position->position, vec2(0, -p->super->hitbox->box.size.y)),
|
||||
vec2(0, -100), 2, 6, 6,
|
||||
duration_FromSeconds(0), &render_ModeDefault);
|
||||
}
|
||||
}
|
||||
|
@ -7,3 +7,8 @@ double rand_Double01() {
|
||||
// Very bad implementation.
|
||||
return ((double)rand()) / (double)RAND_MAX;
|
||||
}
|
||||
|
||||
|
||||
double rand_DoubleRange(double min, double max) {
|
||||
return min + rand_Double01() * (max - min);
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ extern "C" {
|
||||
// returns a double in the [0,1) range.
|
||||
double rand_Double01();
|
||||
|
||||
double rand_DoubleRange(double min, double max);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user