diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmlk-rpg/mlk/rpg/map.h	Sat Oct 15 21:24:17 2022 +0200
@@ -0,0 +1,120 @@
+/*
+ * map.h -- game map
+ *
+ * Copyright (c) 2020-2022 David Demelier <markand@malikania.fr>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef MLK_RPG_MAP_H
+#define MLK_RPG_MAP_H
+
+#include <stddef.h>
+
+#include <mlk/core/action.h>
+#include <mlk/core/action-stack.h>
+#include <mlk/core/core.h>
+
+#include "walksprite.h"
+
+struct tileset;
+
+union event;
+
+enum map_layer_type {
+	MAP_LAYER_TYPE_BACKGROUND,
+	MAP_LAYER_TYPE_FOREGROUND,
+	MAP_LAYER_TYPE_ABOVE,
+	MAP_LAYER_TYPE_NUM
+};
+
+struct map_layer {
+	unsigned short *tiles;
+};
+
+enum map_flags {
+	MAP_FLAGS_NONE          = 0,
+	MAP_FLAGS_SHOW_GRID     = (1 << 0),
+	MAP_FLAGS_SHOW_COLLIDE  = (1 << 2)
+};
+
+struct map_block {
+	int x;
+	int y;
+	unsigned int w;
+	unsigned int h;
+};
+
+struct map {
+	const char *title;              /*!< (+) Map title name. */
+	unsigned int columns;           /*!< (-) Number of columns. */
+	unsigned int rows;              /*!< (-) Number of rows. */
+
+	/* Tileset. */
+	struct tileset *tileset;        /*!< (+&?) Tileset to use. */
+
+	/* View options. */
+	enum map_flags flags;           /*!< (+) View options. */
+
+	/* Extra collisions blocks. */
+	struct map_block *blocks;       /*!< (+&?) Extra collisions. */
+	size_t blocksz;                 /*!< (+) Number of collisions. */
+
+	/* List of actions. */
+	struct action_stack astack_par; /*!< (+) Parallel actions. */
+	struct action_stack astack_seq; /*!< (+) Blocking actions. */
+
+	/* Player. */
+	struct sprite *player_sprite;   /*!< (+) The sprite to use */
+	struct walksprite player_ws;    /*!< (-) Walking sprite for moving the player. */
+	int player_x;                   /*!< (+) Player position in x */
+	int player_y;                   /*!< (+) Player position in y */
+	int player_angle;               /*!< (+) Player angle (see walksprite) */
+	unsigned int player_movement;   /*!< (*) Current player movements. */
+
+	/* View to zoom/locate. */
+	int view_x;                     /*!< (+) Position in x */
+	int view_y;                     /*!< (+) Position in y */
+	unsigned int view_w;            /*!< (+) View width */
+	unsigned int view_h;            /*!< (+) View height */
+
+	/* View margin. */
+	int margin_x;                   /*!< (+) View margin in x. */
+	int margin_y;                   /*!< (+) View margin in y. */
+	unsigned int margin_w;          /*!< (+) Margin width. */
+	unsigned int margin_h;          /*!< (+) Margin height. */
+
+	/* Different tile layers. */
+	struct map_layer layers[MAP_LAYER_TYPE_NUM];
+};
+
+CORE_BEGIN_DECLS
+
+int
+map_init(struct map *map);
+
+void
+map_handle(struct map *map, const union event *ev);
+
+void
+map_update(struct map *map, unsigned int ticks);
+
+void
+map_draw(const struct map *map);
+
+void
+map_finish(struct map *map);
+
+CORE_END_DECLS
+
+#endif /* !MLK_RPG_MAP_H */