level names

This commit is contained in:
KikooDX 2021-12-18 12:47:35 +01:00
parent 14e7c15326
commit 87bfda98ab
2 changed files with 16 additions and 4 deletions

View File

@ -11,6 +11,11 @@ struct LevelBin {
uint8_t data[];
} __attribute__((__packed__));
struct LevelBinNamed {
struct LevelBin *bin;
char *name;
};
struct Level {
int width, height, size, id;
uint8_t *data;

View File

@ -12,8 +12,11 @@ static struct Level level;
extern bopti_image_t bimg_tileset;
extern struct LevelBin kble_test, kble_burn, kble_bounce;
static const struct LevelBin *levels[] = {&kble_test, &kble_burn, &kble_bounce,
NULL};
static const struct LevelBinNamed levels[] = {
{&kble_test, "gentle introduction"},
{&kble_burn, "these are rare"},
{&kble_bounce, "deceptive road"},
{NULL, NULL}};
static void level_free(void);
@ -34,7 +37,7 @@ level_deinit(void)
void
level_load(int id)
{
const struct LevelBin *const b = levels[id];
const struct LevelBin *const b = levels[id].bin;
int i = b->width * b->height;
level_free();
level.width = b->width;
@ -58,7 +61,7 @@ level_reload(void)
void
level_next(void)
{
if (levels[level.id + 1] != NULL)
if (levels[level.id + 1].bin != NULL)
level_load(level.id + 1);
else
level_reload();
@ -105,6 +108,10 @@ level_draw(void)
vd->img_y, TILE_SIZE, TILE_SIZE, 0);
}
}
/* level name */
dprint_opt(DWIDTH - 2, DHEIGHT - 2, C_WHITE, C_BLACK, DTEXT_RIGHT,
DTEXT_BOTTOM, "%s", levels[level.id].name);
}
int