A game engine for top-down 2D RPG games.
rpg game-engine raylib c99
at main 3.7 kB view raw
1#include <keraforge.h> 2#include <raylib.h> 3#include <string.h> 4 5 6f32 kf_deadzone = 0.2f; 7 8struct _kf_inputbinds kf_inputbinds = { 9 .count = 1, 10}; 11 12 13kf_inputbind_t kf_addinput(char *id, KeyboardKey key, KeyboardKey alt, MouseButton mouse, GamepadButton gamepad, GamepadAxis axis) 14{ 15 kf_inputbind_t i = kf_inputbinds.count; 16 if (i >= KF_INPUTBIND_MAX) 17 { 18 KF_THROW("max keybind count is 255"); 19 return -1; /* unreachable */ 20 } 21 kf_inputbinds.count++; 22 23 // kf_logdbg("add keybind: %d: %s (k=%d a=%d m=%d g=%d x=%d)", i, id, key, alt, mouse, gamepad, axis); 24 kf_inputbinds.id[i] = id; 25 kf_inputbinds.key[i] = key; 26 kf_inputbinds.alt[i] = alt; 27 kf_inputbinds.mouse[i] = mouse; 28 kf_inputbinds.gamepad[i] = gamepad; 29 kf_inputbinds.axis[i] = axis; 30 31 return i; 32} 33 34kf_inputbind_t kf_getinput(char *id) 35{ 36 for (int i = 0 ; i < KF_INPUTBIND_MAX ; i++) 37 { 38 if (strcmp(id, kf_inputbinds.id[i]) == 0) 39 { 40 return i; 41 } 42 } 43 44 return KF_INPUTBIND_NONE; 45} 46 47 48int kf_checkkeypress(kf_inputbind_t id) 49{ 50 return 51 (kf_inputbinds.key[id] != KEY_NULL && IsKeyPressed(kf_inputbinds.key[id])) || 52 (kf_inputbinds.alt[id] != KEY_NULL && IsKeyPressed(kf_inputbinds.alt[id])); 53} 54 55int kf_checkkeyrelease(kf_inputbind_t id) 56{ 57 return 58 (kf_inputbinds.key[id] != KEY_NULL && IsKeyReleased(kf_inputbinds.key[id])) || 59 (kf_inputbinds.alt[id] != KEY_NULL && IsKeyReleased(kf_inputbinds.alt[id])); 60} 61 62int kf_checkkeydown(kf_inputbind_t id) 63{ 64 return 65 (kf_inputbinds.key[id] != KEY_NULL && IsKeyDown(kf_inputbinds.key[id])) || 66 (kf_inputbinds.alt[id] != KEY_NULL && IsKeyDown(kf_inputbinds.alt[id])); 67} 68 69int kf_checkkeyup(kf_inputbind_t id) 70{ 71 return 72 (kf_inputbinds.key[id] != KEY_NULL && IsKeyUp(kf_inputbinds.key[id])) || 73 (kf_inputbinds.alt[id] != KEY_NULL && IsKeyUp(kf_inputbinds.alt[id])); 74} 75 76int kf_checkmousepress(kf_inputbind_t id) 77{ 78 return kf_inputbinds.mouse[id] != MOUSE_BUTTON_UNKNOWN && IsMouseButtonPressed(kf_inputbinds.mouse[id]); 79} 80 81int kf_checkmouserelease(kf_inputbind_t id) 82{ 83 return kf_inputbinds.mouse[id] != MOUSE_BUTTON_UNKNOWN && IsMouseButtonReleased(kf_inputbinds.mouse[id]); 84} 85 86int kf_checkmousedown(kf_inputbind_t id) 87{ 88 return kf_inputbinds.mouse[id] != MOUSE_BUTTON_UNKNOWN && IsMouseButtonDown(kf_inputbinds.mouse[id]); 89} 90 91int kf_checkmouseup(kf_inputbind_t id) 92{ 93 return kf_inputbinds.mouse[id] != MOUSE_BUTTON_UNKNOWN && IsMouseButtonUp(kf_inputbinds.mouse[id]); 94} 95 96int kf_checkgamepadpress(kf_inputbind_t id) 97{ 98 return kf_inputbinds.gamepad[id] != GAMEPAD_BUTTON_UNKNOWN && IsGamepadButtonPressed(0, kf_inputbinds.gamepad[id]); 99} 100 101int kf_checkgamepadrelease(kf_inputbind_t id) 102{ 103 return kf_inputbinds.gamepad[id] != GAMEPAD_BUTTON_UNKNOWN && IsGamepadButtonReleased(0, kf_inputbinds.gamepad[id]); 104} 105 106int kf_checkgamepaddown(kf_inputbind_t id) 107{ 108 return kf_inputbinds.gamepad[id] != GAMEPAD_BUTTON_UNKNOWN && IsGamepadButtonDown(0, kf_inputbinds.gamepad[id]); 109} 110 111int kf_checkgamepadup(kf_inputbind_t id) 112{ 113 return kf_inputbinds.gamepad[id] != GAMEPAD_BUTTON_UNKNOWN && IsGamepadButtonUp(0, kf_inputbinds.gamepad[id]); 114} 115 116float kf_getgamepadaxis(kf_inputbind_t id) 117{ 118 return kf_inputbinds.axis[id] != GAMEPAD_AXIS_UNKNOWN ? GetGamepadAxisMovement(0, kf_inputbinds.gamepad[id]) : 0; 119} 120 121 122int kf_checkinputpress(kf_inputbind_t id) 123{ 124 return kf_checkkeypress(id) || kf_checkmousepress(id) || kf_checkgamepadpress(id); 125} 126 127int kf_checkinputrelease(kf_inputbind_t id) 128{ 129 return kf_checkkeyrelease(id) || kf_checkmouserelease(id) || kf_checkgamepadrelease(id); 130} 131 132int kf_checkinputdown(kf_inputbind_t id) 133{ 134 return kf_checkkeydown(id) || kf_checkmousedown(id) || kf_checkgamepaddown(id); 135} 136 137int kf_checkinputup(kf_inputbind_t id) 138{ 139 return kf_checkkeyup(id) || kf_checkmouseup(id) || kf_checkgamepadup(id); 140}