voleur/minigun.c

70 lines
2.0 KiB
C
Raw Normal View History

2024-10-08 10:41:21 +02:00
#include "raylib.h"
#include "raymath.h"
#include "keys.h"
#include "bullet.h"
Texture minigun_texture;
#define DEFAULT_BACK_SPEED 5
float back_speed = DEFAULT_BACK_SPEED;
2024-10-08 10:41:21 +02:00
void load_minigun()
{
minigun_texture = LoadTexture("data/minigun.png");
}
float minigun_radius()
{
return fmax(minigun_texture.width, minigun_texture.height)/2;
}
2024-10-11 11:41:38 +02:00
void process_minigun(Vector2 pos, Camera2D *real_cam, Camera2D *effect_cam)
2024-10-08 10:41:21 +02:00
{
2024-10-11 11:41:38 +02:00
if (key_down(KC_SPECIAL)) {
int force = 5;
effect_cam->offset.x += GetRandomValue(-force/2, force/2);
effect_cam->offset.y += GetRandomValue(-force/2, force/2);
}
else if (key_down(KC_SHOOT)) {
back_speed += GetFrameTime() * 1.2;
if (back_speed >= 25)
back_speed = 25;
2024-10-11 11:41:38 +02:00
float angle = -Vector2LineAngle(pos, GetMousePosition());
angle *= 180/PI;
Vector2 world = GetScreenToWorld2D(pos, *real_cam);
Vector2 toward = Vector2Normalize((Vector2) {cos(angle * PI/180), sin(angle * PI/180)});
real_cam->target = Vector2Subtract(world, Vector2Scale(toward, back_speed));
2024-10-11 11:41:38 +02:00
2024-10-28 17:43:14 +01:00
Vector2 b1 = Vector2Scale(toward, 5*1.0);
Vector2 b2 = Vector2Scale(toward, 5*6.0);
b1.x += GetRandomValue(-7, 7);
b1.y += GetRandomValue(-7, 7);
b2.x += GetRandomValue(-7, 7);
b2.y += GetRandomValue(-7, 7);
bullet_spawn(BULLET_MINIGUN, Vector2Subtract(world, b1), angle);
bullet_spawn(BULLET_MINIGUN, Vector2Subtract(world, b2), angle);
}
if (key_down(KC_SPECIAL) || !key_down(KC_SHOOT)) {
back_speed = DEFAULT_BACK_SPEED;
2024-10-11 11:41:38 +02:00
}
}
2024-10-08 10:41:21 +02:00
2024-10-11 11:41:38 +02:00
void draw_minigun(Vector2 pos, Camera2D *cam)
{
(void) cam;
2024-10-08 10:41:21 +02:00
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;
2024-10-11 11:41:38 +02:00
if (key_down(KC_SPECIAL))
DrawLineEx(pos, GetMousePosition(), 10, RED);
2024-10-08 10:41:21 +02:00
DrawTexturePro(m, source, dest, origin, angle + 90, WHITE);
}