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