From 4933a7c038087ae465e588fafb392a57d7f92b87 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Fri, 9 Dec 2022 21:56:43 +0100 Subject: gun angle --- bullets.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'bullets.c') diff --git a/bullets.c b/bullets.c index dae2a9b..9475729 100644 --- a/bullets.c +++ b/bullets.c @@ -12,8 +12,12 @@ void shoot(platform_window* window) { dirx /= length; diry /= length; - float bulletx = playerx + (get_player_size_in_tile()/2); - float bullety = playery + (get_player_size_in_tile()/2); + #define SPRAY_BOUNDS (0.1f) + dirx += ((float)rand()/(float)(RAND_MAX/SPRAY_BOUNDS)-(SPRAY_BOUNDS/2)); + diry += ((float)rand()/(float)(RAND_MAX/SPRAY_BOUNDS)-(SPRAY_BOUNDS/2)); + + float bulletx = gunx; + float bullety = guny; float bullet_end_point_x = bulletx+dirx*bullet_range; float bullet_end_point_y = bullety+diry*bullet_range; @@ -163,8 +167,13 @@ void draw_bullets(platform_window* window) { map_info info = get_map_info(window); for (int i = 0; i < max_bullets; i++) { + bullets[i].position.x = gunx; + bullets[i].position.y = guny; + bullets[i].position.z = gun_height; bullet b = bullets[i]; if (!b.active) continue; + + if (check_if_bullet_collided_with_ground(&b, window)) { bullets[i].endy = b.endy; -- cgit v1.2.3-70-g09d2