Compare commits

...

4 commits

Author SHA1 Message Date
Theo Champion
6cee6643e4 fix: Fixed memory leak for shooting texture 2025-09-16 16:09:20 +02:00
Theo Champion
ee56e2fdbd feat: added clips for the weapon 2025-09-16 16:07:41 +02:00
Theo Champion
c3cb34c3bb enhancement: Added a nuzzle flash for the gun 2025-09-16 15:59:07 +02:00
Theo Champion
b94e722ab9 feat: Added an aiming point in the hud 2025-09-16 14:19:28 +02:00
7 changed files with 6720 additions and 12 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/15 13:06:07 by tchampio ### ########.fr */
/* Updated: 2025/09/16 15:03:09 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -84,6 +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 16:07:09 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,16 +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 -= 10;
ft_printf("Shooting %p, now at %d HP\n", data->player.aimed_zombie,
data->player.aimed_zombie->health);
data->player.aimed_zombie->health -= 32;
data->player.points += 10;
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);
}
}
@ -75,6 +96,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 16:06:46 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -65,7 +65,10 @@ 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')
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;

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/18 13:05:31 by kcolin #+# #+# */
/* Updated: 2025/09/15 15:39:44 by tchampio ### ########.fr */
/* Updated: 2025/09/16 16:08:40 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -80,4 +80,5 @@ void destroy_hud_textures(t_cub3d_data *data)
while (i < 3)
destroy_texture(data, data->perk_logos[i++]);
destroy_texture(data, data->player.weapon.texture);
destroy_texture(data, data->player.weapon.shoot_texture);
}