From 6112da75f973b1099fa95fcd9d3113c00302f5b4 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Wed, 8 Jan 2025 10:46:14 +0100 Subject: player bullet working --- game/player/PlayerScript.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'game/player/PlayerScript.cpp') diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index 8372080..96a0552 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -17,6 +17,7 @@ void PlayerScript::init() { subscribe([this](const CollisionEvent & ev) -> bool { return this->on_collision(ev); }); + this->last_fired = std::chrono::steady_clock::now(); } bool PlayerScript::on_collision(const CollisionEvent & ev) { BehaviorScript & play_scr = this->get_components_by_name("player").front(); @@ -86,7 +87,13 @@ void PlayerScript::fixed_update(crepe::duration_t dt) { }); } if(this->get_key_state(Keycode::ENTER)){ - this->shoot(transform.position,0); + + auto now = std::chrono::steady_clock::now(); + std::chrono::duration elapsed = now - last_fired; + if (elapsed > shot_delay) { + this->shoot(transform.position,0); + last_fired = now; + } } if (this->get_key_state(Keycode::SPACE)) { rb.add_force_linear(vec2(0, -PLAYER_GRAVITY_SCALE / 2.5) * dt.count() / 0.02); -- cgit v1.2.3