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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
#ifndef RESOURCE_MAP_H
#define RESOURCE_MAP_H
#include <SDL_stdinc.h>
#include "resource.h"
#include "palette.h"
#include "image.h"
enum map_palette_id {
MAP_PALETTE_DEFAULT = 0,
MAP_PALETTE_MORN,
MAP_PALETTE_DAY,
MAP_PALETTE_EVE,
MAP_PALETTE_NIGHT,
MAP_PALETTES_MAX
};
enum map_layer {
MAP_LAYER_GROUND = 0,
MAP_LAYER_OBJ_LOW,
MAP_LAYER_OBJ_MID,
MAP_LAYER_OBJ_HIGH,
MAP_LAYER_COLLISION,
MAP_LAYER_WEATHER,
MAP_LAYERS_MAX
};
struct map_palette {
struct palette *palette;
Uint16 min;
};
struct tileset {
struct resource res;
char *dirname;
char *name;
int tilewidth;
int tileheight;
int width;
int height;
enum {
TILESET_TYPE_IMAGE,
TILESET_TYPE_COLLISION
} type;
struct image *image;
Uint8 *collision_tiles;
int cur_collision_tile;
};
struct map_tileset {
struct tileset *tileset;
Uint32 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: Consider making these Uint16s. */
int width;
int height;
int tilewidth;
int tileheight;
struct map_palette palettes[MAP_PALETTES_MAX];
struct map_tileset *tilesets_head;
struct map_tileset *tilesets_tail;
struct layer layers[MAP_LAYERS_MAX];
struct map_collision *collisions;
struct map_exit *map_exits_head;
struct map_exit *map_exits_tail;
Uint32 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, Uint32 firstgid);
struct map_palette *map_get_palette(struct map *m, const char *name);
struct layer *map_get_layer(struct map *m, const char *name);
void map_add_exit(struct map *m, struct map_exit *e);
#endif
|