2021-05-30 21:59:09 +02:00
|
|
|
//---
|
|
|
|
// 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"
|
2021-06-01 17:49:29 +02:00
|
|
|
#include "map.h"
|
|
|
|
#include "geometry.h"
|
2021-05-30 21:59:09 +02:00
|
|
|
|
2021-12-25 18:21:31 +01:00
|
|
|
#include <gint/display.h>
|
|
|
|
|
2021-05-30 21:59:09 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2021-06-01 21:30:05 +02:00
|
|
|
//---
|
|
|
|
// Tiles
|
|
|
|
//---
|
|
|
|
|
2021-12-25 11:47:22 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
2021-05-30 21:59:09 +02:00
|
|
|
/* TODO: Layers of objects, stuff, dynamic elements, etc? */
|
2021-06-01 17:49:29 +02:00
|
|
|
/* TODO: Allow any collision shape for the tile! */
|
2021-05-30 21:59:09 +02:00
|
|
|
bool solid;
|
2021-12-28 20:28:17 +01:00
|
|
|
/* Rendering plane for that tile */
|
|
|
|
uint8_t plane;
|
2021-06-02 09:38:59 +02:00
|
|
|
/* Base layer: floor/wall pattern */
|
|
|
|
uint8_t base;
|
|
|
|
/* Decoration layer */
|
|
|
|
uint8_t decor;
|
2021-12-25 11:47:22 +01:00
|
|
|
|
|
|
|
} tile_t;
|
2021-05-30 21:59:09 +02:00
|
|
|
|
2021-06-01 21:30:05 +02:00
|
|
|
/* 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) */
|
2021-12-25 11:47:22 +01:00
|
|
|
rect tile_shape(tile_t const *tile);
|
2021-06-01 21:30:05 +02:00
|
|
|
|
|
|
|
//---
|
|
|
|
// Map grid, tiles location in space, and entities
|
|
|
|
//---
|
2021-06-01 17:49:29 +02:00
|
|
|
|
2021-12-25 11:47:22 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
2021-05-30 21:59:09 +02:00
|
|
|
/* Dimensions, columns are 0 to width-1, rows are 0 to height-1 */
|
2021-12-27 21:54:55 +01:00
|
|
|
uint16_t width, height;
|
2021-12-25 18:21:31 +01:00
|
|
|
/* Tileset base (first layer), tileset decor (second layer) */
|
2021-12-27 21:54:55 +01:00
|
|
|
bopti_image_t *tileset;
|
2021-05-30 21:59:09 +02:00
|
|
|
/* All tiles */
|
2021-12-25 11:47:22 +01:00
|
|
|
tile_t *tiles;
|
2021-06-01 17:49:29 +02:00
|
|
|
|
2021-06-04 15:14:12 +02:00
|
|
|
} map_t;
|
2021-06-01 17:49:29 +02:00
|
|
|
|
2021-06-04 15:14:12 +02:00
|
|
|
/* Get a pointer to the tile at (x,y) in map; NULL if out of bounds. */
|
2021-12-25 11:47:22 +01:00
|
|
|
tile_t *map_tile(map_t const *m, int x, int y);
|
2021-06-01 17:49:29 +02:00
|
|
|
|
2021-06-04 15:14:12 +02:00
|
|
|
/* Check whether a hitbox collides with the map. */
|
2021-10-24 21:54:37 +02:00
|
|
|
bool map_collides(map_t const *m, rect hitbox);
|