/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */ /* Updated: 2025/07/17 14:55:29 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ #include "../libft/includes/libft.h" #include "../includes/structs.h" #include "../mlx/mlx.h" #include "consts.h" #include "map/map_checker.h" #include "draw/draw_map.h" #include "utils/hooks.h" #include #include #include #include #include void init_player(t_mapdata *mapdata, t_player *player) { player->health = 100; player->x = mapdata->startx; player->y = mapdata->starty; } int game_loop(t_cub3d_data *data) { data->player.x += data->player.movement.x; data->player.y += data->player.movement.y; mlx_destroy_image(data->mlx, data->mlx_data->img); data->mlx_data->img = mlx_new_image(data->mlx, 800, 600); draw_map(data->map, &data->player, data->mlx_data); mlx_put_image_to_window(data->mlx, data->mlx_win, data->mlx_data->img, 0, 0); mlx_string_put(data->mlx, data->mlx_win, 10, 10, 0x00FFFFFF, COMPILED_TEXT); return (0); } int main(int argc, char **argv) { t_cub3d_data data; if (argc < 2) return (ft_printf("Error: Missing cub3d file\n"), 1); data.map = ft_calloc(sizeof(t_mapdata), 1); if (!check_cubfile(argv[1], data.map)) return (ft_printf("Error: Wrong map file. Reason: %s\n", data.map->error), 1); data.mlx = mlx_init(); data.mlx_win = mlx_new_window(data.mlx, 800, 600, "Cub3d"); data.mlx_data = ft_calloc(sizeof(t_mlx_data), 1); 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); init_player(data.map, &(data.player)); mlx_hook(data.mlx_win, KeyPress, KeyPressMask, keypress_handler, &data); mlx_hook(data.mlx_win, KeyRelease, KeyReleaseMask, keyrelease_handler, &data); mlx_loop_hook(data.mlx, game_loop, &data); mlx_loop(data.mlx); }