minigun special attack

This commit is contained in:
nemo 2024-10-11 11:41:38 +02:00
parent eac8f75da8
commit aeb2cf2b23
3 changed files with 27 additions and 10 deletions

2
main.c
View File

@ -125,6 +125,8 @@ int main(void)
Camera2D effect_camera = camera; Camera2D effect_camera = camera;
effect_camera.offset = Vector2Add(effect_camera.offset, cam_shake); effect_camera.offset = Vector2Add(effect_camera.offset, cam_shake);
if (player_type == PLAYER_MINIGUN)
process_minigun(Vector2Add(SCREEN_MIDDLE, cam_shake), &camera, &effect_camera);
BeginMode2D(effect_camera); BeginMode2D(effect_camera);
{ {
DrawTexture(map.texture, map.box.x, map.box.y, WHITE); DrawTexture(map.texture, map.box.x, map.box.y, WHITE);

View File

@ -16,9 +16,29 @@ float minigun_radius()
return fmax(minigun_texture.width, minigun_texture.height)/2; return fmax(minigun_texture.width, minigun_texture.height)/2;
} }
void process_minigun(Vector2 pos, Camera2D *real_cam, Camera2D *effect_cam)
{
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)) {
int speed = 5;
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, speed));
bullet_spawn(BULLET_MINIGUN, Vector2Subtract(world, Vector2Scale(toward, speed*1.0)), angle);
bullet_spawn(BULLET_MINIGUN, Vector2Subtract(world, Vector2Scale(toward, speed*6.0)), angle);
}
}
void draw_minigun(Vector2 pos, Camera2D *cam) void draw_minigun(Vector2 pos, Camera2D *cam)
{ {
(void) cam;
Texture m = minigun_texture; Texture m = minigun_texture;
Rectangle source = {0, 0, m.width, m.height}; Rectangle source = {0, 0, m.width, m.height};
Rectangle dest = {pos.x, pos.y, m.width, m.height}; Rectangle dest = {pos.x, pos.y, m.width, m.height};
@ -26,15 +46,8 @@ void draw_minigun(Vector2 pos, Camera2D *cam)
float angle = -Vector2LineAngle(pos, GetMousePosition()); float angle = -Vector2LineAngle(pos, GetMousePosition());
angle *= 180/PI; angle *= 180/PI;
if (key_down(KC_SHOOT)) { if (key_down(KC_SPECIAL))
int speed = 5; DrawLineEx(pos, GetMousePosition(), 10, RED);
Vector2 world = GetScreenToWorld2D(pos, *cam);
Vector2 toward = Vector2Normalize((Vector2) {cos(angle * PI/180), sin(angle * PI/180)});
cam->target = Vector2Subtract(world, Vector2Scale(toward, speed));
bullet_spawn(BULLET_MINIGUN, Vector2Subtract(world, Vector2Scale(toward, speed*1.0)), angle);
bullet_spawn(BULLET_MINIGUN, Vector2Subtract(world, Vector2Scale(toward, speed*6.0)), angle);
}
DrawTexturePro(m, source, dest, origin, angle + 90, WHITE); DrawTexturePro(m, source, dest, origin, angle + 90, WHITE);
} }

View File

@ -5,6 +5,8 @@ void load_minigun();
float minigun_radius(); float minigun_radius();
void process_minigun(Vector2 pos, Camera2D *real_cam, Camera2D *effect_cam);
void draw_minigun(Vector2 pos, Camera2D *cam); void draw_minigun(Vector2 pos, Camera2D *cam);
float minigun_dash_time(); float minigun_dash_time();