A game engine for top-down 2D RPG games.
rpg game-engine raylib c99
1#include <keraforge.h> 2#include <raylib.h> 3#include <stdio.h> 4#include <string.h> 5 6f32 kf_deadzone = 0.2f; 7 8struct _kf_inputbinds kf_inputbinds = { 9 .count = 1, 10}; 11 12kf_inputbind_t kf_addinput(char *id, KeyboardKey key, MouseButton mouse, GamepadButton gamepad, GamepadAxis axis) 13{ 14 kf_inputbind_t i = kf_inputbinds.count; 15 if (i >= KF_INPUTBIND_MAX) 16 { 17 fprintf(stderr, "error: max keybind count is 255.\n"); 18 return -1; 19 } 20 kf_inputbinds.count++; 21 22 printf("add keybind: %d: %s (k=%d m=%d g=%d x=%d)\n", i, id, key, mouse, gamepad, axis); 23 kf_inputbinds.id[i] = id; 24 kf_inputbinds.key[i] = key; 25 kf_inputbinds.mouse[i] = mouse; 26 kf_inputbinds.gamepad[i] = gamepad; 27 kf_inputbinds.axis[i] = axis; 28 29 return i; 30} 31 32kf_inputbind_t kf_getinput(char *id) 33{ 34 for (int i = 0 ; i < KF_INPUTBIND_MAX ; i++) 35 { 36 if (strcmp(id, kf_inputbinds.id[i]) == 0) 37 { 38 return i; 39 } 40 } 41 42 return KF_INPUTBIND_NONE; 43} 44 45int kf_checkkeypress(kf_inputbind_t id) { return kf_inputbinds.key[id] != KEY_NULL && IsKeyPressed(kf_inputbinds.key[id]); } 46int kf_checkkeyrelease(kf_inputbind_t id) { return kf_inputbinds.key[id] != KEY_NULL && IsKeyReleased(kf_inputbinds.key[id]); } 47int kf_checkkeydown(kf_inputbind_t id) { return kf_inputbinds.key[id] != KEY_NULL && IsKeyDown(kf_inputbinds.key[id]); } 48int kf_checkkeyup(kf_inputbind_t id) { return kf_inputbinds.key[id] != KEY_NULL && IsKeyUp(kf_inputbinds.key[id]); } 49int kf_checkmousepress(kf_inputbind_t id) { return kf_inputbinds.mouse[id] != MOUSE_BUTTON_UNKNOWN && IsMouseButtonPressed(kf_inputbinds.mouse[id]); } 50int kf_checkmouserelease(kf_inputbind_t id) { return kf_inputbinds.mouse[id] != MOUSE_BUTTON_UNKNOWN && IsMouseButtonReleased(kf_inputbinds.mouse[id]); } 51int kf_checkmousedown(kf_inputbind_t id) { return kf_inputbinds.mouse[id] != MOUSE_BUTTON_UNKNOWN && IsMouseButtonDown(kf_inputbinds.mouse[id]); } 52int kf_checkmouseup(kf_inputbind_t id) { return kf_inputbinds.mouse[id] != MOUSE_BUTTON_UNKNOWN && IsMouseButtonUp(kf_inputbinds.mouse[id]); } 53int kf_checkgamepadpress(kf_inputbind_t id) { return kf_inputbinds.gamepad[id] != GAMEPAD_BUTTON_UNKNOWN && IsGamepadButtonPressed(0, kf_inputbinds.gamepad[id]); } 54int kf_checkgamepadrelease(kf_inputbind_t id) { return kf_inputbinds.gamepad[id] != GAMEPAD_BUTTON_UNKNOWN && IsGamepadButtonReleased(0, kf_inputbinds.gamepad[id]); } 55int kf_checkgamepaddown(kf_inputbind_t id) { return kf_inputbinds.gamepad[id] != GAMEPAD_BUTTON_UNKNOWN && IsGamepadButtonDown(0, kf_inputbinds.gamepad[id]); } 56int kf_checkgamepadup(kf_inputbind_t id) { return kf_inputbinds.gamepad[id] != GAMEPAD_BUTTON_UNKNOWN && IsGamepadButtonUp(0, kf_inputbinds.gamepad[id]); } 57float kf_getgamepadaxis(kf_inputbind_t id) { return kf_inputbinds.axis[id] != GAMEPAD_AXIS_UNKNOWN ? GetGamepadAxisMovement(0, kf_inputbinds.gamepad[id]) : 0; } 58 59int kf_checkinputpress(kf_inputbind_t id) 60{ 61 return kf_checkkeypress(id) || kf_checkmousepress(id) || kf_checkgamepadpress(id); 62} 63 64int kf_checkinputrelease(kf_inputbind_t id) 65{ 66 return kf_checkkeyrelease(id) || kf_checkmouserelease(id) || kf_checkgamepadrelease(id); 67} 68 69int kf_checkinputdown(kf_inputbind_t id) 70{ 71 return kf_checkkeydown(id) || kf_checkmousedown(id) || kf_checkgamepaddown(id); 72} 73 74int kf_checkinputup(kf_inputbind_t id) 75{ 76 return kf_checkkeyup(id) || kf_checkmouseup(id) || kf_checkgamepadup(id); 77}