/* ************************************************************************** */ /* LE - / */ /* / */ /* ft_drawmap.c .:: .:/ . .:: */ /* +:+:+ +: +: +:+:+ */ /* By: rbousset +:+ +: +: +:+ */ /* #+# #+ #+ #+# */ /* Created: 2020/02/02 17:19:18 by rbousset #+# ## ## #+# */ /* Updated: 2020/02/02 17:19:19 by rbousset ### #+. /#+ ###.fr */ /* / */ /* / */ /* ************************************************************************** */ #include #include #include #include static void ft_draw_core_map(char **map, t_cub *clist) { const uint8_t scale = clist->scale; size_t x; size_t y; x = 0; y = 0; while (map[y]) { while (map[y][x]) { if (map[y][x] == '1') ft_drawsquare(scale + (x * (scale + 1)), scale + (y * (scale + 1)), 0x00aa99aa, clist); else if (map[y][x] == '2') ft_drawsquare(scale + (x * (scale + 1)), scale + (y * (scale + 1)), 0x0033ccff, clist); else ft_drawsquare(scale + (x * (scale + 1)), scale + (y * (scale + 1)), ft_rgb_to_hex(clist->f_rgb), clist); x++; } x = 0; y++; } } static void ft_draw_player(t_player *plist, t_cub *clist) { const float x = plist->pos_x; const float y = plist->pos_y; const uint16_t scale = clist->scale; ft_drawsquare( scale + (x * (scale + 1)), scale + (y * (scale + 1)), 0x009843fa, clist); } void ft_drawmap(t_cub *clist) { mlx_clear_window(clist->wlist->wlx, clist->wlist->winptr); clist->img.img = mlx_new_image(clist->wlist->wlx, clist->wlist->x_size, clist->wlist->y_size); clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp, &clist->img.sizeline, &clist->img.endian); ft_draw_core_map(clist->map, clist); ft_draw_player(clist->plist, clist); mlx_put_image_to_window(clist->wlist->wlx, clist->wlist->winptr, clist->img.img, 0, 0); mlx_destroy_image(clist->wlist->wlx, clist->img.img); }