voleur/ninja.c

44 lines
991 B
C
Raw Normal View History

2024-09-27 12:40:28 +02:00
#include "raylib.h"
#include "raymath.h"
#include "stdio.h"
2024-09-27 14:03:07 +02:00
#include "keys.h"
2024-09-27 12:40:28 +02:00
Texture ninja_texture;
void load_ninja()
{
ninja_texture = LoadTexture("data/ninja.png");
}
float ninja_radius()
{
return fmax(ninja_texture.width, ninja_texture.height)/2;
}
2024-09-27 14:03:07 +02:00
Vector2 ninja_dash(Vector2 pos)
{
Vector2 dash = {0};
Vector2 mouse = GetMousePosition();
Vector2 diff = Vector2Subtract(mouse, pos);
dash = Vector2Normalize(diff);
dash.x *= 100;
dash.y *= 100;
return dash;
}
void draw_ninja(Vector2 pos, Camera2D *cam)
2024-09-27 12:40:28 +02:00
{
2024-09-27 14:03:07 +02:00
if (key_pressed(KC_SHOOT))
cam->target = Vector2Add(cam->target, ninja_dash(pos));
2024-09-27 12:40:28 +02:00
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};
float angle = -Vector2LineAngle(pos, GetMousePosition());
angle *= 180/PI;
angle += 90;
DrawTexturePro(n, source, dest, origin, angle, WHITE);
}