cooldown main attack
This commit is contained in:
parent
db592bdb70
commit
6e45a0ce11
11
ninja.c
11
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);
|
||||
|
|
Loading…
Reference in New Issue