comparison librpg/rpg/tileset.h @ 215:64f24b482722

rpg: implement tilesets separately, closes #2515 @4h While here: - Add CMake macros, - Update maps, - Add more tests.
author David Demelier <markand@malikania.fr>
date Tue, 17 Nov 2020 20:08:42 +0100
parents
children 71f989ae8de9
comparison
equal deleted inserted replaced
214:82fd79d5019e 215:64f24b482722
1 /*
2 * tileset.h -- map tileset definition
3 *
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #ifndef MOLKO_RPG_TILESET_H
20 #define MOLKO_RPG_TILESET_H
21
22 #include <stdbool.h>
23 #include <stddef.h>
24
25 struct sprite;
26
27 /**
28 * \brief Describe a tile property in a tileset.
29 *
30 * It can contains an animation and a collision mask.
31 */
32 struct tileset_tiledef {
33 short id; /*!< (+) Tile index. */
34 short x; /*!< (+) Collision region starts in y. */
35 short y; /*!< (+) Collision region starts in y. */
36 unsigned short w; /*!< (+) Collision width. */
37 unsigned short h; /*!< (+) Collision height. */
38 };
39
40 /**
41 * \brief Tileset definition.
42 */
43 struct tileset {
44 struct tileset_tiledef *tiledefs; /*!< (+&?) Per tile properties (must be sorted by id). */
45 size_t tiledefsz; /*!< (+) Number of tile properties. */
46 struct sprite *sprite; /*!< (+&) Sprite to generate the terrain. */
47 };
48
49 bool
50 tileset_ok(const struct tileset *ts);
51
52 void
53 tileset_draw(const struct tileset *ts, unsigned int r, unsigned int c, int x, int y);
54
55 #endif /* !MOLKO_RPG_TILESET_H */