CmdFX
A lightweight game engine for your terminal.
cmdfx is a lightweight game engine for your terminal, allowing you to create some pretty wild things. It is designed to be simple and easy to use, while still providing a powerful set of features.
It is written in C and is available cross-platform. It is licensed under the MIT license.
🍎 Features
- Cross-platform: cmdfx is available on Windows, macOS, and Linux.
- Lightweight: cmdfx is designed to be lightweight and fast.
- Easy to use: cmdfx is simple to use and easy to learn.
- Powerful: cmdfx provides a powerful set of features for creating terminal-based games.
📋 Highlighted Features
For a full method list, check out the documentation.
- Events API
- Handle window events such as key presses and window resizing.
- Get the current state of the keyboard.
- Canvas API
- Draw characters and shapes on the terminal.
- Set foreground and background colors.
- Clear the screen.
- Get the size of the terminal and the screen.
- ...and much more!
- Sprites API
- Load and draw sprites on the terminal.
- Set the color of a sprite.
- Create Gradients for a sprite.
- ...and much more!
- Builder API
- Easily build 2D arrays of characters and strings.
- Set the color of the text.
- Create gradients of text and colors!
- ...and much more!
- Physics Engine
- Create and manage physics objects with the Sprite API.
- Set the velocity and acceleration of a sprite.
- Detect collisions between sprites.
- ...and much more!
- Input API
- Get the current state of the keyboard and mouse events.
- Handle key presses and key releases.
- ..and much more!
- Cross-Platform Exposure
- Expose platform-specific features and utilities such as setting the title of the terminal.
📦 Installation
You can download the latest release of cmdfx from the releases page.
🚀 Examples
int main() {
}
void Canvas_setChar(int x, int y, char c)
Sets a character at a specific position.
void Canvas_hLine(int x, int y, int width, char c)
Draws a horizontal line.
void Canvas_setForeground(int rgb)
Sets the foreground color at the current cursor position.
void Canvas_fillCircle(int x, int y, int radius, char c)
Fills a circle with a character.
The main header file for CmdFX. Includes the rest of the library.
int main() {
}
@ GRADIENT_ANGLE_45
A 45-degree gradient.
Definition builder.h:484
void Sprite_moveTo(CmdFX_Sprite *sprite, int x, int y)
Moves a sprite to the given position.
int Sprite_setForegroundGradientAll(CmdFX_Sprite *sprite, enum CmdFX_GradientDirection direction, int numColors,...)
Sets a foreground gradient using RGB colors.
CmdFX_Sprite * Sprite_loadFromFile(const char *path, int z)
Creates a new sprite from a file.
int Sprite_draw(int x, int y, CmdFX_Sprite *sprite)
Draws a sprite to the terminal.
CmdFX_Sprite * Sprite_createFilled(int width, int height, char c, char *ansi, int z)
Creates a new sprite with the given dimensions.
int Sprite_setForegroundAll(CmdFX_Sprite *sprite, int rgb)
Sets the foreground color of the sprite at the given position.
Represents a sprite that can be drawn to the terminal.
Definition sprites.h:30
#include <stdio.h>
printf("Terminal resized from %dx%d to %dx%d\n", resizeEvent->prevWidth, resizeEvent->prevHeight, resizeEvent->newWidth, resizeEvent->newHeight);
return 0;
}
int main() {
int r = 0;
while (1) {
}
}
void Canvas_clearScreen()
Clears the screen.
int addCmdFXEventListener(unsigned int id, CmdFX_EventCallback callback)
Adds an event listener.
#define CMDFX_EVENT_RESIZE
Called when the terminal is resized.
Definition events.h:37
The main event structure for CmdFX.
Definition events.h:149
void * data
A pointer to the data associated with the event.
Definition events.h:161
The payload for the CMDFX_EVENT_RESIZE event.
Definition events.h:42
More examples can be found in the samples directory.
📝 Contributing
If you would like to contribute to cmdfx, please see the contributing guidelines. All contributions are welcome!