/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* initialize.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/22 17:08:26 by qmennen #+# #+# */ /* Updated: 2025/05/27 15:12:33 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ #include "cub3d.h" t_sprite make_sprite(mlx_texture_t *texture, double x, double y, int collectible) { t_sprite sprite; ft_memset(&sprite, 0, sizeof(t_sprite)); sprite.texture = texture; // if (sprite.texture->width % 64 != 0) // { // ft_putstr_fd("Error: Texture width is not a multiple of 64\n", 2); // exit(EXIT_FAILURE); // } // if (sprite.texture->height != 64) // { // ft_putstr_fd("Error: Texture height must be 64\n", 2); // exit(EXIT_FAILURE); // } sprite.n_frames = sprite.texture->width / sprite.texture->height; sprite.pos.x = x; sprite.pos.y = y; sprite.visible = 1; sprite.collectible = collectible; return (sprite); } static int init_temp(t_game **game) { // t_sprite *sprites; // (*game)->map->sprites = malloc(sizeof(t_sprite) * 10); // if (!(*game)->map->sprites) // return (FAILURE); // sprites = (*game)->map->sprites; // sprites[0] = make_sprite("./assets/battery.png", 3.5, 3.5, 1); // sprites[1] = make_sprite("./assets/plant.png", 2.5, 3.5, 0); // sprites[2] = make_sprite("./assets/plant.png", 1.5, 3.5, 0); // sprites[3] = make_sprite("./assets/broken_mirror.png", 3.5, 4.5, 0); // sprites[4] = make_sprite("./assets/lamp.png", 2.5, 5.5, 0); // sprites[5] = make_sprite("./assets/battery.png", 10.5, 6.5, 1); // sprites[6] = make_sprite("./assets/plant.png", 14.5, 3.5, 0); // sprites[7] = make_sprite("./assets/battery.png", 2.5, 7.5, 1); // sprites[8] = make_sprite("./assets/broken_mirror.png", 42.5, 4.5, 0); // sprites[9] = make_sprite("./assets/lamp.png", 9.5, 10.5, 0); // (*game)->map->n_sprites = 10; mlx_texture_t *hud_texture; hud_texture = mlx_load_png("./assets/overlay2.png"); (*game)->screen->hud = mlx_texture_to_image((*game)->screen->mlx, hud_texture); mlx_delete_texture(hud_texture); return (SUCCESS); } int initialize_cub3d(t_game **game, const char *mapfile) { if (!game_create(game)) return (FAILURE); if (!player_create(game)) return (FAILURE); if (!map_create(game, mapfile)) return (FAILURE); if (!texture_load(*game)) return (FAILURE); if (!screen_create(game)) return (FAILURE); if (!keyboard_create(game)) return (FAILURE); if (!init_temp(game)) return (FAILURE); if (!screen_display((*game)->screen)) return (FAILURE); return (SUCCESS); }