diff --git a/Makefile b/Makefile index 5786535..2eed4a3 100644 --- a/Makefile +++ b/Makefile @@ -30,11 +30,7 @@ fclean: clean bonus: CFLAGS += -D BONUS=1 -bonus: $(OBJECTS) - $(MAKE) -C mlx/ - $(MAKE) -C libft/ - cp libft/libft.a . - $(CC) $(CFLAGS) $(OBJECTS) -o $(NAME) -L. -lft -Lmlx -lmlx -lz -lXext -lX11 +bonus: re re: fclean all diff --git a/includes/structs.h b/includes/structs.h index 4145950..bfafec5 100644 --- a/includes/structs.h +++ b/includes/structs.h @@ -6,7 +6,7 @@ /* By: tchampio +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/06/21 19:46:20 by tchampio #+# #+# */ -/* Updated: 2025/06/25 17:52:35 by tchampio ### ########.fr */ + /* */ /* ************************************************************************** */ @@ -52,12 +52,21 @@ typedef struct s_mapdata char error[1024]; } t_mapdata; +typedef struct s_player +{ + float x; + float y; + double yaw; + int health; +} t_player; + typedef struct s_cub3d_data { void *mlx; void *mlx_win; t_mlx_data *mlx_data; t_mapdata *map; + t_player player; } t_cub3d_data; #endif diff --git a/ressources/good_maps/testmap_bonus.cub b/ressources/good_maps/testmap_bonus.cub index 4769d16..3038d01 100644 --- a/ressources/good_maps/testmap_bonus.cub +++ b/ressources/good_maps/testmap_bonus.cub @@ -9,7 +9,7 @@ C 225,30,0 1111111111111111111111111 100000000011000Z000000001 1011000001110000000000001 - 1001000000d000z0000000001 + 1001000000d00000000000001 111111111011000001110000000000001 10000000001100000111011111D111111 11110111111111011100000010001 diff --git a/src/main.c b/src/main.c index 5a763d3..81115fc 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: tchampio map[i][j]) { if (map->map[i][j] == '1') - draw_2d_wall(map->f_color, data, 20, 20 * j, 20 * i); + draw_2d_wall(map->f_color, data, 20 * j, 20 * i); else if (map->map[i][j] == 'Z' || map->map[i][j] == 'z') - draw_2d_wall(0x0008D9D6, data, 20, 20 * j, 20 * i); + draw_2d_wall(0x0008D9D6, data, 20 * j, 20 * i); else if (map->map[i][j] == 'D' || map->map[i][j] == 'd') - draw_2d_wall(0x00FF2E63, data, 20, 20 * j, 20 * i); + draw_2d_wall(0x00FF2E63, data, 20 * j, 20 * i); else if (map->map[i][j] == 's') - draw_2d_wall(0x00E84545, data, 20, 20 * j, 20 * i); + draw_2d_wall(0x00E84545, data, 20 * j, 20 * i); else if (map->map[i][j] == 'M') - draw_2d_wall(0x00F4CE14, data, 20, 20 * j, 20 * i); + draw_2d_wall(0x00F4CE14, data, 20 * j, 20 * i); else if (ft_strchr("NSEW", map->map[i][j])) - draw_2d_wall(0x00FF0000, data, 20, 20 * j, 20 * i); + draw_2d_wall(0x00FF0000, data, 20 * j, 20 * i); j++; } i++; } } +void init_player(t_mapdata *mapdata, t_player *player) +{ + char facing; + + facing = mapdata->map[mapdata->starty][mapdata->startx]; + player->health = 100; + player->x = mapdata->startx; + player->y = mapdata->starty; + if (facing == 'N') + player->yaw = 0; + else if (facing == 'E') + player->yaw = 90; + else if (facing == 'S') + player->yaw = 180; + else if (facing == 'W') + player->yaw = 270; + else + player->yaw = 0; +} + +void draw_player_pos(t_mapdata *map, t_mlx_data *data) +{ + (void)data; + ft_printf("position: %d %d\n", map->startx, map->starty); +} + int main(int argc, char **argv) { t_cub3d_data data; @@ -111,7 +138,9 @@ int main(int argc, char **argv) data.mlx_data->img = mlx_new_image(data.mlx, 800, 600); data.mlx_data->addr = mlx_get_data_addr(data.mlx_data->img, &data.mlx_data->bits_per_pixel, &data.mlx_data->line_length, &data.mlx_data->endian); mlx_hook(data.mlx_win, 17, 0L, destroy, &data); + init_player(data.map, &(data.player)); draw_map(data.map, data.mlx_data); + draw_player_pos(data.map, data.mlx_data); mlx_key_hook(data.mlx_win, key_destroy, &data); mlx_put_image_to_window(data.mlx, data.mlx_win, data.mlx_data->img, 0, 0); #ifdef BONUS diff --git a/src/map/checkers.c b/src/map/checkers.c index 402fd20..dd646c0 100644 --- a/src/map/checkers.c +++ b/src/map/checkers.c @@ -6,7 +6,7 @@ /* By: tchampio +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/06/21 19:29:45 by tchampio #+# #+# */ -/* Updated: 2025/07/02 10:38:16 by tchampio ### ########.fr */ +/* Updated: 2025/07/04 15:04:38 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/map/forbidden_characters.c b/src/map/forbidden_characters.c index 9004b69..74e900f 100644 --- a/src/map/forbidden_characters.c +++ b/src/map/forbidden_characters.c @@ -6,14 +6,13 @@ /* By: tchampio mapflood[y][x] == '1') return ; + if (map->mapflood[y][x] == 'z') + return ; if (map->mapflood[y][x] == ' ' || map->mapflood[y][x] == '\n') map->isvalid = false; map->mapflood[y][x] = '1';