A game engine for top-down 2D RPG games.
rpg game-engine raylib c99
1#include <keraforge.h> 2#include <raylib.h> 3 4static struct kf_uiconfig _kf_uiconfig = { 5 .select = KF_INPUTBIND_NONE, 6 .cancel = KF_INPUTBIND_NONE, 7 .up = KF_INPUTBIND_NONE, 8 .down = KF_INPUTBIND_NONE, 9 .fmt = " %s ", 10 .selectfmt = "> %s <", 11 .fontsize = 20, 12 .bg = BLACK, 13 .fg = WHITE, 14 .panelheight = 200, 15 .xpadding = 8, 16 .ypadding = 16, 17}; 18 19struct kf_uiconfig *kf_ui_getconfig(void) 20{ 21 return &_kf_uiconfig; 22} 23 24int kf_ui_panel(char *title) 25{ 26 int y = GetScreenHeight() - _kf_uiconfig.panelheight; 27 DrawRectangle(0, y, GetScreenWidth(), _kf_uiconfig.panelheight, _kf_uiconfig.bg); 28 29 if (title) 30 { 31 y += _kf_uiconfig.ypadding; 32 DrawText(title, _kf_uiconfig.xpadding, y, _kf_uiconfig.fontsize, _kf_uiconfig.fg); 33 y += _kf_uiconfig.fontsize; 34 } 35 36 return y; 37} 38 39int kf_ui_choice(char *title, char **choices, int nchoices, int *choice) 40{ 41 int y = kf_ui_panel(title); 42 43 if (*choice >= nchoices) 44 goto skip_text; 45 46 for (int i = 0 ; i < nchoices ; i++) 47 { 48 char *c = choices[i]; 49 50 DrawText( 51 TextFormat(i == *choice ? _kf_uiconfig.selectfmt : _kf_uiconfig.fmt, c), 52 _kf_uiconfig.xpadding, 53 y, 54 _kf_uiconfig.fontsize, 55 _kf_uiconfig.fg 56 ); 57 58 y += _kf_uiconfig.fontsize; 59 if (y >= GetScreenHeight()) 60 break; 61 } 62 63skip_text: 64 65 if (kf_checkinputpress(_kf_uiconfig.select) || kf_checkinputpress(_kf_uiconfig.cancel)) 66 return 1; 67 else if (kf_checkinputpress(_kf_uiconfig.down) && *choice < nchoices) 68 (*choice)++; 69 else if (kf_checkinputpress(_kf_uiconfig.up) && *choice > 0) 70 (*choice)--; 71 72 return 0; 73} 74 75int kf_ui_yesno(char *title, int *choice) 76{ 77 static char *yesno[] = { "yes", "no" }; 78 return kf_ui_choice(title, yesno, 2, choice); 79} 80 81int kf_ui_textinput(char *title, char *text); 82