GithubHelp home page GithubHelp logo

morasiu / termgine Goto Github PK

View Code? Open in Web Editor NEW
37.0 37.0 1.0 109 KB

Game engine for making terminal based games.

License: MIT License

C# 100.00%
cross-platform csharp dotnet-core engine game game-engine terminal terminal-based

termgine's Introduction

Hey ๐Ÿ‘‹, This is Hubert Morawski

Gmail Badge Linkedin Badge Github Badge Portfolio Badge

C# passionate who loves making bugs and removing features... Wait a second...

Some of my Github Stats

Morasiu

Github stats

termgine's People

Contributors

morasiu avatar tkaczz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

tkaczz

termgine's Issues

Terminal rendering does not respect scene size

When rendering an 80x30 scene on a terminal emulator of a different size (e.g. 120x30) the scene is improperly rendered, as the renderer does not return the carriage after the expected 80th column.

This is what happens when trying to rendering an 80x30 scene on a 120x30 terminal
error

And here's the appropriate rendering on a properly sized terminal
correct

The issue comes from the rendering portion of the Display class, more specifically in this function

private void DrawCurrentScene() {
    if (CurrentScene == null)throw new NullReferenceException("CurrentScene is null");
    Console.SetCursorPosition(0, 0);
    var currentContent = CurrentScene.Content.Split('\n');
    var currentColors = CurrentScene.ColorMask.Split('\n');

    for (var y = 0; y < CurrentScene.Height; y++) {
        for (var x = 0; x < CurrentScene.Width; x++) {
            var color = GetColorFromNumber(currentColors[y][x]);
            WriteInColor(currentContent[y][x], color);
        }
    }
}

because currentContent is generated by splitting the scene per newlines, but the actual newline character is never rendered, the scene will ever only be rendered correctly on a properly sized terminal.

Since defining a terminal buffer size or resizing the console windows is not supported outside of Windows, I'd suggest to simply add an empty WriteLine() after the inner cicle, so that after each row has been completely rendered, a new line is always drawn.

If that's an ok solution I can write up a pull request

[Suggestion] Replace project's Vector2 with System.Numerics.Vector2

Few possible reasons to do that:

  • standard Vector2 from .net libraries
  • "The Vector2 structure provides support for hardware acceleration."
  • less code to maintain

Edit: As I tried to experiment with this using System.Numerics.Vector2, few errors occurred due to x,y of Vector2 being floats. Inside of function's AddObjectToGlobalContent and AddObjectColorToGlobalColorMask, globalPositionY and globalPositionX need to be int's but result of addition on right side is float and this need to be converted to int. Of course this can lead to rounding errors i.e. rendering console char's/content at wrong place. To avoid that, generic Vector of int type need to be used, but that would lead to use of Span and as a result C# 7.3 requirement. Sample code:

Span<int> span = stackalloc int[] {1,1};
Vector<int> vector = new Vector<int>(span);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.