ninja hitbox box hit

This commit is contained in:
nemo 2024-09-30 11:02:28 +02:00
parent c43558413c
commit cb3bff4ac5
3 changed files with 32 additions and 1 deletions

2
keys.c
View File

@ -3,6 +3,8 @@
int keys[KC_COUNT] = {
[KC_SHOOT] = MOUSE_BUTTON_LEFT,
[KC_SPECIAL] = MOUSE_BUTTON_RIGHT,
[KC_ULTI] = KEY_R,
[KC_CROUCH] = KEY_LEFT_SHIFT,
[KC_FREECAM] = KEY_F,
};

2
keys.h
View File

@ -9,6 +9,8 @@ typedef enum KeyControl {
KC_LEFT,
KC_RIGHT,
KC_SHOOT,
KC_SPECIAL,
KC_ULTI,
KC_FREECAM,
KC_CROUCH,
KC_COUNT,

29
ninja.c
View File

@ -47,12 +47,37 @@ float ninja_dash_time()
return dash_time;
}
void hit_hitbox(Vector2 pos, float angle)
{
if (dash_time >= EPSILON) {
Vector2 range = {ninja_texture.width, ninja_texture.height};
Vector2 coll[] = {
{ range.x/2, 0},
{ range.x/2, -range.y},
{-range.x/2, -range.y},
{-range.x/2, 0},
{ range.x/2, 0},
{-range.x/2, -range.y},
};
int coll_len = sizeof(coll) / sizeof(*coll);
for (int i = 0; i < coll_len; i++) {
coll[i] = Vector2Rotate(coll[i], angle * PI/180);
}
DrawTriangle((Vector2){ pos.x + coll[0].x, pos.y + coll[0].y },
(Vector2){ pos.x + coll[1].x, pos.y + coll[1].y },
(Vector2){ pos.x + coll[2].x, pos.y + coll[2].y }, VIOLET);
DrawTriangle((Vector2){ pos.x + coll[3].x, pos.y + coll[3].y },
(Vector2){ pos.x + coll[4].x, pos.y + coll[4].y },
(Vector2){ pos.x + coll[5].x, pos.y + coll[5].y }, VIOLET);
}
}
void draw_ninja(Vector2 pos, Camera2D *cam)
{
Vector2 dash = ninja_dash(GetScreenToWorld2D(pos, *cam), GetScreenToWorld2D(GetMousePosition(), *cam), 0.12);
cam->target = Vector2Add(cam->target, dash);
Texture n = ninja_texture;
Texture n = ninja_texture;
Rectangle source = {0, 0, n.width, n.height};
Rectangle dest = {pos.x, pos.y, n.width, n.height};
Vector2 origin = {n.width/2, n.height/2};
@ -60,4 +85,6 @@ void draw_ninja(Vector2 pos, Camera2D *cam)
angle *= 180/PI;
angle += 90;
DrawTexturePro(n, source, dest, origin, angle, WHITE);
hit_hitbox(pos, angle);
}