Skip to content

Commit

Permalink
WIP docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Naamloos committed Nov 27, 2024
1 parent 2263471 commit 967eac6
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 140 deletions.
13 changes: 13 additions & 0 deletions docs/articles/drawing-your-first-sprite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Drawing Your First Sprite

## Preloading Your Sprite


## Retrieving Your Sprite


## Drawing Your Sprite


## Moving, Squishing, Spinning, Stretching

135 changes: 135 additions & 0 deletions docs/articles/getting-started-old.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Getting started

> [!WARNING]
> This documentation is currently out-of-date!
> This will be resolved ASAP. To some degree this might still work for you.
> Do make sure to take a look at the [Example Project](https://github.com/Naamloos/Axolotl2D/tree/master/Axolotl2D.Example)

To create a new Axolotl2D game, you'll want to reference the Axolotl2D library and create a new class inheriting the abstract `Game` class. This is very much prone to changes and may or may not be outdated at the time of reading! Once Axolotl2D is more ready for "general use", a proper documentation will be written.

```cs
using System.Numerics;
using Microsoft.Extensions.Logging;
using Axolotl2D.Drawable;
using Axolotl2D.Entities;
using Axolotl2D.Input;

public class MyGame : Game
{
// Our services
private Mouse? _mouse;
private ILogger<ExampleGame> _logger;

// Our resources / drawables
private Sprite? _sprite;

// You are required to pass the IServiceProvider service as a
// dependency to the base Game class.
// Other things like the Mouse, or the ILogger<MyGame> are free to
// inject as needed, if they're defined in your services.
// You are also able to set the max framerate and max update rate
// through the base constructor.
// These will later be changeable at runtime, but for the time being
// these can only be updated as your game gets constructed.
public ExampleGame(IServiceProvider services, Mouse mouse,
ILogger<MyGame> logger)
: base(services, maxDrawRate: 240, maxUpdateRate: 240)
{
// Set a title for the window
Title = "Axolotl2D Game";
// Set a clear color
ClearColor = Color.FromHTML("#0088FF");
// These can be changed at any time in your game loop.
// Axolotl2D uses events for it's game loop. You'll want to hook
// these manually as you see fit.
OnLoad += Load;
OnUpdate += Update;
OnDraw += Draw;
OnResize += Resize;

// Assigning properties from dependencies as needed.
this._logger = logger;
this._mouse = mouse;
}

// This is the place where you would pre-load all your assets.
public void Load()
{
// We can load sprites from embedded resources.
// You'll have to mark your texture as an Embedded Resource
_sprite = Sprite.FromManifestResource(this,
"MyAwesomeGame.Sprites.MySprite.png");
// Of course, it is also possible to load a Sprite from any other
// type of Stream.
// This is done with Sprites constructor:
// _sprite = new Sprite(this, imageStream);
_logger.LogInformation("Loaded Game Assets");
}

// This is our draw method. You'll want to draw your sprites here.
public void Draw(double frameDelta, double frameRate)
{
// This will draw your sprite at coordinates 50, 50
// with a size of 50x50
_sprite.Draw(50, 50, 50, 50);
}

// This is our update method. We can use this method to
// update values without interrupting our draw loop.
// For example, you'll want to manipulate your Sprite's
// position and size here.
public void Update(double frameDelta)
{

}

// This is the Resize method.
// It is called when the game window resizes.
public void Resize(Vector2D<int> size)
{
}

// When your game is closed,
// you'll want to clean up everything nicely.
// This can be done right here.
public override void Cleanup()
{
_logger.LogInformation("Cleaned up events and unloading game...");
// unhook events
OnLoad -= Load;
OnUpdate -= Update;
OnDraw -= Draw;
OnResize -= Resize;
}
}
```

Once you're done creating your Game class, you'll want to create a Host that houses your game and injects dependencies where you need them.
You'll want to do this in your Program.cs.

```cs
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Axolotl2D;

internal class Program
{
static void Main(string[] args)
{
var host = Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddGame<ExampleGame>();
services.UseMouse();
services.AddLogging();
})
.Build();

host.Start();
}
}
```
As of right now, the engine is very barebones. More to come in the near future!
141 changes: 13 additions & 128 deletions docs/articles/getting-started.md
Original file line number Diff line number Diff line change
@@ -1,135 +1,20 @@
# Getting started
# Getting Started with Axolotl2D

> [!WARNING]
> This documentation is currently out-of-date!
> This will be resolved ASAP. To some degree this might still work for you.
> Do make sure to take a look at the [Example Project](https://github.com/Naamloos/Axolotl2D/tree/master/Axolotl2D.Example)
*[Old article](./getting-started-old.md)*

To get started working with Axolotl2D, you will first need to set up your project. This guide will walk you through the necessary steps to configure your project, and run a simple example to ensure everything is working correctly. By the end of this guide, you should be ready to start developing your own projects.

To create a new Axolotl2D game, you'll want to reference the Axolotl2D library and create a new class inheriting the abstract `Game` class. This is very much prone to changes and may or may not be outdated at the time of reading! Once Axolotl2D is more ready for "general use", a proper documentation will be written.
## Creating a new project
// TODO

```cs
using System.Numerics;
using Microsoft.Extensions.Logging;
using Axolotl2D.Drawable;
using Axolotl2D.Entities;
using Axolotl2D.Input;
## Creating a GenericHost
// TODO

public class MyGame : Game
{
// Our services
private Mouse? _mouse;
private ILogger<ExampleGame> _logger;
## Creating your game skeleton
// TODO

// Our resources / drawables
private Sprite? _sprite;
## Registering your game and services into the host
// TODO

// You are required to pass the IServiceProvider service as a
// dependency to the base Game class.
// Other things like the Mouse, or the ILogger<MyGame> are free to
// inject as needed, if they're defined in your services.
// You are also able to set the max framerate and max update rate
// through the base constructor.
// These will later be changeable at runtime, but for the time being
// these can only be updated as your game gets constructed.
public ExampleGame(IServiceProvider services, Mouse mouse,
ILogger<MyGame> logger)
: base(services, maxDrawRate: 240, maxUpdateRate: 240)
{
// Set a title for the window
Title = "Axolotl2D Game";
// Set a clear color
ClearColor = Color.FromHTML("#0088FF");
// These can be changed at any time in your game loop.
// Axolotl2D uses events for it's game loop. You'll want to hook
// these manually as you see fit.
OnLoad += Load;
OnUpdate += Update;
OnDraw += Draw;
OnResize += Resize;

// Assigning properties from dependencies as needed.
this._logger = logger;
this._mouse = mouse;
}

// This is the place where you would pre-load all your assets.
public void Load()
{
// We can load sprites from embedded resources.
// You'll have to mark your texture as an Embedded Resource
_sprite = Sprite.FromManifestResource(this,
"MyAwesomeGame.Sprites.MySprite.png");
// Of course, it is also possible to load a Sprite from any other
// type of Stream.
// This is done with Sprites constructor:
// _sprite = new Sprite(this, imageStream);
_logger.LogInformation("Loaded Game Assets");
}

// This is our draw method. You'll want to draw your sprites here.
public void Draw(double frameDelta, double frameRate)
{
// This will draw your sprite at coordinates 50, 50
// with a size of 50x50
_sprite.Draw(50, 50, 50, 50);
}

// This is our update method. We can use this method to
// update values without interrupting our draw loop.
// For example, you'll want to manipulate your Sprite's
// position and size here.
public void Update(double frameDelta)
{

}

// This is the Resize method.
// It is called when the game window resizes.
public void Resize(Vector2D<int> size)
{
}

// When your game is closed,
// you'll want to clean up everything nicely.
// This can be done right here.
public override void Cleanup()
{
_logger.LogInformation("Cleaned up events and unloading game...");
// unhook events
OnLoad -= Load;
OnUpdate -= Update;
OnDraw -= Draw;
OnResize -= Resize;
}
}
```

Once you're done creating your Game class, you'll want to create a Host that houses your game and injects dependencies where you need them.
You'll want to do this in your Program.cs.

```cs
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Axolotl2D;

internal class Program
{
static void Main(string[] args)
{
var host = Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddGame<ExampleGame>();
services.UseMouse();
services.AddLogging();
})
.Build();

host.Start();
}
}
```
As of right now, the engine is very barebones. More to come in the near future!
## Initializing and running your game
// TODO
Empty file removed docs/articles/introduction.md
Empty file.
4 changes: 3 additions & 1 deletion docs/articles/toc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
- name: Getting Started
href: getting-started.md
href: getting-started.md
- name: Drawing Your First Sprite
href: drawing-your-first-sprite.md
3 changes: 2 additions & 1 deletion docs/docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}
],
"output": "_site",
"template": ["default", "modern", "memberpage", "templates/material"],
"template": ["default", "modern", "templates/material"],
"postProcessors": [
"ExtractSearchIndex"
],
Expand All @@ -35,6 +35,7 @@
"_appTitle": "Axolotl2D",
"_appLogoPath": "images/logo_small.png",
"_appFaviconPath": "images/favicon.ico",
"_appFooter": "© 2025 Ryan de Jonge (Naamloos)",
"_enableSearch": true,
"pdf": false
}
Expand Down
5 changes: 5 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ uid: index
title: Axolotl2D Documentation
---

> [!NOTE]
> Axolotl2D is curently in early development, thus this documentation WILL be out-of-date quickly!
> If you run into any issues during development, feel free to ask any questions on [Discord](https://discord.gg/hMRWUTa).
> Do make sure to take a look at the [Example Project](https://github.com/Naamloos/Axolotl2D/tree/master/Axolotl2D.Example) as well, as this example is more likely to be up-to-date with the rest of the project!
![medium sized logo](images/logo_mid.png)
# Axolotl2D
Axolotl2D is a small lightweight 2D game engine based on [Silk.NET](https://github.com/dotnet/Silk.NET).
Expand Down
Loading

0 comments on commit 967eac6

Please sign in to comment.