comparison libmlk-rpg/mlk/rpg/map.h @ 434:4e78f045e8c0

rpg: cleanup hierarchy
author David Demelier <markand@malikania.fr>
date Sat, 15 Oct 2022 21:24:17 +0200
parents src/libmlk-rpg/rpg/map.h@8f59201dc76b
children 9c3b3935f0aa
comparison
equal deleted inserted replaced
433:862b15c3a3ae 434:4e78f045e8c0
1 /*
2 * map.h -- game map
3 *
4 * Copyright (c) 2020-2022 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 MLK_RPG_MAP_H
20 #define MLK_RPG_MAP_H
21
22 #include <stddef.h>
23
24 #include <mlk/core/action.h>
25 #include <mlk/core/action-stack.h>
26 #include <mlk/core/core.h>
27
28 #include "walksprite.h"
29
30 struct tileset;
31
32 union event;
33
34 enum map_layer_type {
35 MAP_LAYER_TYPE_BACKGROUND,
36 MAP_LAYER_TYPE_FOREGROUND,
37 MAP_LAYER_TYPE_ABOVE,
38 MAP_LAYER_TYPE_NUM
39 };
40
41 struct map_layer {
42 unsigned short *tiles;
43 };
44
45 enum map_flags {
46 MAP_FLAGS_NONE = 0,
47 MAP_FLAGS_SHOW_GRID = (1 << 0),
48 MAP_FLAGS_SHOW_COLLIDE = (1 << 2)
49 };
50
51 struct map_block {
52 int x;
53 int y;
54 unsigned int w;
55 unsigned int h;
56 };
57
58 struct map {
59 const char *title; /*!< (+) Map title name. */
60 unsigned int columns; /*!< (-) Number of columns. */
61 unsigned int rows; /*!< (-) Number of rows. */
62
63 /* Tileset. */
64 struct tileset *tileset; /*!< (+&?) Tileset to use. */
65
66 /* View options. */
67 enum map_flags flags; /*!< (+) View options. */
68
69 /* Extra collisions blocks. */
70 struct map_block *blocks; /*!< (+&?) Extra collisions. */
71 size_t blocksz; /*!< (+) Number of collisions. */
72
73 /* List of actions. */
74 struct action_stack astack_par; /*!< (+) Parallel actions. */
75 struct action_stack astack_seq; /*!< (+) Blocking actions. */
76
77 /* Player. */
78 struct sprite *player_sprite; /*!< (+) The sprite to use */
79 struct walksprite player_ws; /*!< (-) Walking sprite for moving the player. */
80 int player_x; /*!< (+) Player position in x */
81 int player_y; /*!< (+) Player position in y */
82 int player_angle; /*!< (+) Player angle (see walksprite) */
83 unsigned int player_movement; /*!< (*) Current player movements. */
84
85 /* View to zoom/locate. */
86 int view_x; /*!< (+) Position in x */
87 int view_y; /*!< (+) Position in y */
88 unsigned int view_w; /*!< (+) View width */
89 unsigned int view_h; /*!< (+) View height */
90
91 /* View margin. */
92 int margin_x; /*!< (+) View margin in x. */
93 int margin_y; /*!< (+) View margin in y. */
94 unsigned int margin_w; /*!< (+) Margin width. */
95 unsigned int margin_h; /*!< (+) Margin height. */
96
97 /* Different tile layers. */
98 struct map_layer layers[MAP_LAYER_TYPE_NUM];
99 };
100
101 CORE_BEGIN_DECLS
102
103 int
104 map_init(struct map *map);
105
106 void
107 map_handle(struct map *map, const union event *ev);
108
109 void
110 map_update(struct map *map, unsigned int ticks);
111
112 void
113 map_draw(const struct map *map);
114
115 void
116 map_finish(struct map *map);
117
118 CORE_END_DECLS
119
120 #endif /* !MLK_RPG_MAP_H */