2022-02-04 14:22:58 +00:00
|
|
|
|
/// Collision bitmap
|
|
|
|
|
/// ----------------
|
|
|
|
|
/// TH03 tracks collidable areas by maintaining a bitmap of each playfield,
|
|
|
|
|
/// where each set bit corresponds to a tile occupied by a collidable entity.
|
|
|
|
|
/// To save a bit of memory, these bitmaps are reduced to a quarter of the
|
|
|
|
|
/// screen resolution: Every bit corresponds to a tile of 2×2 screen pixels,
|
|
|
|
|
// or 2×1 VRAM pixels.
|
|
|
|
|
|
2024-05-25 18:31:09 +00:00
|
|
|
|
#include "th03/main/playfld.hpp"
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
2022-02-04 14:22:58 +00:00
|
|
|
|
typedef int collmap_tile_amount_t;
|
|
|
|
|
|
|
|
|
|
// Constants
|
|
|
|
|
// ---------
|
|
|
|
|
|
|
|
|
|
static const pixel_t COLLMAP_TILE_W = 2;
|
|
|
|
|
static const pixel_t COLLMAP_TILE_H = 2;
|
|
|
|
|
static const char COLLMAP_TILE_W_BITS = 1;
|
|
|
|
|
static const char COLLMAP_TILE_H_BITS = 1;
|
|
|
|
|
|
|
|
|
|
static const size_t COLLMAP_MEMORY_W = ((PLAYFIELD_W / COLLMAP_TILE_W) / 8);
|
|
|
|
|
static const size_t COLLMAP_H = (PLAYFIELD_H / COLLMAP_TILE_H);
|
|
|
|
|
static const size_t COLLMAP_SIZE = (COLLMAP_MEMORY_W * COLLMAP_H);
|
2022-02-06 16:24:09 +00:00
|
|
|
|
|
2022-02-15 13:19:07 +00:00
|
|
|
|
// Matches the size of the player hitbox. Increasing this distance beyond that
|
|
|
|
|
// size turns these stripes from an optimization into something that actually
|
|
|
|
|
// affects game difficulty.
|
2022-02-08 03:51:02 +00:00
|
|
|
|
static const collmap_tile_amount_t COLLMAP_RECT_VSTRIPE_DISTANCE = 4;
|
2022-02-15 13:19:07 +00:00
|
|
|
|
|
2022-02-06 16:24:09 +00:00
|
|
|
|
static const collmap_tile_amount_t COLLMAP_SLOPE_VSTRIPE_DISTANCE = 2;
|
2022-02-04 14:22:58 +00:00
|
|
|
|
// ---------
|
|
|
|
|
|
|
|
|
|
// Function parameters
|
|
|
|
|
// -------------------
|
|
|
|
|
|
|
|
|
|
// MODDERS: These two are stored at the same address in memory. Not having to
|
|
|
|
|
// use a union here is one advantage of emitting these in an undecompilable ASM
|
|
|
|
|
// translation unit, I guess...
|
|
|
|
|
extern PlayfieldPoint collmap_center;
|
|
|
|
|
extern PlayfieldPoint collmap_topleft;
|
|
|
|
|
|
|
|
|
|
extern collmap_tile_amount_t collmap_stripe_tile_w;
|
|
|
|
|
extern collmap_tile_amount_t collmap_tile_h;
|
|
|
|
|
extern PlayfieldPoint collmap_bottomright;
|
2023-10-27 21:28:28 +00:00
|
|
|
|
extern pid_t collmap_pid;
|
2022-02-04 14:22:58 +00:00
|
|
|
|
|
|
|
|
|
// Stored as columns from left to right, not rows from top to bottom.
|
|
|
|
|
extern uint8_t collmap[PLAYER_COUNT][COLLMAP_MEMORY_W][COLLMAP_H];
|
|
|
|
|
// -------------------
|
2022-02-06 16:24:09 +00:00
|
|
|
|
|
2022-02-08 03:51:02 +00:00
|
|
|
|
// Sets all bits on every [COLLMAP_RECT_VSTRIPE_DISTANCE]th row of a
|
|
|
|
|
// rectangle, clipped at all sides of the collision bitmap.
|
|
|
|
|
// Takes the following parameters:
|
|
|
|
|
// • [collmap_center] (X and Y)
|
|
|
|
|
// • [collmap_stripe_tile_w] (width of the rectangle)
|
|
|
|
|
// • [collmap_tile_h] (height of the rectangle)
|
|
|
|
|
// • [collmap_pid]
|
|
|
|
|
void collmap_set_rect_striped();
|
|
|
|
|
|
2022-02-07 16:21:35 +00:00
|
|
|
|
// Sets all bits on a straight 1-tile wide vertical line, clipped to the
|
|
|
|
|
// height of the collision bitmap. Takes the following parameters:
|
|
|
|
|
// • [collmap_topleft] (X and Y)
|
|
|
|
|
// • [collmap_tile_h] (height of the line)
|
|
|
|
|
// • [collmap_pid]
|
|
|
|
|
void collmap_set_vline();
|
|
|
|
|
|
2022-02-06 16:24:09 +00:00
|
|
|
|
// Sets all bits on every [COLLMAP_SLOPE_VSTRIPE_DISTANCE]th row of a
|
|
|
|
|
// potentially sloped vertical line across one whole playfield.
|
|
|
|
|
// Takes the following parameters:
|
|
|
|
|
// • [collmap_topleft.x] (always uses 0 for [y])
|
|
|
|
|
// • [collmap_bottomright.x] (always uses to_sp(PLAYFIELD_H) for [y])
|
|
|
|
|
// • [collmap_stripe_tile_w] (between 0 and 7)
|
|
|
|
|
// • [collmap_pid]
|
|
|
|
|
void collmap_set_slope_striped();
|
2022-02-04 14:22:58 +00:00
|
|
|
|
/// ----------------
|