This guide walks you through building a complete interactive Fazen2d program from scratch, going beyond the bundledDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/adi3120/Fazen2d/llms.txt
Use this file to discover all available pages before exploring further.
main.cpp demo. By the end you will understand how to initialize the engine, compose shapes, drive the render loop, and let the user exit cleanly — the foundation of every Fazen2d application.
Program Structure
Include the umbrella header
Add a single
#include at the top of your source file:Fazen.h is an umbrella header that transitively pulls in every Fazen2d subsystem — ConsoleHandler, GraphicsRenderer, KeyboardHandler, MouseHandler, TimeManager, StateManager, MathUtils, all color constants, and all shape headers (Box, Circle, Line, Point, Text). You do not need to include any of those individually for a typical program.Initialize the Fazen engine
Construct a The constructor internally instantiates a
Fazen object, passing the width and height of your console buffer in character cells:ConsoleHandler that allocates the back-buffer (CHAR_INFO*), configures the console font, sets the window size, and acquires the output and input handles. All other subsystems (graphics, keyboardHandler, mouseHandler, timer) are ready to use immediately after construction as public members of game.Choose dimensions that fit comfortably in your terminal. Requesting a buffer larger than the current console window size may clip the output or resize the window automatically.Create shapes
Instantiate shapes using their constructors. Every shape accepts a position, size parameters, and a Shapes are plain value objects — they hold their own position state.
short color value from the ConsoleColor enum:translate(dx, dy) accumulates floating-point offsets that are truncated to integers when the shape writes into the buffer.Run the render loop
Every Fazen2d program follows the same three-step cycle inside a loop:
background() must be called first in every iteration; it overwrites the entire buffer, erasing the previous frame. display() must be called last; it sends the completed buffer to the Windows console via WriteConsoleOutputW.Handle ESC exit with CheckForUserExit()
Use This gives users a reliable, low-latency exit path without requiring any platform-specific signal handling on your part.
keyboardHandler.CheckForUserExit() as your loop condition rather than true. It polls VK_ESCAPE via GetAsyncKeyState and returns true the moment the user holds the Escape key:Complete Example
The program below draws a bouncing box, displays a persistent label, and exits when the user presses ESC. It demonstrates all five steps above working together.Key Observations
- Call
background()at the top of every frame.GraphicsRenderer::background()fills the entireCHAR_INFOarray with space characters at the given color attribute. Skipping it causes shape trails to accumulate across frames because the buffer is never cleared. - Float positions are truncated to integers internally.
translate(dx, dy)accumulates the floating-point delta into the shape’sxandyfields, but whendraw()writes into the buffer it casts coordinates tointfor the array index calculation (x + width * y). Use small float deltas (e.g.,0.1f–0.5f) to produce smooth sub-cell animation. - Shapes are not automatically clipped beyond console edges. If a shape’s computed buffer index falls outside the allocated
CHAR_INFOarray, the write is out of bounds. Guard everytranslate()call with boundary checks (as the bouncing box example above does) to keep positions within[0, width)×[0, height).
Next Steps
Frame Loop Internals
Understand how
background(), draw(), and display() interact with the CHAR_INFO back-buffer and the Win32 WriteConsoleOutputW API.Coordinate System
Learn how console cell coordinates map to the back-buffer index, and how
StateManager applies a global center offset.GraphicsRenderer API
Full reference for
background(), draw(), and display() including parameter types and internal behavior.Keyboard Input
Explore
IsKeyPressed(), IsKeyReleased(), and CheckForUserExit() for richer interactive control schemes.