From 6e45a0ce118438f8c865c6cb25cb4876b640db10 Mon Sep 17 00:00:00 2001 From: nemo Date: Mon, 30 Sep 2024 15:11:54 +0200 Subject: [PATCH] cooldown main attack --- ninja.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ninja.c b/ninja.c index ae18c13..19e41f8 100644 --- a/ninja.c +++ b/ninja.c @@ -10,6 +10,8 @@ Texture ninja_attack_texture; float dash_time = 0; +float main_attack_cooldown = 0; + void load_ninja() { ninja_texture = LoadTexture("data/ninja.png"); @@ -27,7 +29,8 @@ Vector2 ninja_dash(Vector2 pos, Vector2 to, float sec) Vector2 dash = {0}; if (sec <= EPSILON) return dash; - if (key_pressed(KC_SHOOT)) { + if (main_attack_cooldown <= EPSILON && key_pressed(KC_SHOOT)) { + main_attack_cooldown = sec + 0.069; dash_time = sec; Vector2 diff = Vector2Subtract(to, pos); Vector2 scale = Vector2Normalize(diff); @@ -36,12 +39,14 @@ Vector2 ninja_dash(Vector2 pos, Vector2 to, float sec) scale.y *= dist; target = Vector2Add(pos, scale); } - if (dash_time > 0) { + if (dash_time > EPSILON) { float dt = GetFrameTime(); dash_time -= dt; dash.x = Lerp(pos.x, target.x, dt/sec) - pos.x; dash.y = Lerp(pos.y, target.y, dt/sec) - pos.y; } + if (main_attack_cooldown > EPSILON) + main_attack_cooldown -= GetFrameTime(); return dash; } @@ -93,7 +98,7 @@ void draw_ninja(Vector2 pos, Camera2D *cam) angle *= 180/PI; angle += 90; - if (key_pressed(KC_SPECIAL)) + if (main_attack_cooldown <= EPSILON && key_pressed(KC_SPECIAL)) bullet_spawn(BULLET_SHURIKEN, GetScreenToWorld2D(pos, *cam), angle - 90); DrawTexturePro(n, source, dest, origin, angle, WHITE);