enhancement: Added a nuzzle flash for the gun

This commit is contained in:
Theo Champion 2025-09-16 15:59:07 +02:00
parent b94e722ab9
commit c3cb34c3bb
6 changed files with 6695 additions and 8 deletions

File diff suppressed because it is too large Load diff

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:59:37 by kcolin #+# #+# */
/* Updated: 2025/09/10 15:58:56 by tchampio ### ########.fr */
/* Updated: 2025/09/16 15:13:28 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -39,6 +39,7 @@ typedef struct s_cub3d_data
t_player player;
t_keypresses keypresses;
int *screen_matrix;
int last_since_shoot; // temp
int delta;
int last_tick;
t_sprite **sprite_list;

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/08 17:27:12 by tchampio #+# #+# */
/* Updated: 2025/09/16 11:28:56 by tchampio ### ########.fr */
/* Updated: 2025/09/16 15:03:09 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -84,7 +84,11 @@ void create_hud(t_cub3d_data *data)
draw_points(data);
draw_perks(data);
draw_round(data);
matrix_image_put(data, data->player.weapon.texture,
WIDTH / 2, HEIGHT - 175);
if (data->player.weapon.is_shooting)
matrix_image_put(data, data->player.weapon.shoot_texture,
WIDTH / 2, HEIGHT - 175);
else
matrix_image_put(data, data->player.weapon.texture,
WIDTH / 2, HEIGHT - 175);
matrix_set(data, WIDTH / 2, HEIGHT / 2, 0x0000FF00);
}

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
/* Updated: 2025/09/15 15:45:27 by tchampio ### ########.fr */
/* Updated: 2025/09/16 15:15:08 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -39,6 +39,7 @@ void kill_zombie(t_cub3d_data *data, t_sprite *zombie_ptr)
mlx_destroy_image(data->mlx, zombie_ptr->image->img);
free(zombie_ptr->image);
zombie_ptr->sprite_type = DEAD_ZOMBIE;
data->player.points += 60;
}
void handle_shooting(t_cub3d_data *data)
@ -47,9 +48,12 @@ void handle_shooting(t_cub3d_data *data)
{
if (!data->player.weapon.is_auto)
data->keypresses.is_space_pressed = false;
data->player.weapon.is_shooting = true;
data->last_since_shoot = get_milliseconds();
if (data->player.aimed_zombie)
{
data->player.aimed_zombie->health -= 10;
data->player.aimed_zombie->health -= 32;
data->player.points += 10;
ft_printf("Shooting %p, now at %d HP\n", data->player.aimed_zombie,
data->player.aimed_zombie->health);
if (data->player.aimed_zombie->health <= 0)
@ -75,6 +79,11 @@ int game_loop(t_cub3d_data *data)
raycaster(data, &ray);
sprite_caster(data);
create_hud(data);
if (data->player.weapon.is_shooting)
{
if (get_milliseconds() - data->last_since_shoot > 7000)
data->player.weapon.is_shooting = false;
}
matrix_to_image(data);
mlx_put_image_to_window(data->mlx, data->mlx_win,
data->img_data->img, 0, 0);

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/06 11:29:14 by kcolin #+# #+# */
/* Updated: 2025/09/10 15:58:32 by tchampio ### ########.fr */
/* Updated: 2025/09/16 14:59:49 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -66,6 +66,7 @@ void init_player(t_cub3d_data *data, t_player *player, t_mapdata *map)
ft_bzero(player->perk_order, 3);
ft_bzero(&player->weapon, sizeof(t_weapon));
player->weapon.texture = load_hud_texture(data, "ressources/weapon.xpm");
player->weapon.shoot_texture = load_hud_texture(data, "ressources/weapon_shooting.xpm");
if (dir == 'N' || dir == 'S')
init_lon(player, dir);
else

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 15:51:29 by kcolin #+# #+# */
/* Updated: 2025/09/15 13:18:49 by tchampio ### ########.fr */
/* Updated: 2025/09/16 15:01:18 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -36,6 +36,8 @@ typedef struct s_weapon
t_img_data *texture;
t_img_data *shoot_texture;
bool is_auto;
bool is_shooting;
bool reloading;
int clip;
int remaining_ammos;
} t_weapon;