feat: added clips for the weapon

This commit is contained in:
Theo Champion 2025-09-16 16:07:41 +02:00
parent c3cb34c3bb
commit ee56e2fdbd
2 changed files with 24 additions and 5 deletions

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
/* Updated: 2025/09/16 15:15:08 by tchampio ### ########.fr */
/* Updated: 2025/09/16 16:07:09 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -48,19 +48,36 @@ void handle_shooting(t_cub3d_data *data)
{
if (!data->player.weapon.is_auto)
data->keypresses.is_space_pressed = false;
if (data->player.weapon.clip <= 0)
return ;
data->player.weapon.is_shooting = true;
data->last_since_shoot = get_milliseconds();
data->player.weapon.clip--;
if (data->player.weapon.clip == 0)
{
ft_printf("reloading\n");
if (data->player.weapon.remaining_ammos < 8)
{
data->player.weapon.clip = data->player.weapon.remaining_ammos;
data->player.weapon.remaining_ammos = 0;
}
else
{
data->player.weapon.clip = 8;
data->player.weapon.remaining_ammos -= 8;
}
}
if (data->player.aimed_zombie)
{
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);
ft_printf("Shooting %p, now at %d HP %d/%d\n", data->player.aimed_zombie,
data->player.aimed_zombie->health, data->player.weapon.clip, data->player.weapon.remaining_ammos);
if (data->player.aimed_zombie->health <= 0)
kill_zombie(data, data->player.aimed_zombie);
}
else
ft_printf("Shoot!\n");
ft_printf("Shoot! %d/%d\n", data->player.weapon.clip, data->player.weapon.remaining_ammos);
}
}

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/06 11:29:14 by kcolin #+# #+# */
/* Updated: 2025/09/16 14:59:49 by tchampio ### ########.fr */
/* Updated: 2025/09/16 16:06:46 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -65,6 +65,8 @@ void init_player(t_cub3d_data *data, t_player *player, t_mapdata *map)
player->points = 500;
ft_bzero(player->perk_order, 3);
ft_bzero(&player->weapon, sizeof(t_weapon));
player->weapon.clip = 8;
player->weapon.remaining_ammos = 35;
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')