From 87bfda98ab35799bfab4d21d6b6885c910f1a019 Mon Sep 17 00:00:00 2001 From: KikooDX Date: Sat, 18 Dec 2021 12:47:35 +0100 Subject: [PATCH] level names --- inc/level.h | 5 +++++ src/level.c | 15 +++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/inc/level.h b/inc/level.h index eaf87bd..8c1790d 100644 --- a/inc/level.h +++ b/inc/level.h @@ -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; diff --git a/src/level.c b/src/level.c index d5e337d..37c4c3a 100644 --- a/src/level.c +++ b/src/level.c @@ -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