summaryrefslogtreecommitdiff
path: root/map.h
blob: b4ce6411a763fcf94a2b11b7512767a79459d890 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   map.h                                              :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: kdx    <kdx   @student.42angouleme.fr      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2022/10/10 07:29:31 by kdx               #+#    #+#             */
/*   Updated: 2022/10/16 00:12:59 by kdx              ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#ifndef MAP_H
# define MAP_H
# include "libft/libft.h"
# include "sily.h"
# define TSIZE 16

enum
{
	TILE_NONE = '0',
	TILE_WALL = '1',
	TILE_COLLECTIBLE = 'C',
	TILE_EXIT = 'E',
	TILE_PLAYER = 'P',
};

enum
{
	ERR_NONE,
	ERR_OPEN,
	ERR_READ,
	ERR_MALLOC,
	ERR_INVALID_CHAR,
	ERR_WRONG_DIMENSION,
	ERR_FILENAME,
	ERR_MISSING,
	ERR_DUPLICATE,
	ERR_OPEN_BORDER,
	ERR_NO_PATH,
};

typedef struct s_map
{
	unsigned char	*data;
	size_t			width;
	size_t			height;
	size_t			exit[2];
}	t_map;

t_err			map_load(t_map *map, const char *path);
void			map_destroy(t_map *map);
const char		*map_load_error(t_err err);
void			map_draw_tile(t_sily *sily, t_map *map, int x, int y);
void			map_draw(t_sily *sily, t_map *map);
void			map_spawn(t_game *game, t_map *map);
unsigned char	map_get(t_map *map, int x, int y);
void			map_set(t_map *map, int x, int y, unsigned char v);
size_t			map_count(t_map *map, int v);

t_err			map_verify(t_map *map, const unsigned char *data);
t_err			map_pathfind(t_map *map);

#endif