44 lines
991 B
C
44 lines
991 B
C
#include "raylib.h"
|
|
#include "raymath.h"
|
|
#include "stdio.h"
|
|
|
|
#include "keys.h"
|
|
|
|
Texture ninja_texture;
|
|
|
|
void load_ninja()
|
|
{
|
|
ninja_texture = LoadTexture("data/ninja.png");
|
|
}
|
|
|
|
float ninja_radius()
|
|
{
|
|
return fmax(ninja_texture.width, ninja_texture.height)/2;
|
|
}
|
|
|
|
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)
|
|
{
|
|
if (key_pressed(KC_SHOOT))
|
|
cam->target = Vector2Add(cam->target, ninja_dash(pos));
|
|
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);
|
|
}
|