Code Monkey home page Code Monkey logo

console-game-engine's Introduction

Console-Game-Engine

The simple lightweight 2D framework to make console games easier

Getting started

Install

  • Create a Console App (.NET Framework) project in your IDE
  • Download or compile the Console-Game-Engine repository
  • Add references to the WindowsBase.dll and ConsoleGameEngine.dll assemblies

First step

  • Create a main game class and inherit it from the GameCore class:
using ConsoleGameEngine.Core.GameSystems.DefaultSystem;
or
using ConsoleGameEngine.Core.GameSystems.ECS;

// Note: see the examples below for understanding the game systems

...

class Game1 : GameCore {
  public Game1 : base(width: 32, height: 32, name: "Game1") { }
}
  • Run the game from Program.cs:
class Program {
  [STAThread] // That's important
  static void Main(string[] args) {
    var game = new Game1();
    game.Run();
  }
}

Examples

Default game system

The default system is a MonoGame-like game system

using ConsoleGameEngine.Core.GameSystems.DefaultSystem;

...

class Game1 : GameCore {
  public Game1 : base(width: 32, height: 32, name: "Game1") { }
  
    Point playerPosition;
    ConsoleTexture playerTexture;

    protected override void Initialize() {
      string[] textureData = new[] {
        " # ",
        "###",
        "# #"
      };
      playerTexture = new ConsoleTexture(textureData);
      playerTexture.Normalize();
      
      base.Initialize();
    }

    protected override void Update() {
      if (Input.IsKeyDown(Key.Right)) {
        playerPosition.X++;
      }
      if (Input.IsKeyDown(Key.Left)) {
        playerPosition.X--;
      }				
      
      base.Update();
    }

    protected override void Draw() {
      Graphics.Clear(' ');
      Graphics.Draw(playerTexture, playerPosition);
      
      base.Draw();
    }
}

ECS game system

The ECS (Entity-Component-System) is an extended game system with greater flexibility

using ConsoleGameEngine.Core.GameSystems.ECS;

...

class Game1 : GameCore {
  public Game1 : base(width: 32, height: 32, name: "Game1") { }
  
    Entity player;

    protected override void Initialize() {
      player = new Entity();
      Scene.AddEntity(player);
      
      string[] textureData = new[] {
        " # ",
        "###",
        "# #"
      };
      var playerTexture = new ConsoleTexture(textureData);
      playerTexture.Normalize();
      var playerSprite = new Sprite(playerTexture);      
      player.AddComponent(playerSprite);      

      base.Initialize();
    }

    protected override void Update() {
      if (Input.IsKeyDown(Key.Right)) {
        player.Transform.Position += new Point(1, 0);
      }
      if (Input.IsKeyDown(Key.Left)) {
        player.Transform.Position += new Point(-1, 0);
      }
      
      base.Update();
    }
}

console-game-engine's People

Contributors

crt09 avatar

Stargazers

Mike avatar Vladislav Chechyotkin avatar

console-game-engine's Issues

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.