A lightweight game engine written in pure C, designed for console-based card based games.
MiniCore is a minimalistic yet powerful framework that provides:
- Flexible "object-oriented" architecture
- Interface-based component system
- Screen rendering capabilities
- Input handling
- Event system
- Modular Design: Core/Implementation separation
- Interface System:
- CardHandler
- Drawable
- Interactable
- Dynamic
- ButtonHandler
- PositionHandler
- Updateable
- Screen Management: ASCII/Unicode rendering
- Input Handling: Keyboard events
- Memory Efficient: No dynamic allocations by default
The framework comes with a Solitaire card game implementation showcasing the engine's capabilities:
Clone the repository
git clone https://github.com/gooderfreed/minicore.git
Build the project
Build all implementations
make
or build a specific implementation:
Go to the implementation directory
cd impl/solitaire
Build the project
make
First, define your object structure and initialize it with required interfaces:
typedef struct MyObject {
ObjectInterfaces interfaces;
// Your object data
} MyObject;
MyObject init_object(void) {
MyObject obj = {0};
static const Drawable drawable = {
.print = my_print_function
};
static const Interactable interactable = {
.move = my_move_function,
.place_cursor = my_place_cursor_function
};
obj.interfaces = (ObjectInterfaces){
.name = "MyObject",
.capabilities = {
.is_drawable = true,
.is_interactable = true
},
.drawable = &drawable,
.interactable = &interactable
};
return obj;
}
Add your object to the map to make it part of the game world:
MyObject my_object = init_object();
Screen screen = init_screen();
Map map = {
.objects = {
{
{&my_object, MY_OBJECT_DEFAULT_COORDS},
// Other objects...
}
},
.global_coords = (Coords){.x = 0, .y = 0}
};
// Initialize cursor and core
MapObject object = map_get_current_object(&map);
Cursor cursor = init_cursor(object.object, object.default_coords);
Core core = init_core(&map, &cursor, &screen);
Handle input and update screen:
while (true) {
wint_t input = getwchar();
bool need_update = true;
switch (input) {
case KEY_LEFT: core_move(&core, CURSOR_LEFT); break;
case KEY_RIGHT: core_move(&core, CURSOR_RIGHT); break;
case KEY_SPACE: core_action(&core); break;
default: need_update = false;
}
if (need_update) {
core_update_screen(&core);
}
}
Licensed under the MIT License. See LICENSE for details.
Contributions are welcome! Please feel free to submit a Pull Request.