voleur/minigun.c

39 lines
998 B
C

#include "raylib.h"
#include "raymath.h"
#include "keys.h"
#include "bullet.h"
Texture minigun_texture;
void load_minigun()
{
minigun_texture = LoadTexture("data/minigun.png");
}
float minigun_radius()
{
return fmax(minigun_texture.width, minigun_texture.height)/2;
}
void draw_minigun(Vector2 pos, Camera2D *cam)
{
Texture m = minigun_texture;
Rectangle source = {0, 0, m.width, m.height};
Rectangle dest = {pos.x, pos.y, m.width, m.height};
Vector2 origin = {m.width/2, m.height/2};
float angle = -Vector2LineAngle(pos, GetMousePosition());
angle *= 180/PI;
if (key_down(KC_SHOOT)) {
bullet_spawn(BULLET_MINIGUN, GetScreenToWorld2D(pos, *cam), angle);
int speed = 5;
Vector2 toward = Vector2Normalize((Vector2) {cos(angle * PI/180), sin(angle * PI/180)});
cam->target = Vector2Subtract(GetScreenToWorld2D(pos, *cam), Vector2Scale(toward, speed));
}
DrawTexturePro(m, source, dest, origin, angle + 90, WHITE);
}