···18181919/* Load a sprite sheet with the given sprite width/height. */
2020struct kf_spritesheet kf_loadspritesheet(char *filename, int spritewidth, int spriteheight);
2121+/* Draw a single sprite from the sheet with a provided width and height. */
2222+void kf_drawsprite_wh(struct kf_spritesheet *sheet, f32 x, f32 y, f32 w, f32 h, int spritex, int spritey);
2123/* Draw a single sprite from the sheet at the given coordinates. */
2224void kf_drawsprite(struct kf_spritesheet *sheet, f32 x, f32 y, int spritex, int spritey);
2325
+39-3
include/keraforge/world.h
···4455#include <keraforge/_header.h>
66#include <keraforge/math.h>
77+#include <keraforge/sprites.h>
78#include <raylib.h>
891010+1111+#define KF_TILE_SIZE_PX 16
9121013#define KF_TILEID_MAX UINT16_MAX
1114typedef u16 kf_tileid_t;
1212-#define KF_TILE_SIZE_PX 16
1515+/* Used to store connectivity variant. */
1616+typedef u16 kf_tiledatum_t;
131714181519struct kf_actor; /* Forward declaration */
162017212222+#define KF_TILEMASK_NORTH (0x0001)
2323+#define KF_TILEMASK_WEST (0x0010)
2424+#define KF_TILEMASK_EAST (0x0100)
2525+#define KF_TILEMASK_SOUTH (0x1000)
2626+2727+2828+/* Represents a singular tile in the world. */
2929+struct kf_tile
3030+{
3131+ kf_tileid_t id;
3232+ kf_tiledatum_t data;
3333+};
3434+1835/* Represents a world (or a subworld, often called "rooms"). */
1936struct kf_world
2037{
···3047 /* Height of the map. */
3148 u32 height;
3249 /* Array of tiles in the map. Use kf_gettile to get a tile using an X/Y position. */
3333- kf_tileid_t map[];
5050+ struct kf_tile map[];
3451};
35523653/* Struct-of-arrays for tiles. See: kf_tiles */
···5168/* Struct-of-arrays for tiles. */
5269extern struct _kf_tiles kf_tiles;
53707171+/* Options for creating tiles using addtile and addtiles. */
7272+struct kf_tile_opts
7373+{
7474+ char *key;
7575+ Color mapcol;
7676+ struct kf_spritesheet *sheet;
7777+ struct kf_vec2(u32) sprite;
7878+ bool collide;
7979+};
8080+8181+kf_tileid_t kf_addtile(struct kf_tile_opts opts);
8282+#define KF_ADDTILE(...) (kf_addtile((struct kf_tile_opts){ __VA_ARGS__ }))
8383+5484/* Create a world using the given width and height.
5585 Fills the map with the given `fill` tile. */
5686struct kf_world *kf_world_new(u32 width, u32 height, kf_tileid_t fill);
···5888/* Get the size of the world in bytes. */
5989size_t kf_world_getsize(struct kf_world *world);
60909191+/* Get the sprite offset for a given tile datum. */
9292+struct kf_vec2(u32) kf_getspritefortilebitmask(kf_tiledatum_t t);
9393+9494+/* Update a tile and optionally its neighbours. */
9595+void kf_world_updatetile(struct kf_world *world, u32 x, u32 y, bool update_neighbours);
9696+6197/* Get a pointer to the tile ID at a given position. */
6262-kf_tileid_t *kf_world_gettile(struct kf_world *world, u32 x, u32 y);
9898+struct kf_tile *kf_world_gettile(struct kf_world *world, u32 x, u32 y);
639964100/* Draw visible collision rectangles. */
65101void kf_world_drawcolliders(struct kf_world *world, struct kf_actor *player, Camera2D camera);