Compare commits

...

3 Commits

Author SHA1 Message Date
nemo 4ae6c3fdfb ninja ulti scale hitbox attack 2024-10-01 15:16:38 +02:00
nemo 2b6326c803 ninja ulti 2024-10-01 14:57:17 +02:00
nemo 9a0afc9941 smaller shuriken 2024-10-01 14:19:54 +02:00
4 changed files with 30 additions and 10 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 400 B

After

Width:  |  Height:  |  Size: 297 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 400 B

38
ninja.c
View File

@ -23,14 +23,15 @@ float ninja_radius()
return fmax(ninja_texture.width, ninja_texture.height)/2; 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}; static Vector2 target = {0};
Vector2 dash = {0}; static int attack_type = 0;
if (sec <= EPSILON) if (sec <= EPSILON)
return dash; return attack_type;
if (main_attack_cooldown <= EPSILON && key_pressed(KC_SHOOT)) { if (main_attack_cooldown <= EPSILON && key_pressed(KC_SHOOT)) {
main_attack_cooldown = sec + 0.069; main_attack_cooldown = sec + 0.069;
attack_type = KC_SHOOT;
dash_time = sec; dash_time = sec;
Vector2 diff = Vector2Subtract(to, pos); Vector2 diff = Vector2Subtract(to, pos);
Vector2 scale = Vector2Normalize(diff); Vector2 scale = Vector2Normalize(diff);
@ -39,15 +40,29 @@ Vector2 ninja_dash(Vector2 pos, Vector2 to, float sec)
scale.y *= dist; scale.y *= dist;
target = Vector2Add(pos, scale); target = Vector2Add(pos, scale);
} }
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);
int dist = 400;
scale.x *= dist;
scale.y *= dist;
target = Vector2Add(pos, scale);
}
if (dash_time > EPSILON) { if (dash_time > EPSILON) {
float dt = GetFrameTime(); float dt = GetFrameTime();
dash_time -= dt; dash_time -= dt;
dash.x = Lerp(pos.x, target.x, dt/sec) - pos.x; dash->x = Lerp(pos.x, target.x, dt/sec) - pos.x;
dash.y = Lerp(pos.y, target.y, dt/sec) - pos.y; dash->y = Lerp(pos.y, target.y, dt/sec) - pos.y;
} else {
attack_type = 0;
} }
if (main_attack_cooldown > EPSILON) if (main_attack_cooldown > EPSILON)
main_attack_cooldown -= GetFrameTime(); main_attack_cooldown -= GetFrameTime();
return dash; return attack_type;
} }
float ninja_dash_time() float ninja_dash_time()
@ -55,10 +70,11 @@ float ninja_dash_time()
return 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) { if (dash_time >= EPSILON) {
Vector2 range = {ninja_texture.width, ninja_texture.height}; Vector2 range = {ninja_texture.width, ninja_texture.height};
range = Vector2Scale(range, multiplicator);
Vector2 coll[] = { Vector2 coll[] = {
{ range.x/2, 0}, { range.x/2, 0},
{ range.x/2, -range.y}, { range.x/2, -range.y},
@ -82,7 +98,8 @@ void hit_hitbox(Vector2 pos, float angle)
void draw_ninja(Vector2 pos, Camera2D *cam) 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); cam->target = Vector2Add(cam->target, dash);
Texture n; Texture n;
@ -103,5 +120,8 @@ void draw_ninja(Vector2 pos, Camera2D *cam)
DrawTexturePro(n, source, dest, origin, angle, WHITE); 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);
} }