RogueLife/src/map.h

64 lines
1.5 KiB
C

//---
// map: Dynamic level models
//
// This module provides dynamic maps as they are used during games. This
// includes objects being activated and their current state, doors being
// opened, crates being blown up, you name it. But not moving entities.
//---
#pragma once
#include "fixed.h"
#include "map.h"
#include "geometry.h"
#include <gint/display.h>
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
//---
// Tiles
//---
typedef struct
{
/* TODO: Layers of objects, stuff, dynamic elements, etc? */
/* TODO: Allow any collision shape for the tile! */
bool solid;
/* Rendering plane for that tile */
uint8_t plane;
/* Base layer: floor/wall pattern */
uint8_t base;
/* Decoration layer */
uint8_t decor;
} tile_t;
/* Shape for a tile; this lives in a coordinate system whose (0,0) ends up at
the middle of the tile in the map space (which is a point with half-integer
coordinates) */
rect tile_shape(tile_t const *tile);
//---
// Map grid, tiles location in space, and entities
//---
typedef struct
{
/* Dimensions, columns are 0 to width-1, rows are 0 to height-1 */
uint16_t width, height;
/* Tileset base (first layer), tileset decor (second layer) */
bopti_image_t *tileset;
/* All tiles */
tile_t *tiles;
} map_t;
/* Get a pointer to the tile at (x,y) in map; NULL if out of bounds. */
tile_t *map_tile(map_t const *m, int x, int y);
/* Check whether a hitbox collides with the map. */
bool map_collides(map_t const *m, rect hitbox);