cub3d/src/parser/parse_map_sprites.c
Quinten 3c4b3803c9 Norm work:
Refactor code for improved readability and maintainability, including function signature updates, new utility functions for score handling, and removal of unused error handling code.
2025-06-10 15:48:59 +02:00

58 lines
1.6 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_map_sprites.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/10 15:45:12 by qmennen #+# #+# */
/* Updated: 2025/06/10 15:47:07 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int count_sprites(char *line)
{
int count;
int i;
count = 0;
i = 0;
while (line[i])
{
if (line[i] >= 'a' && line[i] <= 'z')
count++;
i++;
}
return (count);
}
int parse_map_line_sprites(char *line, t_game *game, int y)
{
int x;
t_map *map;
t_sprite_lib *sprite_lib;
map = game->map;
sprite_lib = map->sprite_lib;
x = 0;
while (line[x])
{
if (line[x] >= 'a' && line[x] <= 'z')
{
if (sprite_lib[line[x] - 'a'].texture == NULL)
{
ft_putstr_fd("Error: Undefined sprite symbol\n", 2);
return (FAILURE);
}
map->sprites[map->n_sprites] = make_sprite(
&sprite_lib[line[x] - 'a'],
(double)x + 0.5f, (double)y + 0.5f);
map->n_sprites++;
}
x++;
}
return (SUCCESS);
}