add tilemap/tilesheet
This commit is contained in:
parent
c18896def0
commit
ff698730f1
13 changed files with 841 additions and 28 deletions
80
src/pxl8_tilemap.h
Normal file
80
src/pxl8_tilemap.h
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#pragma once
|
||||
|
||||
#include "pxl8_types.h"
|
||||
#include "pxl8_gfx.h"
|
||||
#include "pxl8_tilesheet.h"
|
||||
|
||||
#define PXL8_TILE_SIZE 16
|
||||
#define PXL8_MAX_TILEMAP_WIDTH 256
|
||||
#define PXL8_MAX_TILEMAP_HEIGHT 256
|
||||
#define PXL8_MAX_TILE_LAYERS 4
|
||||
|
||||
typedef enum pxl8_tile_flags {
|
||||
PXL8_TILE_FLIP_X = 1 << 0,
|
||||
PXL8_TILE_FLIP_Y = 1 << 1,
|
||||
PXL8_TILE_SOLID = 1 << 2,
|
||||
PXL8_TILE_TRIGGER = 1 << 3,
|
||||
} pxl8_tile_flags;
|
||||
|
||||
typedef struct pxl8_tile {
|
||||
u16 id;
|
||||
u8 flags;
|
||||
u8 palette_offset;
|
||||
} pxl8_tile;
|
||||
|
||||
typedef struct pxl8_tilemap_layer {
|
||||
pxl8_tile* tiles;
|
||||
u32 width;
|
||||
u32 height;
|
||||
bool visible;
|
||||
u8 opacity;
|
||||
} pxl8_tilemap_layer;
|
||||
|
||||
typedef struct pxl8_tilemap {
|
||||
pxl8_tilemap_layer layers[PXL8_MAX_TILE_LAYERS];
|
||||
u32 width;
|
||||
u32 height;
|
||||
u32 tile_size;
|
||||
u32 active_layers;
|
||||
|
||||
pxl8_tilesheet* tilesheet;
|
||||
|
||||
i32 camera_x;
|
||||
i32 camera_y;
|
||||
} pxl8_tilemap;
|
||||
|
||||
typedef struct pxl8_tilemap_view {
|
||||
i32 x, y;
|
||||
i32 width, height;
|
||||
i32 tile_start_x, tile_start_y;
|
||||
i32 tile_end_x, tile_end_y;
|
||||
} pxl8_tilemap_view;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
pxl8_result pxl8_tilemap_init(pxl8_tilemap* tilemap, u32 width, u32 height, u32 tile_size);
|
||||
pxl8_result pxl8_tilemap_set_tilesheet(pxl8_tilemap* tilemap, pxl8_tilesheet* tilesheet);
|
||||
void pxl8_tilemap_free(pxl8_tilemap* tilemap);
|
||||
|
||||
pxl8_result pxl8_tilemap_set_tile(pxl8_tilemap* tilemap, u32 layer, u32 x, u32 y, u16 tile_id, u8 flags);
|
||||
pxl8_tile pxl8_tilemap_get_tile(const pxl8_tilemap* tilemap, u32 layer, u32 x, u32 y);
|
||||
|
||||
void pxl8_tilemap_set_camera(pxl8_tilemap* tilemap, i32 x, i32 y);
|
||||
void pxl8_tilemap_get_view(const pxl8_tilemap* tilemap, const pxl8_gfx_ctx* gfx, pxl8_tilemap_view* view);
|
||||
|
||||
void pxl8_tilemap_render(const pxl8_tilemap* tilemap, pxl8_gfx_ctx* gfx);
|
||||
void pxl8_tilemap_render_layer(const pxl8_tilemap* tilemap, pxl8_gfx_ctx* gfx, u32 layer);
|
||||
void pxl8_tilemap_render_tile(const pxl8_tilemap* tilemap, pxl8_gfx_ctx* gfx, u16 tile_id, i32 x, i32 y, u8 flags);
|
||||
|
||||
bool pxl8_tilemap_is_solid(const pxl8_tilemap* tilemap, u32 x, u32 y);
|
||||
bool pxl8_tilemap_check_collision(const pxl8_tilemap* tilemap, i32 x, i32 y, i32 w, i32 h);
|
||||
|
||||
pxl8_tilemap* pxl8_tilemap_new(u32 width, u32 height, u32 tile_size);
|
||||
void pxl8_tilemap_destroy(pxl8_tilemap* tilemap);
|
||||
u16 pxl8_tilemap_get_tile_id(const pxl8_tilemap* tilemap, u32 layer, u32 x, u32 y);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue