summaryrefslogtreecommitdiffstats
path: root/src/resources/map.h
blob: e0881616122c569c94e55a0133cdfe405d00fdf7 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef RESOURCE_MAP_H
#define RESOURCE_MAP_H

#include <SDL_stdinc.h>
#include "resource.h"
#include "image.h"

enum layer_id {
	LAYER_GROUND = 0,
	LAYER_OBJ_LOW,
	LAYER_CHAR_BOT,
	LAYER_OBJ_MID,
	LAYER_CHAR_TOP,
	LAYER_OBJ_HIGH,
	LAYER_WEATHER,
	LAYERS_MAX
};
struct tileset {
	struct resource res;
	char *dirname;
	char *name;
	int tilewidth;
	int tileheight;
	struct image *image;
};
struct map_tileset {
	struct tileset *tileset;
	int firstgid;
	struct map_tileset *next;
};
struct layer {
	struct map *map;
	Uint32 *tiles;
	char *encoding;
	char *compression;
	char *raw_data;
};
struct map_collision {
	enum {
		COLLISION_NONE = 0,
		COLLISION_CHAR,
		COLLISION_OBJ,
		COLLISION_EXIT
	} type;
	union {
/*		struct character *c;*/
		Uint8 o;
		struct map_exit *e;
	} data;
};
struct map_exit {
	struct map *map;
	int x;
	int y;
	int width;
	int height;
	char *target_map_name;
	struct map *target_map;
	int target_x_coord;
	int target_y_coord;
	struct map_exit *next;
};
struct map_spawn {
	struct map *map;
	int x;
	int y;
	int width;
	int height;
	int player;
	struct map_spawn *next;
};
struct map {
	struct resource res;
	char *dirname;
	/* TODO: map_get() should take a name, not a path.
	char *name;
	*/
	int width;
	int height;
	int tilewidth;
	int tileheight;
	struct map_tileset *tilesets_head;
	struct map_tileset *tilesets_tail;
	struct layer layers[LAYERS_MAX];
	struct map_collision *collisions;
	struct map_exit *map_exits_head;
	struct map_exit *map_exits_tail;
	int cur_ts_firstgid;
};

struct map *map_get(const char *path);
void map_free(struct map *map);
void map_add_tileset(struct map *m, struct tileset *t, int firstgid);
struct layer *map_get_layer(struct map *m, const char *name);
void map_add_exit(struct map *m, struct map_exit *e);

#endif