comparison libmlk-rpg/rpg/map.h @ 243:71b3b7036de7

misc: lot of cleanups, - prefix libraries with libmlk, - move assets from source directories closes #2520, - prefix header guards closes #2519
author David Demelier <markand@malikania.fr>
date Sat, 28 Nov 2020 22:37:30 +0100
parents librpg/rpg/map.h@e71039d820a7
children 8ef7fb7f14ad
comparison
equal deleted inserted replaced
242:4c24604efcab 243:71b3b7036de7
1 /*
2 * map.h -- game map
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_MAP_H
20 #define MOLKO_RPG_MAP_H
21
22 /**
23 * \file map.h
24 * \brief Game map.
25 */
26
27 #include <stddef.h>
28
29 #include <core/action.h>
30
31 #include "walksprite.h"
32
33 struct tileset;
34
35 union event;
36
37 /**
38 * \brief Map layer type.
39 */
40 enum map_layer_type {
41 MAP_LAYER_TYPE_BACKGROUND, /*!< Background layer. */
42 MAP_LAYER_TYPE_FOREGROUND, /*!< Foreground layer. */
43 MAP_LAYER_TYPE_ABOVE, /*!< Above foreground layer. */
44 MAP_LAYER_TYPE_NUM /*!< Number of layers. */
45 };
46
47 /**
48 * \brief Map layer.
49 */
50 struct map_layer {
51 unsigned short *tiles; /*!< (+&) Array of tiles, depending on the map size. */
52 };
53
54 /**
55 * \brief Map view flags.
56 */
57 enum map_flags {
58 MAP_FLAGS_NONE = 0, /*!< No flags. */
59 MAP_FLAGS_SHOW_GRID = (1 << 0), /*!< Show grid pattern. */
60 MAP_FLAGS_SHOW_COLLIDE = (1 << 2) /*!< Show collision layer. */
61 };
62
63 /**
64 * \brief Map object.
65 *
66 * The map object is used to move a player within the map according to the
67 * tilesets and collisions masks.
68 *
69 * By itself, a map does not know how to be loaded from a file and must be done
70 * from an helper like \ref map_file.
71 */
72 struct map {
73 const char *title; /*!< (+) Map title name. */
74 unsigned int columns; /*!< (-) Number of columns. */
75 unsigned int rows; /*!< (-) Number of rows. */
76
77 /* Tileset. */
78 struct tileset *tileset; /*!< (+&?) Tileset to use. */
79
80 /* View options. */
81 enum map_flags flags; /*!< (+) View options. */
82
83 /* List of actions. */
84 struct action_stack actions; /*!< (+) */
85
86 /* Player. */
87 struct sprite *player_sprite; /*!< (+) The sprite to use */
88 struct walksprite player_ws; /*!< (-) Walking sprite for moving the player. */
89 int player_x; /*!< (+) Player position in x */
90 int player_y; /*!< (+) Player position in y */
91 int player_angle; /*!< (+) Player angle (see walksprite) */
92 unsigned int player_movement; /*!< (*) Current player movements. */
93
94 /* View to zoom/locate. */
95 int view_x; /*!< (+) Position in x */
96 int view_y; /*!< (+) Position in y */
97 unsigned int view_w; /*!< (+) View width */
98 unsigned int view_h; /*!< (+) View height */
99
100 /* View margin. */
101 int margin_x; /*!< (+) View margin in x. */
102 int margin_y; /*!< (+) View margin in y. */
103 unsigned int margin_w; /*!< (+) Margin width. */
104 unsigned int margin_h; /*!< (+) Margin height. */
105
106 /**
107 * Different tile layers.
108 */
109 struct map_layer layers[MAP_LAYER_TYPE_NUM];
110 };
111
112 /**
113 * Initialize the map.
114 *
115 * This function will re-generate the terrain and center the view to the player
116 * position.
117 *
118 * \pre map != NULL
119 * \param map the map to initialize
120 */
121 bool
122 map_init(struct map *map);
123
124 /**
125 * Handle an event.
126 *
127 * \pre map != NULL
128 * \pre ev != NULL
129 * \param map the map
130 * \param ev the event to handle
131 */
132 void
133 map_handle(struct map *map, const union event *ev);
134
135 /**
136 * Update the map.
137 *
138 * \pre map != NULL
139 * \param map the map
140 * \param ticks ellapsed milliseconds since last frame
141 */
142 void
143 map_update(struct map *map, unsigned int ticks);
144
145 /**
146 * Render a map.
147 *
148 * \pre map != NULL
149 * \param map the map to render
150 */
151 void
152 map_draw(const struct map *map);
153
154 /**
155 * Dispose map resources.
156 *
157 * \pre map != NULL
158 * \param map the map to close
159 */
160 void
161 map_finish(struct map *map);
162
163 #endif /* !MOLKO_RPG_MAP_H */