2D Cross-Platform Game Engine in C#

This is the result of a 3-week project to create a cross-platform 2D game engine in C# and write a game in it.

  • Space Invaders demo project
  • Component system
  • Audio system (sources, streamed, scriptable and persistent audio)
  • Shader support, audio streaming, texture atlas handling, dynamic batching
  • OpenGL for rendering, OpenAL for audio
  • Developer mode console running side-by-side with game (in DEVMODE build)
  • Tested on Windows and OS X Mountain Lion
  • And more...

Space Invaders demo project included! Excuse the terrible gif recorder filtering out full green.

Game Engine Demo GIF

Important! This is in an extremely early stage and many parts are missing or incomplete, mostly because they weren't needed to write a working Space Invaders game (and even then using shaders was fun but totally unnecessary). One example is the collision system accepting non-convex shapes but applying the separating axis theorem on the convex hull of the shape. The font manager is extremely rudimentary and will return a unique texture for each string, and the dynamic batching will ignore your draw order!

Splash Screen Example

This is the splash screen from the Space Invaders demo.

class SplashContext
{
    public GameContext Context { get; private set; }
    public SplashContext()
    {
        Context = new GameContext("Splash Screen");

        // Run in 60 fps
        Context.TargetUpdateRate = 60;
        Context.TargetRenderRate = 60;

        // Create a new game object and give it the splash component
        GameObject splash = new GameObject();
        splash.AddComponent(new SplashComponent());
        // Add the game object to the splash screen context
        Context.AddGameObject(splash);
    }
}

//
//  Splash component
//
class SplashComponent : GameComponent
{
    /* not gonna show ~90 lines of code here */
    public override void OnStart() { }
    public override void OnKeyUp(Key key, KeyModifiers modifiers) { }
    public override void OnUpdate() { }
    public override void OnRender() { }
}

//
//  And this is how you launch the game into the splash screen
//
{
    // Set up the game window
    GameWindow gameWindow = new GameWindow(WINDOW_CAPTION, WINDOW_WIDTH, WINDOW_HEIGHT);

    // Launch into the splash screen!
    gameWindow.StartGameContext(new SplashContext().Context);
}

For full splash component source, see https://github.com/borup3/Code-Cafe-Game-Engine/blob/master/App/SpaceInvaders/Components/Splash/SplashComponent.cs.

Installation

If you need more info on how to set it up, then contact me and I will try to provide a more thorough guide.

  1. Extract _Dependencies.zip into Framework/ and copy the _Dependencies/x86/ contents into App/bin/<configuration> for x86 builds or _Dependencies/x64/ for x64 builds.
  2. Install NuGet.
  3. Run the App solution.

Pull Requests & License

You're free to fork this project and to submit pull requests to this repository. It's released under the MIT license so knock yourself out. I do appreciate if you tell me what you're using the code for, purely out of interest (and a potential blogging topic on my website http://thecode.cafe if it's really cool). If you make nice changes on a fork or personal project, everyone would benefit if you submit a pull request to bring those changes into this repository as well.

Link

This project is hosted on GitHub and is available here: https://github.com/borup3/Code-Cafe-Game-Engine.