RogueLife/src/map.h

56 lines
1.4 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 "entities.h"
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
//---
// Tiles
//---
struct tile {
/* TODO: Layers of objects, stuff, dynamic elements, etc? */
/* TODO: Allow any collision shape for the tile! */
bool solid;
/* Base layer: floor/wall pattern */
uint8_t base;
/* Decoration layer */
uint8_t decor;
};
/* 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) */
frect_t tile_shape(struct tile 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 */
int width, height;
/* All tiles */
struct tile *tiles;
} map_t;
/* Get a pointer to the tile at (x,y) in map; NULL if out of bounds. */
struct tile *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, frect_t hitbox);