Skip to content

Getting Started πŸš€

Leon Schimmel edited this page Mar 2, 2025 · 8 revisions

Installation 🌐

  1. Open your project folder
  2. Open your projects NuGet package manager
  3. Search for ConsoleNexusEngine by the author BlyZe
  4. Install the newest version
  5. Congrats! You can now start to make your first game πŸ₯³

Implementing ConsoleGame πŸ‘ͺ

using ConsoleNexusEngine;
using ConsoleNexusEngine.IO;

public sealed class TestGame : NexusConsoleGame
{
    public TestGame()
    {
        
    }

    protected override void Load()
    {
        // Called once before the start of the game.
        // Import game files and load resources here.
    }

    protected override void Update(in NexusInputCollection inputs)
    {
        // Called every frame and contains the input that were made last frame.
    }

    protected override void OnCrash(Exception exception)
    {
        // Called once if an unhandled exception occurs.
        // Show the user an error message and write into a log here.
    }

    protected override void CleanUp()
    {
        // Called once after stopping the game.
        // Clean up used files or stop music here
    }
}

Customizing your console game 🌈

// Set the allowed input types
Settings.InputTypes = NexusInputType.All;

// Set the color palette of the console
Settings.ColorPalette = new WindowsColorPalette();

// Set the font family and size of the console
Settings.Font = new NexusFont("Terminal", new NexusSize(25));

// Set the key that should immediately stop the game
Settings.StopGameKey = NexusKey.Escape;

// Set the title of the console
Settings.Title = "My first game";

Run your console game (best practices) πŸƒπŸΌ

To use this code block you need to add the namespace ConsoleNexusEngine.Helpers

// If the current console window is a conhost.exe process, this returns true
if (!NexusEngineHelper.IsSupportedConsole())
{
    // This restarts the whole program in a conhost.exe process, so better use it at the start of the program
    // Due to Windows limitations this is the only way to properly ensure that the current window is a conhost.exe process
    // Optionally you can request to start the app as administrator
    NexusEngineHelper.StartInSupportedConsole();
    return;
}
// Create the game in a using block because it's disposable
// It's good practise to use a using block to make sure the game is properly disposed after it ended
using (var game = new TestGame())
{
    // This starts the game and blocks the current thread until the game is stopped by using the StopGameKey
    game.Start();
    
    // This stops the console game and shuts down the game thread
    game.Stop();
}

Clone this wiki locally