- Language: C# 9.0+ (.NET 9 Target)
- Framework: MonoGame
- Architecture: Component-based Game Engine (Hybrid EC framework)
- Goal: Cross-platform 2D game engine. Always mimic the engine's object-oriented principles, modularity, and maintain performance optimization.
Agents MUST use standard .NET Core CLI commands for executing workflows.
- Build Solution:
dotnet build MonoGo.sln - Clean Project:
dotnet clean MonoGo.sln - Run Samples:
dotnet run --project ./MonoGo.Samples/MonoGo.Samples.csproj - Linting / Code Quality:
dotnet formator rely on IDE/MSBuild-level analyzers (CSxxxx warnings). Address warnings proactively.
Tests use VSTest (dotnet test).
- List Available Tests:
dotnet test -t - Run All Tests:
dotnet test - Run a Single Test:
dotnet test --filter <TestName> - Run a Specific Test Class:
dotnet test --filter FullyQualifiedName~Namespace.TestClassName
- Namespaces: Block-scoped namespaces (
namespace MonoGo.Engine { ... }). Groupusingdirectives at the very top. - Naming:
PascalCasefor Classes/Methods/Properties._camelCasefor private fields (prefix with_).camelCasefor parameters/locals. - Formatting: 4 spaces (No Tabs). Allman style braces (new line for
{). Single-lineifwithout braces is permitted if concise. - Documentation: All public members MUST have XML documentation (
/// <summary>...</summary>). - Nullability: Mark nullability constructs appropriately. Use the null-forgiving operator (
!) only when logically safe.
The engine utilizes static Manager classes for globally accessible states. Always use these instead of creating local instances:
CameraMgr: AccessCameraMgr.Cameras[0]for the currently active camera.GameMgr&WindowMgr: For core game lifecycle and window/display properties.GraphicsMgr: For accessing the activeGraphicsDeviceand the customVertexBatch(used instead of MonoGame'sSpriteBatch).RenderMgr: Handles surfaces, viewport adapters, and full-screen post-processing.
- Architecture: Create logic by extending
MonoGo.Engine.EC.EntityorMonoGo.Engine.EC.Component. - Coroutines & Jobs: DO NOT use standard C#
async/awaitfor game-tick logic. UseEntity.StartCoroutine(IEnumerator routine)orEntity.StartJob()which are integrated directly into the engine's update loop. - Alarms: Do NOT use
System.Timers.TimerorSystem.Threading.Timerfor delayed logic. UseMonoGo.Engine.Utils.Alarminstead, as it safely ties into the game loop's time. - State Machines: The engine provides a native stack-based
MonoGo.Engine.Utils.StateMachine<T>. Use this instead of building custom state managers.
- Scene System (
MonoGo.Engine.SceneSystem): UseSceneandSceneMgrto manage game states and layers. - Content Management (
MonoGo.Engine.Resources): The engine usesResourceHubwhich holdsResourceBoximplementations (e.g.,DirectoryResourceBox) to load and unload assets dynamically. Do NOT rely purely on MonoGame'sContentManager.
- Viewport Adapters: For Independent-Resolution-Rendering, assign a ViewportAdapter to the RenderMgr (e.g.,
RenderMgr.ViewportAdapter = new ScalingViewportAdapter(1280, 720);). - World vs Screen Coordinates:
Input.ScreenMousePositionprovides raw screen coordinates. To get transformed world-space coordinates, ALWAYS useCameraMgr.Cameras[0].GetRelativeMousePosition(). - Surfaces (Managed RenderTargets): Use
MonoGo.Engine.Drawing.Surfaceinstead of rawRenderTarget2D. Surfaces automatically integrate withVertexBatchand matrix transformations. They use a static stack-based targeting system: callSurface.SetTarget(surface)to begin rendering to it (this automatically handles matrix states and batch flushing) andSurface.ResetTarget()when done. Render the surface itself easily viasurface.Draw(). - Rendering & Debugging: The engine uses a custom
MonoGo.Engine.Drawing.VertexBatch. For debugging, utilize built-in drawing tools likeLineShapeandCircleShape. - Culling & Layers: Use
Camera.RenderMaskfor bitwise culling of specific layers and scenes.
- Engine Serialization: Always refer to
MonoGo.Engine.Serializationwhen serializing/deserializing engine formats. - Polymorphism & Converters: This system handles polymorphic serialization using attributes like
[MonoGoConverter]. Do not use genericSystem.Text.Jsonsettings without integrating the engine's configurations. - JsonNodes: Use the
SerializeToNodemethod to simply and directly create aJsonNodefrom an object.
- Sprite System: The engine uses its own robust sprite system. Avoid using standard raw
Texture2Drendering for entities when sprites are more appropriate. - Frames & SpriteSheets: Use
MonoGo.Engine.Drawing.Spritewhich inherently supports animations by holding an array ofMonoGo.Engine.Drawing.Frameobjects. These map directly to Texture Atlases/SpriteSheets.
- Built-in System: Do NOT import heavy physics engines (like Farseer or Velcro) unless explicitly required. The engine features a fast, built-in lightweight collision detection system.
- Usage: Use
MonoGo.Engine.Collisions.CollisionChecker.CheckCollision(Collider a, Collider b)along with the engine's built-in colliders (e.g.,CircleCollider,RectangleCollider,LineCollider) and shapes for performant spatial checks.
- Default Audio: By default, use standard MonoGame
SoundEffectorSongclasses for game audio. - FMOD (Optional): The engine supports FMOD as an optional, standalone library via FmodForFoxes (https://github.com/Martenfur/FmodForFoxes/). Only use FMOD if the library is explicitly referenced in the project or requested by the user.
The engine can operate entirely on its own, but offers optional modules. BEFORE using any of these, always verify they are actually referenced in the project's .csproj:
- UI System (
MonoGo.Iguina): If included, the global UI system is accessible viaMonoGo.Iguina.GUIMgr.System. - Tile Maps (
MonoGo.Tiled): Used for parsing and rendering Tiled maps. - Particles (
MonoGo.MercuryParticleEngine): Provides advanced particle effect components (e.g.,ParticleEffectComponent).
- Colors: Use
MonoGo.Engine.ColorHelperandMonoGo.Engine.HSLColorfor conversions (Color, HSL, HEX). DO NOT useSystem.Drawing.Color. - Math & Geometry: Use
MonoGo.Engine.Utils.GameMathfor common calculations. CheckVector2Extensions,RectangleExtensions, andNumberExtensionsbefore writing custom math. Always useMonoGo.Engine.Anglefor angle representations to ensure correct 0..359 degree wrapping. UseMonoGo.Engine.Utils.SlowRotatorandMonoGo.Engine.Utils.AngleDamperfor smooth angle transitions and damping over time. - Collections: Use
MonoGo.Engine.Utils.CustomCollections.SafeList<T>when you need a list that allows safe modification during enumeration. UseMonoGo.Engine.Utils.CustomCollections.Pool<T>for object pooling (IPoolable) to prevent garbage collection spikes. - Animations: Use
MonoGo.Engine.Utils.AnimationandMonoGo.Engine.Utils.Easingfor generic value interpolations and tweening. - Input Management: Use
MonoGo.Engine.Inputto check Keyboard, Mouse, and GamePad states. - Time: Use
MonoGo.Engine.Utils.TimeKeeper.Globalfor tracking elapsed time (TimeKeeper.Global.TimeMultiplierfor slow-motion).
DO NOT invent implementation patterns. If you need examples of how to correctly implement engine features, ALWAYS read the respective files in the MonoGo.Samples/Demos/ directory first.
Important for NuGet Users: If the MonoGo.Samples/Demos/ directory is not available locally, you MUST use web-fetching tools to read the raw files directly from the repository:
https://raw.githubusercontent.com/MonoGo-Engine/MonoGo/refs/heads/master/MonoGo.Samples/Demos/[FileName]
Each demo showcases specific capabilities:
CollisionsDemo.cs: Lightweight Collision Detection (Colliders, spatial checks).CoroutinesDemo.cs: Coroutines, Jobs, and Alarms (async logic tied to game ticks).ECDemo.cs: Entity-Component (ECS) architecture usage and instantiation.InputDemo.cs: Keyboard, Mouse, and Gamepad input handling.ParticlesDemo.cs: Advanced particle effects (requiresMonoGo.MercuryParticleEngine).PrimitiveDemo.cs: Rendering raw geometric primitives and basic geometry.SceneSystemDemo.cs: Scene setup, layer management, andSceneMgrusage.ShapeDemo.cs: Utilizing built-in debug drawing tools (LineShape,CircleShape, etc.).SpriteDemo.cs: Sprite sheets,Frameusage, and animations.TiledDemo.cs: Parsing and rendering Tiled maps (requiresMonoGo.Tiled).UIDemo.cs: Comprehensive GUI system implementation (requiresMonoGo.Iguina).UtilsDemo.cs: UtilizingGameMath,TimeKeeper,ColorHelper, and general utilities.VertexBatchDemo.cs: High-performance customVertexBatchrendering (alternative to SpriteBatch).