Skip to content

Terria-K/Teuria

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Teuria

A Simple Game Engine made from MonoGame

This game engine includes a basic functionality you need for 2D game development.

This engine is still work-in-progress and still needs more improvements. It is heavily inspired from Monocle and Godot. This has a Nodes and ECS system combined together to make things easy to use, and straightforward for beginners that has different game development experience whether they want ECS or Nodes. It is not usable for larger projects, but it is useful for starters who wants to get in to Monogame.

  • ECS
  • Scenes
  • Coroutines
  • Draw Images
  • Camera
  • Physics
  • Audio
  • User Interfaces

Getting Started

We first need to create a game class that is inherits to Engine, and instance the game in Program.cs

using Teuria;
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
// YourGame.cs
public class YourGame : TeuriaEngine
{
    public YourGame(int width, int height, int screenWidth, int screenHeight, string windowTitle, bool fullScreen) : base(width, height, screenWidth, screenHeight, windowTitle, fullScreen)
    {
    }

    /** We need to setup the scene renderer before going any further */
    protected override void Init()
    {
        var camera = new Camera();
		Scene = new MainScene(Content, camera);
    }
}

// MainScene.cs
public class MainScene : Scene 
{
	public MainScene(ContentManager content, Camera camera) : base(content, camera) {}
	
	public override void Hierarchy(GraphicsDevice device) 
	{
		// Setup the main Renderer
		var sceneCanvas = new SceneCanvas(this, Camera, Color.CornflowerBlue); 
        Add(sceneCanvas);
		/** Load Content Here */
		// We need the font first, but we can use the built-in font
		var font = FontText.Create("Teuria/Rubik-Regular");
		
		/** Instance any Entity here */
		var helloWorld = new Label(font);
		
		/** Add them to the scene */
		Add(helloWorld);
		base.Ready(device);
	}
}

// Program.cs
public static class Program
{
    [STAThread]
    static void Main()
    {
        using (var game = new PongPing(720, 1024, 480, 720, "Pong Ping", false))
            game.Run();
    }
}

Switching through Scene

Switching scene is also very simple, you just need to replace the current scene from the game using SceneRenderer.

// We need to change the scene using the SceneRenderer built-in to Scene
var scene = new NewScene(Content, null);
SceneRenderer.ChangeScene(scene);

Moving the Camera

Here is how you can move the camera, allowing you to make a cutscene, shake effects and more possibilities!

// Change the position
Camera.Position = new Vector2(45f, 45f);
// Change Zoom
Camera.Zoom = new Vector2(1.2f, 1.2f);
// Change Offset
Camera.Offset = new Vector2(65f, 65f);

Loading an image

There is two ways to load an image, Content ways or TextureImporter ways. The TextureImporter will just use the Texture2D.FromStream() to load an image from stream, but this is also managed by the engine and will be freed automatically when the program is terminated or freed by Sprite when cleanup is enabled.

/** Remember to always load image in the 'Hierarchy'. */

// This is loaded using MGCB Editor
var mgcbImg = Content.Load<Texture2D>("bat");
// This is loaded using TextureImporter Load Image
var texImpImg = TextureImporter.LoadImage(device, "bat.png");

// Manually Dispose an image loaded. (This is not required as the engine and Monogame Framework will handle all of those)
mgcbImg.Dispose();
TextureImporter.CleanUp(texImpImg);
base.Ready(device);

About

A Simple Game Engine made from MonoGame

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published