From a0f20b396ca7dfa6c0e4ed623f5b8c8028ab83e4 Mon Sep 17 00:00:00 2001 From: Theo Champion Date: Mon, 8 Sep 2025 17:33:05 +0200 Subject: [PATCH] norme: fixed norme issues --- Makefile | 1 + src/hud/hud.c | 88 ++++++++++++++++++++++++++++++++++++++++++ src/hud/hud.h | 20 ++++++++++ src/hud/load_texture.c | 26 ++++++++----- src/main.c | 76 +----------------------------------- src/utils/inits.c | 12 +++--- 6 files changed, 134 insertions(+), 89 deletions(-) create mode 100644 src/hud/hud.c create mode 100644 src/hud/hud.h diff --git a/Makefile b/Makefile index 2217473..d28974d 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ IFLAGS = -I./mlx -I./libft SOURCEFILES = \ src/hud/load_texture.c \ + src/hud/hud.c \ src/utils/inits.c \ src/utils/time.c \ src/utils/destroy_utils.c \ diff --git a/src/hud/hud.c b/src/hud/hud.c new file mode 100644 index 0000000..1153c54 --- /dev/null +++ b/src/hud/hud.c @@ -0,0 +1,88 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* hud.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tchampio +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/09/08 17:27:12 by tchampio #+# #+# */ +/* Updated: 2025/09/08 17:32:39 by tchampio ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../cub3d_data.h" +#include "../../libft/includes/libft.h" +#include "../renderer/render.h" + +void draw_points(t_cub3d_data *data) +{ + char points_str[11]; + int i; + int horizontalpos; + + ft_itoa_static(data->player.points, points_str, 11); + i = 0; + horizontalpos = 170; + while (i < (int)ft_strlen(points_str)) + { + matrix_image_put(data, data->point_figures[points_str[i] - '0'], + WIDTH - horizontalpos, HEIGHT / 2); + horizontalpos -= 25; + i++; + } +} + +void draw_perks(t_cub3d_data *data) +{ + int i; + int perk_pos; + + i = 0; + perk_pos = 50; + while (i < 3) + { + if (data->player.perk_order[i] != NONE) + { + if (data->player.perk_order[i] == REVIVE) + matrix_image_put(data, data->perk_logos[1], perk_pos, HEIGHT + - 200); + else if (data->player.perk_order[i] == JUGGERNOG) + matrix_image_put(data, data->perk_logos[0], perk_pos, HEIGHT + - 200); + else if (data->player.perk_order[i] == DOUBLETAP) + matrix_image_put(data, data->perk_logos[2], perk_pos, HEIGHT + - 200); + perk_pos += 50; + } + i++; + } +} + +void draw_round(t_cub3d_data *data) +{ + int i; + int pos; + char round_str[5]; + + if (data->round <= 5) + return (matrix_image_put(data, data->tally_marks[data->round - 1], 20, + HEIGHT - 85)); + pos = 20; + i = 0; + ft_itoa_static(data->round, round_str, 5); + while (round_str[i]) + { + matrix_image_put(data, data->round_figures[round_str[i] - '0'], pos, + HEIGHT - 85); + pos += 50; + i++; + } +} + +void create_hud(t_cub3d_data *data) +{ + draw_points(data); + draw_perks(data); + draw_round(data); + matrix_image_put(data, data->gun, WIDTH / 2, HEIGHT - 175); +} diff --git a/src/hud/hud.h b/src/hud/hud.h new file mode 100644 index 0000000..59e511f --- /dev/null +++ b/src/hud/hud.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* hud.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tchampio +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/09/08 17:28:57 by tchampio #+# #+# */ +/* Updated: 2025/09/08 17:29:54 by tchampio ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef HUD_H +# define HUD_H + +# include "../cub3d_data.h" + +void create_hud(t_cub3d_data *data); + +#endif // HUD_H diff --git a/src/hud/load_texture.c b/src/hud/load_texture.c index 87e0bd7..feefcd2 100644 --- a/src/hud/load_texture.c +++ b/src/hud/load_texture.c @@ -6,7 +6,7 @@ /* By: tchampio +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/09/03 17:02:08 by tchampio #+# #+# */ -/* Updated: 2025/09/05 20:26:20 by tchampio ### ########.fr */ +/* Updated: 2025/09/08 17:25:53 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,16 +71,24 @@ void load_round_indicators(t_cub3d_data *data) data->tally_marks[2] = load_hud_texture(data, "ressources/tally_three.xpm"); data->tally_marks[1] = load_hud_texture(data, "ressources/tally_two.xpm"); data->tally_marks[0] = load_hud_texture(data, "ressources/tally_one.xpm"); - data->round_figures[0] = load_hud_texture(data, "ressources/round_zero.xpm"); + data->round_figures[0] = load_hud_texture(data, + "ressources/round_zero.xpm"); data->round_figures[1] = load_hud_texture(data, "ressources/round_one.xpm"); data->round_figures[2] = load_hud_texture(data, "ressources/round_two.xpm"); - data->round_figures[3] = load_hud_texture(data, "ressources/round_three.xpm"); - data->round_figures[4] = load_hud_texture(data, "ressources/round_four.xpm"); - data->round_figures[5] = load_hud_texture(data, "ressources/round_five.xpm"); - data->round_figures[6] = load_hud_texture(data, "ressources/round_six.xpm"); - data->round_figures[7] = load_hud_texture(data, "ressources/round_seven.xpm"); - data->round_figures[8] = load_hud_texture(data, "ressources/round_eight.xpm"); - data->round_figures[9] = load_hud_texture(data, "ressources/round_nine.xpm"); + data->round_figures[3] = load_hud_texture(data, + "ressources/round_three.xpm"); + data->round_figures[4] = load_hud_texture(data, + "ressources/round_four.xpm"); + data->round_figures[5] = load_hud_texture(data, + "ressources/round_five.xpm"); + data->round_figures[6] = load_hud_texture(data, + "ressources/round_six.xpm"); + data->round_figures[7] = load_hud_texture(data, + "ressources/round_seven.xpm"); + data->round_figures[8] = load_hud_texture(data, + "ressources/round_eight.xpm"); + data->round_figures[9] = load_hud_texture(data, + "ressources/round_nine.xpm"); } void load_textures(t_cub3d_data *data) diff --git a/src/main.c b/src/main.c index 669c43d..232a174 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */ -/* Updated: 2025/09/08 13:56:27 by tchampio ### ########.fr */ +/* Updated: 2025/09/08 17:30:24 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,6 @@ #include "utils/frees.h" #include "utils/hooks.h" #include "utils/inits.h" -#include "draw/drawutils.h" #include #include #include @@ -33,78 +32,7 @@ #include #include "utils/time.h" #include "sprites/move_sprites.h" - -void draw_points(t_cub3d_data *data) -{ - char points_str[11]; - int i; - int horizontalpos; - - ft_itoa_static(data->player.points, points_str, 11); - i = 0; - horizontalpos = 170; - while (i < (int)ft_strlen(points_str)) - { - matrix_image_put(data, data->point_figures[points_str[i] - '0'], WIDTH - horizontalpos, HEIGHT / 2); - horizontalpos -= 25; - i++; - } -} - -void draw_perks(t_cub3d_data *data) -{ - int i; - int perk_pos; - - i = 0; - perk_pos = 50; - while (i < 3) - { - if (data->player.perk_order[i] != NONE) - { - if (data->player.perk_order[i] == REVIVE) - matrix_image_put(data, data->perk_logos[1], perk_pos, HEIGHT - 200); - else if (data->player.perk_order[i] == JUGGERNOG) - matrix_image_put(data, data->perk_logos[0], perk_pos, HEIGHT - 200); - else if (data->player.perk_order[i] == DOUBLETAP) - matrix_image_put(data, data->perk_logos[2], perk_pos, HEIGHT - 200); - perk_pos += 50; - } - i++; - } -} - -void draw_round(t_cub3d_data *data) -{ - int i; - int pos; - char round_str[5]; - - if (data->round <= 5) - return (matrix_image_put(data, data->tally_marks[data->round - 1], 20, HEIGHT - 85)); - pos = 20; - i = 0; - ft_itoa_static(data->round, round_str, 5); - while (round_str[i]) - { - matrix_image_put(data, data->round_figures[round_str[i] - '0'], pos, HEIGHT - 85); - pos += 50; - i++; - } -} - -void create_hud(t_cub3d_data *data) -{ - // draw points - draw_points(data); - // draw perks - draw_perks(data); - // draw round - draw_round(data); - // draw weapon - matrix_image_put(data, data->gun, WIDTH / 2, HEIGHT - 175); - // draw map -} +#include "hud/hud.h" int game_loop(t_cub3d_data *data) { diff --git a/src/utils/inits.c b/src/utils/inits.c index d886db0..bb298be 100644 --- a/src/utils/inits.c +++ b/src/utils/inits.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/31 13:43:05 by kcolin #+# #+# */ -/* Updated: 2025/09/03 17:53:41 by tchampio ### ########.fr */ +/* Updated: 2025/09/08 17:26:11 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,11 +33,11 @@ t_img_data *load_single_texture(t_cub3d_data *data, char *path) ft_printf("Error: failed to open image at %s\n", path); destroy(data, 1); } -// if (width != height || width != TEXTURE_SIZE) -// { -// ft_printf("Error: textures are not the right size\n"); -// destroy(data, 1); -// } + if (width != height || width != TEXTURE_SIZE) + { + ft_printf("Error: textures are not the right size\n"); + destroy(data, 1); + } ft_printf("image: %p\n", img); img_data = ft_calloc(sizeof(t_img_data), 1); img_data->img = img;