-
Notifications
You must be signed in to change notification settings - Fork 0
Introduction
TextScript is a lightweight, cross-platform terminal game engine designed for rapid prototyping and development of text-based games. Built on C++, it provides a simple and intuitive API for handling game loops, user input, and rendering text to the console. The engine is perfect for developers who want to focus on game logic without the complexities of graphics rendering. Core Concepts Application The TextScript::Application class is the foundation of any TextScript game. It manages the main game loop, initializes the engine, and handles the application's lifecycle. To create your own game, you must inherit from this class and override the key virtual functions: OnStart() and OnUpdate(). Game Loop The game loop is the heart of the engine. It continuously runs, calling OnUpdate() on every iteration. This is where you will implement your game logic, handle events, and update the game state. Logging TextScript provides a set of simple logging macros to help with debugging and providing feedback to the user. These macros are a convenient way to output information to the terminal. Getting Started
- Include the Engine To use the engine, you need to include the main header file:
#include "TextScript.h"
- Create Your Game Class Create a new class that inherits from TextScript::Application. This class will contain your game's specific logic. sandbox.h:
#pragma once
#include "TextScript.h"
class Game : public TextScript::Application {
public:
Game(const std::string& name) : TextScript::Application(name) {}
void OnStart() override {
// This function is called once when the application starts.
// Use it for initialization tasks.
LOG_INFO("Application is working");
}
void OnUpdate() override {
// This function is called every frame.
// Place your main game logic here.
LOG_INFO(""); // Example of logging a new line
}
};
- Initialize and Run the Application In your main.cpp, you will create an instance of your game class and call the Run() method to start the game loop. main.cpp:
#include "TextScript.h" // include game engine
#include "sandbox.h" // import our 'game'
int main() {
// Create an instance of our custom Game class
Game game("Sandbox App");
// Run the application's game loop
game.Run();
return 0;
}
Logging Macros TextScript provides the following logging macros for outputting messages to the console:
Macro | Description |
---|---|
LOG_INFO | Logs a general information message. |
LOG_WARN | Logs a warning message, often for non-critical issues. |
LOG_ERROR | Logs a critical error message. |
Example Usage:
void OnUpdate() override {
LOG_INFO("Player health: 100");
LOG_WARN("You are entering a dangerous area!");
if (player.isDead()) {
LOG_ERROR("Game Over! Player has died.");
}
}
To build your project with CMake, you'll need a CMakeLists.txt file. The engine assumes a specific directory structure where the Engine source code is located in a subdirectory. Here is a basic CMakeLists.txt file to get you started:
cmake_minimum_required(VERSION 3.10)
# Set the project name and language
project(project_name_here CXX)
# Set output directories for executables and libraries
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
# Add the TextScript engine as a subdirectory
# Note: You must copy the 'Engine' directory from the repository into your project.
add_subdirectory(Engine)
# Add your project as a subdirectory
# Replace 'your_project_directory' with the actual name of your game's source folder.
add_subdirectory(your_project_directory)
Note: For this setup to work, your project structure should look like this:
my_game_project/
├── CMakeLists.txt
├── Engine/
│ ├── ... (TextScript engine source files)
└── your_project_directory/
├── sandbox.h
└── main.cpp
Alternatively, you can clone the entire repository which includes a Sandbox directory as a template.