diff --git a/src/consts.h b/src/consts.h index 84f5e96..ce437e1 100644 --- a/src/consts.h +++ b/src/consts.h @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:54:36 by kcolin #+# #+# */ -/* Updated: 2025/08/12 14:49:36 by tchampio ### ########.fr */ +/* Updated: 2025/08/14 21:23:25 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,6 +35,10 @@ // Sprite consts # define SPRITE_TRANPARENCY_COLOR 0xff00dc # define MAX_SPRITES 30 +# define JUGG_TEX "ressources/juggernog.xpm" +# define REV_TEX "ressources/revive.xpm" +# define DBLTAP_TEX "ressources/doubletap.xpm" +# define MYSTERY_TEX "ressources/box.xpm" # ifdef BONUS # define COMPILED_TEXT "Compiled with bonuses" @@ -48,5 +52,12 @@ # define EMALMAP "Map is malformed (invalid chars or missing walls)" # define ENOPLAYER "No player" # define EHOLES "Holes in map" +# define ETRAILING "Trailing chars after map" +# define EBADCHARCOLOR "invalid characters in color definition" +# define EBADVALCOLOR "invalid value for colors" +# define ETOOMANYCOLORS "too many colors" +# define ENOTENOUGHCOLORS "Not enough colors" +# define EDUPTEX "Duplicated texture directive" +# define EMAPBFTEX "Map started before all the textures" #endif diff --git a/src/cub3d_data.h b/src/cub3d_data.h index aff808c..1993a16 100644 --- a/src/cub3d_data.h +++ b/src/cub3d_data.h @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:59:37 by kcolin #+# #+# */ -/* Updated: 2025/08/11 11:59:21 by tchampio ### ########.fr */ +/* Updated: 2025/08/14 21:36:15 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,6 +40,7 @@ typedef struct s_cub3d_data int delta; int last_tick; t_sprite **sprite_list; + int sprite_counter; double zbuffer[WIDTH]; int sprite_order[MAX_SPRITES]; double sprite_distances[MAX_SPRITES]; diff --git a/src/map/populate_map.c b/src/map/populate_map.c index e35240e..4caa366 100644 --- a/src/map/populate_map.c +++ b/src/map/populate_map.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:44:02 by kcolin #+# #+# */ -/* Updated: 2025/07/23 13:34:33 by kcolin ### ########.fr */ +/* Updated: 2025/08/14 19:46:26 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,7 +70,7 @@ bool populate_maps(t_mapdata *map, int fd) { if (line[0] != '\n' && end_reached) { - ft_strlcpy(map->error, "Trailing chars after map", ERRLEN); + ft_strlcpy(map->error, ETRAILING, ERRLEN); retvalue = false; } if (line[0] != '\n') diff --git a/src/map/setters.c b/src/map/setters.c index 0a82082..c3c003d 100644 --- a/src/map/setters.c +++ b/src/map/setters.c @@ -6,12 +6,13 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/06/21 19:35:43 by tchampio #+# #+# */ -/* Updated: 2025/07/31 14:08:27 by kcolin ### ########.fr */ +/* Updated: 2025/08/14 19:50:20 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ #include "../../libft/includes/libft.h" #include "../utils/frees.h" +#include "../consts.h" #include "mapdata.h" bool perform_color_checks(int *color, char *strcolor, t_mapdata *map) @@ -24,8 +25,7 @@ bool perform_color_checks(int *color, char *strcolor, t_mapdata *map) { if (!ft_isdigit(strcolor[i])) { - ft_strlcpy(map->error, "invalid characters in color definition", - ERRLEN); + ft_strlcpy(map->error, EBADCHARCOLOR, ERRLEN); return (false); } i++; @@ -33,7 +33,7 @@ bool perform_color_checks(int *color, char *strcolor, t_mapdata *map) colorvalue = ft_atoi(strcolor); if (colorvalue < 0 || colorvalue > 255) { - ft_strlcpy(map->error, "invalid value for colors", ERRLEN); + ft_strlcpy(map->error, EBADVALCOLOR, ERRLEN); return (false); } *color = colorvalue; @@ -53,14 +53,14 @@ unsigned int set_color(const char *s, t_mapdata *map) while (tab[i]) { if (i > 2) - ft_strlcpy(map->error, "too many colors", ERRLEN); + ft_strlcpy(map->error, ETOOMANYCOLORS, ERRLEN); isok = perform_color_checks(&rgb[i], tab[i], map); free(tab[i]); i++; } free(tab); if (i <= 2) - return (ft_strlcpy(map->error, "Not enough colors", ERRLEN), 0); + return (ft_strlcpy(map->error, ENOTENOUGHCOLORS, ERRLEN), 0); if (!isok) return (0); finalcolor = ((rgb[0] & 0xff) << 16) @@ -77,7 +77,7 @@ int try_set_texture(t_mapdata *map, char **texture, char *texture_name) { if (*texture != NULL) { - ft_strlcpy(map->error, "Duplicated texture directive", ERRLEN); + ft_strlcpy(map->error, EDUPTEX, ERRLEN); return (2); } *texture = ft_strdup(texture_name); @@ -99,7 +99,7 @@ int set_textures(char *line, t_mapdata *map) tab = ft_split(line, ' '); if (tab[0][0] == '1') return (free_tab(tab), ft_strlcpy(map->error, - "Map started before all the textures", ERRLEN), 1); + EMAPBFTEX, ERRLEN), 1); retvalue = 0; if (tab[0] && tab[1]) { diff --git a/src/sprites/create_sprite.c b/src/sprites/create_sprite.c index 1bea488..b55299f 100644 --- a/src/sprites/create_sprite.c +++ b/src/sprites/create_sprite.c @@ -6,7 +6,7 @@ /* By: tchampio +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/08/12 15:43:19 by tchampio #+# #+# */ -/* Updated: 2025/08/12 16:14:27 by tchampio ### ########.fr */ +/* Updated: 2025/08/14 21:24:03 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,15 +34,15 @@ t_sprite *place_right_sprite(t_cub3d_data *data, char c, double x, double y) t_sprite *sprite; if (c == 'M') - sprite = create_sprite(data, "ressources/box.xpm", x + 0.5, y + 0.5); + sprite = create_sprite(data, MYSTERY_TEX, x + 0.5, y + 0.5); if (c == 'Q') sprite = create_sprite(data, - "ressources/revive.xpm", x + 0.5, y + 0.5); + REV_TEX, x + 0.5, y + 0.5); if (c == 'J') sprite = create_sprite(data, - "ressources/juggernog.xpm", x + 0.5, y + 0.5); + JUGG_TEX, x + 0.5, y + 0.5); if (c == 'D') sprite = create_sprite(data, - "ressources/doubletap.xpm", x + 0.5, y + 0.5); + DBLTAP_TEX, x + 0.5, y + 0.5); return (sprite); } diff --git a/src/utils/inits.c b/src/utils/inits.c index d904b41..ebc3a11 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/08/12 16:13:50 by tchampio ### ########.fr */ +/* Updated: 2025/08/14 21:45:19 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -58,10 +58,8 @@ void place_base_sprites(t_cub3d_data *data, char **map) { int y; int x; - int c; y = 0; - c = 0; while (y < data->map->mapheight) { x = 0; @@ -69,8 +67,11 @@ void place_base_sprites(t_cub3d_data *data, char **map) { if (map[y][x] == 'M' || map[y][x] == 'Q' || map[y][x] == 'J' || map[y][x] == 'D') - data->sprite_list[c++] = place_right_sprite(data, - map[y][x], x, y); + { + if (data->sprite_counter < MAX_SPRITES) + data->sprite_list[data->sprite_counter++] + = place_right_sprite(data, map[y][x], x, y); + } x++; } y++;