42 lines
1.0 KiB
C
42 lines
1.0 KiB
C
#ifndef _tilemap_h
|
|
#define _tilemap_h
|
|
|
|
#include "corelib/render.h"
|
|
|
|
#define TILEMAP_MAX_SIZE 16384
|
|
#define TILESET_MAX_SIZE 255
|
|
|
|
typedef struct tile_t {
|
|
sprite_t sprite;
|
|
short walkable;
|
|
} tile_t;
|
|
|
|
typedef struct tileset_t {
|
|
tile_t* set;
|
|
size_t size;
|
|
} tileset_t;
|
|
|
|
typedef struct tilemap_t {
|
|
size_t tiles[TILEMAP_MAX_SIZE];
|
|
int width, height;
|
|
float x, y;
|
|
} tilemap_t;
|
|
|
|
static inline int get_tilemap_index(const tilemap_t* tilemap, int x, int y) {
|
|
return x + y * tilemap->width;
|
|
}
|
|
static inline size_t get_tile(const tilemap_t* tilemap, int x, int y) {
|
|
return *(tilemap->tiles + get_tilemap_index(tilemap, x, y));
|
|
}
|
|
static inline void set_tile(tilemap_t* tilemap, int x, int y, size_t value) {
|
|
*(tilemap->tiles + get_tilemap_index(tilemap, x, y)) = value;
|
|
}
|
|
|
|
extern void draw_tilemap(const tilemap_t* tilemap, const tileset_t* tileset);
|
|
/*load csv tilemap from file*/
|
|
extern int load_tilemap(tilemap_t* tilemap, const char* file);
|
|
/*write csv tilemap to file*/
|
|
extern int save_tilemap(const tilemap_t* tilemap, const char* file);
|
|
|
|
#endif /* _tilemap_h */
|