Giter Site home page Giter Site logo

damian-666 / orbit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bijington/orbit

0.0 1.0 0.0 11.85 MB

The Orbit engine is a game engine built on top of .NET MAUI Graphics. The objective is to firstly enjoy the journey of building a game engine and secondly providing a framework that allows us to utilise the best parts of a cross-platform framework while building a 'typical' game.

C# 100.00%

orbit's Introduction

Orbit Engine

The Orbit engine is a game engine built on top of .NET MAUI Graphics. The objective is to firstly enjoy the journey of building a game engine and secondly providing a framework that allows us to utilise the best parts of a cross-platform framework while building a 'typical' game.

The game loop approach

The engine provides a 'typical' game loop approach where it will process input from the user (TBA), call update across the scene and game objects, perform a render cycle for the scene and game objects and then wait until the next loop of the previous is ready.

flowchart LR
    processInput([Process Input]) -->
    update([Update Game]) -->
    render([Render]) -->
    wait([Wait]) --> processInput

Example usage

This section aims at explaining how to use the engine in your project.

Registering with the MauiAppBuilder

The first step is to register the game engine in your MauiProgram.cs file using the UseOrbitEngine extension method:

builder
    .UseMauiApp<App>()
    .UseOrbitEngine()

Currently this just registers the GameSceneManager provided by the framework as a singleton. In the majority of scenarios this should be fine, if you ever need multiple instances (perhaps you want 2 scenes running side-by-side in a couch based co-op mode) then you will likely need to register this as AddTransient manually yourself and don't call UseOrbitEngine.

Creating your first GameScene

A GameScene represents a screen in your game and its associated state. This is typically your home screen, actual game screen or even individual levels.

public class MainScene : GameScene
{
    public MainScene()
    {
        // Call Add(..) to add GameObjects to your scene.
    }

    public override void Render(ICanvas canvas, RectF dimensions)
    {
        base.Render(canvas, dimensions);

        // Render the state of your scene.
    }

    public override void Update(double millisecondsSinceLastUpdate)
    {
        base.Update(millisecondsSinceLastUpdate);

        // Update the state of your scene.
    }
}

Creating your first GameObject

A GameObject represents a single object in your game. It is recommended that you keep this as simple as possible.

public class Paddle : GameObject
{
    public override void Render(ICanvas canvas, RectF dimensions)
    {
        base.Render(canvas, dimensions);
    
        // Render the state of your object.
    }

    public override void Update(double millisecondsSinceLastUpdate)
    {
        base.Update(millisecondsSinceLastUpdate);

        // Update the state of your scene.
    }
}

Rendering your GameScene

The GameSceneView provides the surface on which your game will be rendered. The IGameSceneManager implementation allows you to load scenes into the GameSceneView and also then control the state of the scene (e.g. Pause, Stop, Start).

XAML

To render the GameSceneView in XAML first add the namespace:

xmlns:engine="clr-namespace:Orbit.Engine;assembly=Orbit.Engine"

Then add the view itself as part of the content of your page:

<engine:GameSceneView x:Name="GameView" />

NOTE: the GameSceneView inherits from Microsoft.Maui.Graphics.GraphicsView which gives a fair amount of touch based interaction should you need to. Orbit will eventually provide an encapsulated way of tracking user based touch/click interaction.

C#

It is also possible to build your page with just C#. First add the following using:

using Orbit.Engine;

Then add the view itself as part of the content of your page:

public MyPage()
{
    Content = new GameSceneView();
}

Loading a scene

Once you have added your GameSceneView you need to use the IGameSceneManager implementation to call LoadScene.

public MyPage(IGameSceneManager gameSceneManager, MainScene mainScene)
{
    gameSceneManager.LoadScene(mainScene, GameView);
}

This will leave the scene in the Loaded state, in order to actually start the game you will need to call gameSceneManager.Start().

orbit's People

Contributors

bijington avatar

Watchers

James Cloos avatar

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.