diff --git a/ninja.c b/ninja.c index b736fd2..20e29fc 100644 --- a/ninja.c +++ b/ninja.c @@ -23,14 +23,15 @@ float ninja_radius() return fmax(ninja_texture.width, ninja_texture.height)/2; } -Vector2 ninja_dash(Vector2 pos, Vector2 to, float sec) +int ninja_dash(Vector2 pos, Vector2 to, float sec, Vector2 *dash) { static Vector2 target = {0}; - Vector2 dash = {0}; + static int attack_type = 0; if (sec <= EPSILON) - return dash; + return attack_type; if (main_attack_cooldown <= EPSILON && key_pressed(KC_SHOOT)) { main_attack_cooldown = sec + 0.069; + attack_type = KC_SHOOT; dash_time = sec; Vector2 diff = Vector2Subtract(to, pos); Vector2 scale = Vector2Normalize(diff); @@ -39,9 +40,10 @@ Vector2 ninja_dash(Vector2 pos, Vector2 to, float sec) scale.y *= dist; target = Vector2Add(pos, scale); } - if (main_attack_cooldown <= EPSILON && key_pressed(KC_ULTI)) { + else if (main_attack_cooldown <= EPSILON && key_pressed(KC_ULTI)) { sec *= 3; main_attack_cooldown = sec + 0.069; + attack_type = KC_ULTI; dash_time = sec; Vector2 diff = Vector2Subtract(to, pos); Vector2 scale = Vector2Normalize(diff); @@ -53,12 +55,14 @@ Vector2 ninja_dash(Vector2 pos, Vector2 to, float sec) 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; + dash->x = Lerp(pos.x, target.x, dt/sec) - pos.x; + dash->y = Lerp(pos.y, target.y, dt/sec) - pos.y; + } else { + attack_type = 0; } if (main_attack_cooldown > EPSILON) main_attack_cooldown -= GetFrameTime(); - return dash; + return attack_type; } float ninja_dash_time() @@ -66,10 +70,11 @@ float ninja_dash_time() return dash_time; } -void hit_hitbox(Vector2 pos, float angle) +void hit_hitbox(Vector2 pos, float angle, float multiplicator) { if (dash_time >= EPSILON) { Vector2 range = {ninja_texture.width, ninja_texture.height}; + range = Vector2Scale(range, multiplicator); Vector2 coll[] = { { range.x/2, 0}, { range.x/2, -range.y}, @@ -93,12 +98,13 @@ void hit_hitbox(Vector2 pos, float angle) void draw_ninja(Vector2 pos, Camera2D *cam) { - Vector2 dash = ninja_dash(GetScreenToWorld2D(pos, *cam), GetScreenToWorld2D(GetMousePosition(), *cam), 0.12); + Vector2 dash = {0}; + int is_attack = ninja_dash(GetScreenToWorld2D(pos, *cam), GetScreenToWorld2D(GetMousePosition(), *cam), 0.12, &dash); cam->target = Vector2Add(cam->target, dash); Texture n; if (dash_time >= EPSILON) - n= ninja_attack_texture; + n = ninja_attack_texture; else n = ninja_texture; @@ -114,5 +120,8 @@ void draw_ninja(Vector2 pos, Camera2D *cam) DrawTexturePro(n, source, dest, origin, angle, WHITE); - // hit_hitbox(pos, angle); + if (is_attack == KC_SHOOT) + hit_hitbox(pos, angle, 1); + else if (is_attack == KC_ULTI) + hit_hitbox(pos, angle, 2); }