From e3ae7b10929cd77236659c551ff1e8942cf1a1f9 Mon Sep 17 00:00:00 2001 From: Quinten Mennen Date: Wed, 28 May 2025 17:08:10 +0200 Subject: [PATCH] add sprite types --- inc/map.h | 16 ++++++++-------- inc/types.h | 12 +++++++++++- src/game/game_hud.c | 2 +- src/main.c | 2 +- src/parser/parse_config_line.c | 8 +++++++- src/parser/parse_map.c | 7 +++---- src/util/initialize.c | 9 ++++----- 7 files changed, 35 insertions(+), 21 deletions(-) diff --git a/inc/map.h b/inc/map.h index a4be9c9..c829674 100644 --- a/inc/map.h +++ b/inc/map.h @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* map.h :+: :+: */ -/* +:+ */ -/* By: whaffman +#+ */ -/* +#+ */ -/* Created: 2025/04/17 19:19:19 by qmennen #+# #+# */ -/* Updated: 2025/05/25 13:39:13 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* map.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/17 19:19:19 by qmennen #+# #+# */ +/* Updated: 2025/05/28 17:07:28 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,6 +26,6 @@ int parse_args(const char *mapfile, t_game *game); t_tile **create_grid(int width, int height); int find_player_or_empty(t_map *map, int *x, int *y); int floodfill(t_map *map, int x, int y); -t_sprite make_sprite(mlx_texture_t *texture, double x, double y, int collectible); +t_sprite make_sprite(t_sprite_lib *def, double x, double y); #endif diff --git a/inc/types.h b/inc/types.h index 067d9ec..af6249b 100644 --- a/inc/types.h +++ b/inc/types.h @@ -6,7 +6,7 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/15 15:52:44 by qmennen #+# #+# */ -/* Updated: 2025/05/28 16:44:33 by qmennen ### ########.fr */ +/* Updated: 2025/05/28 17:04:35 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,6 +24,14 @@ typedef enum TILE TILE_PLAYER = 2, } t_tile; +typedef enum SPRITE_TYPE +{ + SPRITE_TYPE_DEFAULT = 0, + SPRITE_TYPE_COLLECTIBLE = 1, + SPRITE_TYPE_COLLECTED = 2, + SPRITE_TYPE_ENEMY = 3, +} t_sprite_type; + typedef struct s_vec2 { double x; @@ -68,12 +76,14 @@ typedef struct s_sprite int visible; int collectible; mlx_texture_t *texture; + t_sprite_type type; t_vec2 pos; } t_sprite; typedef struct s_sprite_lib { mlx_texture_t *texture; + t_sprite_type type; int collectible; } t_sprite_lib; diff --git a/src/game/game_hud.c b/src/game/game_hud.c index 394d53d..888c1d2 100644 --- a/src/game/game_hud.c +++ b/src/game/game_hud.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/28 14:26:29 by qmennen #+# #+# */ -/* Updated: 2025/05/28 16:03:03 by qmennen ### ########.fr */ +/* Updated: 2025/05/28 17:01:42 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/main.c b/src/main.c index 3ba4a1e..b7bd77d 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/15 16:01:29 by qmennen #+# #+# */ -/* Updated: 2025/05/28 14:24:29 by qmennen ### ########.fr */ +/* Updated: 2025/05/28 17:02:03 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/parser/parse_config_line.c b/src/parser/parse_config_line.c index e1bba70..36e6fc0 100644 --- a/src/parser/parse_config_line.c +++ b/src/parser/parse_config_line.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/22 13:10:06 by whaffman #+# #+# */ -/* Updated: 2025/05/28 16:42:59 by qmennen ### ########.fr */ +/* Updated: 2025/05/28 17:04:39 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -105,9 +105,15 @@ int handle_sprite(char *token, t_map *map) char *texture_path; if (token[1] == 'c') + { sprite.collectible = 1; + sprite.type = SPRITE_TYPE_COLLECTIBLE; + } else + { sprite.collectible = 0; + sprite.type = SPRITE_TYPE_DEFAULT; + } symbol = *ft_strtok(NULL, " "); if (symbol < 'a' || symbol > 'z') return (ft_putstr_fd("Error: Invalid sprite symbol\n", 2), FAILURE); diff --git a/src/parser/parse_map.c b/src/parser/parse_map.c index 775df35..4634813 100644 --- a/src/parser/parse_map.c +++ b/src/parser/parse_map.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/22 13:12:04 by whaffman #+# #+# */ -/* Updated: 2025/05/28 14:34:38 by qmennen ### ########.fr */ +/* Updated: 2025/05/28 17:07:32 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -137,9 +137,8 @@ int parse_map_line_sprites(char *line, t_game *game, int y) return (FAILURE); } map->sprites[map->n_sprites] = make_sprite( - sprite_lib[line[x] - 'a'].texture, - (double)x + 0.5f, (double)y + 0.5f, - sprite_lib[line[x] - 'a'].collectible); + &sprite_lib[line[x] - 'a'], + (double)x + 0.5f, (double)y + 0.5f); map->n_sprites++; } x++; diff --git a/src/util/initialize.c b/src/util/initialize.c index d526ee9..3713a9f 100644 --- a/src/util/initialize.c +++ b/src/util/initialize.c @@ -6,19 +6,18 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/22 17:08:26 by qmennen #+# #+# */ -/* Updated: 2025/05/28 16:44:40 by qmennen ### ########.fr */ +/* Updated: 2025/05/28 17:07:26 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ #include "cub3d.h" -t_sprite make_sprite(mlx_texture_t *texture, double x, double y, - int collectible) +t_sprite make_sprite(t_sprite_lib *def, double x, double y) { t_sprite sprite; ft_memset(&sprite, 0, sizeof(t_sprite)); - sprite.texture = texture; + sprite.texture = def->texture; // if (sprite.texture->width % 64 != 0) // { // ft_putstr_fd("Error: Texture width is not a multiple of 64\n", 2); @@ -34,7 +33,7 @@ t_sprite make_sprite(mlx_texture_t *texture, double x, double y, sprite.pos.x = x; sprite.pos.y = y; sprite.visible = 1; - sprite.collectible = collectible; + sprite.collectible = def->type == SPRITE_TYPE_COLLECTIBLE; return (sprite); }