diff options
Diffstat (limited to 'sprite.c')
-rw-r--r-- | sprite.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/sprite.c b/sprite.c new file mode 100644 index 0000000..09c9815 --- /dev/null +++ b/sprite.c @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* sprite.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: kdx <kdx @student.42angouleme.fr +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/10/09 07:15:24 by kdx #+# #+# */ +/* Updated: 2022/10/10 19:18:58 by kdx ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft/libft.h" +#include "minilibx/mlx.h" +#include "sprite.h" +#include "sily.h" + +t_sprite *sprite_load(t_sily *sily, char *path, int width, int height) +{ + t_sprite *sprite; + + sprite = ft_calloc(1, sizeof(t_sprite)); + if (sprite == NULL) + return (NULL); + sprite->width = width; + sprite->height = height; + sprite->img = mlx_xpm_file_to_image(sily->ctx, path, &sprite->width, + &sprite->height); + if (sprite->img == NULL) + return (ft_free(sprite)); + return (sprite); +} + +void sprite_destroy(t_sily *sily, t_sprite *sprite) +{ + if (sprite != NULL) + { + if (sprite->img != NULL) + mlx_destroy_image(sily->ctx, sprite->img); + ft_free(sprite); + } +} + +void sprite_draw(t_sily *sily, t_sprite *sprite, int x, int y) +{ + if (sprite == NULL) + { + ft_putendl_fd("error: sprite is NULL", 2); + return ; + } + mlx_put_image_to_window(sily->ctx, sily->window, sprite->img, x, y); +} |