Skip to content

Commit

Permalink
Use logo in example instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Naamloos committed Nov 28, 2024
1 parent d6846f5 commit 6b24851
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 30 deletions.
8 changes: 4 additions & 4 deletions Axolotl2D.Example/Axolotl2D.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
</PropertyGroup>

<ItemGroup>
<None Remove="Resources\Fonts\ComicMono.ttf" />
<None Remove="Resources\Music\SpaceJazz.wav" />
<None Remove="Resources\Sprites\mochicat.png" />
<None Remove="Resources\Sprites\rei.png" />
<None Remove="Resources\Sprites\logo.png" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\Fonts\ComicMono.ttf" />
<EmbeddedResource Include="Resources\Music\SpaceJazz.wav" />
<EmbeddedResource Include="Resources\Sprites\mochicat.png" />
<EmbeddedResource Include="Resources\Sprites\rei.png" />
<EmbeddedResource Include="Resources\Sprites\logo.png" />
</ItemGroup>

<ItemGroup>
Expand Down
11 changes: 9 additions & 2 deletions Axolotl2D.Example/ExampleGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Axolotl2D.Cef;
using Axolotl2D.Drawable;
using Microsoft.Extensions.Logging;
using System.Numerics;
using System.Reflection;

namespace Axolotl2D.Example
Expand All @@ -22,18 +23,24 @@ public ExampleGame(IServiceProvider services, ILogger<ExampleGame> logger, Sprit
// It is recommended to hook OnLoad to load assets
OnLoad += Load;

OnDraw += Draw;

this._logger = logger;
this._assetManager = assetManager;
this._cefBrowserManager = cefBrowserManager;

_song = audioPlayer.LoadSong(Assembly.GetEntryAssembly()!.GetManifestResourceStream("Axolotl2D.Example.Resources.Music.SpaceJazz.wav")!);
}

private void Draw(double frameDelta, double frameRate)
{

}

public void Load()
{
// preload assets
_assetManager.LoadSprite("mochicat", Assembly.GetEntryAssembly()!.GetManifestResourceStream("Axolotl2D.Example.Resources.Sprites.mochicat.png")!);
_assetManager.LoadSprite("rei", Assembly.GetEntryAssembly()!.GetManifestResourceStream("Axolotl2D.Example.Resources.Sprites.rei.png")!);
_assetManager.LoadSprite("logo", Assembly.GetEntryAssembly()!.GetManifestResourceStream("Axolotl2D.Example.Resources.Sprites.logo.png")!);

_cefBrowserManager.RegisterBrowser("github", "https://naamloos.github.io/Axolotl2D.Webtest/");
_cefBrowserManager.RegisterBrowser("google", "https://google.com");
Expand Down
Binary file added Axolotl2D.Example/Resources/Fonts/ComicMono.ttf
Binary file not shown.
Binary file added Axolotl2D.Example/Resources/Sprites/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Axolotl2D.Example/Resources/Sprites/mochicat.png
Binary file not shown.
Binary file removed Axolotl2D.Example/Resources/Sprites/rei.png
Binary file not shown.
36 changes: 12 additions & 24 deletions Axolotl2D.Example/Scenes/ExampleScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ namespace Axolotl2D.Example.Scenes
[DefaultScene]
public class ExampleScene : BaseScene
{
private const int QUAD_COUNT = 9;
private const int QUAD_COUNT = 4;
private const int MOVE_SPEED = 5;

private float _currentXPos = 0;
private bool _goesRight = true;
private float _currentRotation = 0;

private BaseDrawable? _object1;
private BaseDrawable? _object2;
private BaseDrawable? _object3;
private BaseDrawable? _logo;

private IMouse? _mouse;
private IKeyboard? _keyboard;
Expand All @@ -42,22 +40,14 @@ public override void Draw(double frameDelta, double frameRate)
{
for (int i = 0; i < QUAD_COUNT; i++)
{
BaseDrawable? thisSprite;
if (i % 3 == 0)
{
thisSprite = _object1;
}
else if (i % 3 == 1)
{
thisSprite = _object2;
}
else
{
thisSprite = _object3;
}
thisSprite!.Rotation = _currentRotation;
thisSprite!.Draw(new Vector2(_currentXPos, i * 74), new Vector2(50, 50));
_logo!.Rotation = _currentRotation;
_logo!.Draw(new Vector2(_currentXPos, i * 150), new Vector2(160, 100));
}

// Squish the width and height at random speeds
float squishWidth = 160 + (float)(Math.Sin(_currentRotation * 2) * 80);
float squishHeight = 100 + (float)(Math.Cos(_currentRotation * 3) * 50);
_logo!.Draw(new Vector2(300, 300), new Vector2(squishWidth, squishHeight));
}

public override void Load()
Expand All @@ -68,9 +58,7 @@ public override void Load()

// It is not recommended to load Sprites any time a scene is initialized, as it can cause memory leaks.
// At this moment it is not possible to do this any other way. This will be fixed in the future.
this._assetManager.TryGetSprite("mochicat", out _object1);
this._assetManager.TryGetSprite("rei", out _object2);
_object3 = new SimpleQuad(_game, new Vector2(0, 0), new Vector2(50, 50));
this._assetManager.TryGetSprite("logo", out _logo);

_mouse = _game.GetMouse();
_keyboard = _game.GetKeyboard();
Expand All @@ -92,7 +80,7 @@ public override void Unload()

public override void Update(double frameDelta)
{
float maxX = _game.Viewport.X - 50;
float maxX = _game.Viewport.X - 160;
float deltaPosition = MOVE_SPEED * ((float)frameDelta * 60);
_currentXPos += _goesRight ? deltaPosition : -deltaPosition;

Expand All @@ -108,7 +96,7 @@ public override void Update(double frameDelta)
}

if (_keyboard!.IsKeyPressed(Key.Space))
_game.ClearColor = Color.Red;
_game.ClearColor = Color.FromHTML("#00BBFF");
else
_game.ClearColor = Color.FromHTML("#0088FF");

Expand Down

0 comments on commit 6b24851

Please sign in to comment.