64 lines
1.6 KiB
C
64 lines
1.6 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) */
|
|
void tile_shape(struct tile const *tile, shape_t *s);
|
|
|
|
//---
|
|
// Map grid, tiles location in space, and entities
|
|
//---
|
|
|
|
struct map {
|
|
/* Dimensions, columns are 0 to width-1, rows are 0 to height-1 */
|
|
int width, height;
|
|
/* All tiles */
|
|
struct tile *tiles;
|
|
/* Entities on the map */
|
|
struct entity **entities;
|
|
int entity_count;
|
|
};
|
|
|
|
/* Get a pointer to the tile at (x,y) in map; NULL if out of bounds. */
|
|
struct tile *map_tile(struct map *m, int x, int y);
|
|
|
|
/* Add an entity to the map. */
|
|
void map_add_entity(struct map *m, struct entity *e);
|
|
|
|
/* Check whether an entity collides with the map. */
|
|
bool map_entity_collides(struct map *m, struct entity *e);
|
|
|
|
/* Free resources associated with the map. */
|
|
void map_destroy(struct map *m);
|