Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion engine/Orbit.Engine/GameObjectContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public virtual void Render(ICanvas canvas, RectF dimensions)

foreach (var gameObject in currentObjects)
{
((IDrawable)gameObject).Draw(canvas, dimensions);
gameObject.Draw(canvas, dimensions);
}
}

Expand Down
2 changes: 1 addition & 1 deletion engine/Orbit.Engine/IGameObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Interface definition representing an object in a game.
/// </summary>
public interface IGameObject
public interface IGameObject : IDrawable
{
RectF Bounds { get; }

Expand Down
27 changes: 27 additions & 0 deletions games/Orbit/Orbit.Tests/Orbit.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<UseMaui>true</UseMaui>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="Microsoft.Maui.Graphics.Skia" Version="6.0.300" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Orbit\Orbit.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="Microsoft.Maui.Graphics.Skia" />
</ItemGroup>
</Project>
66 changes: 66 additions & 0 deletions games/Orbit/Orbit.Tests/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Runtime.CompilerServices;
using Microsoft.Maui.Graphics.Skia;
using NUnit.Framework;
using Orbit.Engine;
using Orbit.GameObjects;
using Orbit.Scenes;
using SkiaSharp;

namespace Orbit.Tests;

public class Tests
{
[Test]
public void SceneShouldRenderAsExpected()
{
VerifyScene(new Scenery(), 1000, 1000);
}

[Test]
public void HomeSceneShouldRenderAsExpected()
{
var home = new HomeScene(new Ship(null, new Gun()), new Sun(), new Planet(null, new GameObjects.Shadow()));
home.Update(0);
VerifyScene(home, 1000, 1000);
}

// TODO: For some reason the asteroid is not rendering.
[Test]
public void AsteroidShouldRenderAsExpected()
{
var asteroid = new Asteroid(null);

asteroid.SetMovement(new Movement(new PointF(0f, 0f), new PointF(0.5f, 0.5f), new PointF(0.01f, 0.01f)));

for (int i = 0; i < 10; i++)
{
VerifyScene(asteroid, 1000, 1000, $"AsteroidShouldRenderAsExpected{i}");

asteroid.Update(16);
}
}

public static void VerifyScene(IRender render, int sceneWidth, int sceneHeight, [CallerMemberName] string caller = "")
{
using var canvas = new SkiaCanvas();
using var bitmap = new SKBitmap(new SKImageInfo(sceneWidth, sceneHeight));
canvas.Canvas = new SKCanvas(bitmap);

render.Render(canvas, new Microsoft.Maui.Graphics.RectF(0, 0, sceneWidth, sceneHeight));

// TODO: apply test name to the file.
using var stream = File.Create($"{caller}.png");
bitmap.Encode(stream, SKEncodedImageFormat.Png, 100);
}

public class Scenery : GameScene
{
public override void Render(ICanvas canvas, RectF dimensions)
{
base.Render(canvas, dimensions);

canvas.FillColor = Colors.PaleGoldenrod;
canvas.FillRectangle(new Rect(0, 0, 100, 100));
}
}
}
6 changes: 6 additions & 0 deletions games/Orbit/Orbit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orbit.Engine.Tests", "..\..
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orbit", "Orbit\Orbit.csproj", "{3DE622E7-1CBE-4B83-B2D5-FD0AD23F1090}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orbit.Tests", "Orbit.Tests\Orbit.Tests.csproj", "{822D0B7B-A190-41EF-9F1F-F71BD8ABD896}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,6 +29,10 @@ Global
{3DE622E7-1CBE-4B83-B2D5-FD0AD23F1090}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3DE622E7-1CBE-4B83-B2D5-FD0AD23F1090}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3DE622E7-1CBE-4B83-B2D5-FD0AD23F1090}.Release|Any CPU.Build.0 = Release|Any CPU
{822D0B7B-A190-41EF-9F1F-F71BD8ABD896}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{822D0B7B-A190-41EF-9F1F-F71BD8ABD896}.Debug|Any CPU.Build.0 = Debug|Any CPU
{822D0B7B-A190-41EF-9F1F-F71BD8ABD896}.Release|Any CPU.ActiveCfg = Release|Any CPU
{822D0B7B-A190-41EF-9F1F-F71BD8ABD896}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
48 changes: 24 additions & 24 deletions games/Orbit/Orbit/GameObjects/Asteroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,29 @@ public override void Render(ICanvas canvas, RectF dimensions)
movement.DestinationY * dimensions.Height);
}

var collision = gameSceneManager.FindCollision(this);

if (collision is Planet planet)
{
planet.OnHit(25);
CurrentScene.Remove(this);
}

if (collision is Ship ship)
{
CurrentScene.Remove(this);

// TODO: Damage the ship;
}

// TODO: Allow collision with other asteroids.
if (collision is Asteroid otherAsteroid)
{
// TODO: Split in to smaller asteroids?
CurrentScene.Remove(otherAsteroid);
CurrentScene.Remove(this);
}

// TODO: remove when off screen.
//var collision = gameSceneManager.FindCollision(this);

//if (collision is Planet planet)
//{
// planet.OnHit(25);
// CurrentScene.Remove(this);
//}

//if (collision is Ship ship)
//{
// CurrentScene.Remove(this);

// // TODO: Damage the ship;
//}

//// TODO: Allow collision with other asteroids.
//if (collision is Asteroid otherAsteroid)
//{
// // TODO: Split in to smaller asteroids?
// CurrentScene.Remove(otherAsteroid);
// CurrentScene.Remove(this);
//}

//// TODO: remove when off screen.
}
}
2 changes: 1 addition & 1 deletion games/Orbit/Orbit/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public partial class MainPage : ContentPage
private readonly HomeScene homeScene;
private readonly MainScene mainScene;

public static bool ShowBounds { get; private set; } = false;
public static bool ShowBounds { get; private set; } = true;

public static TouchMode TouchMode { get; private set; }

Expand Down
5 changes: 3 additions & 2 deletions games/Orbit/Orbit/Orbit.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks>net6.0;net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> -->
<OutputType>Exe</OutputType>

<OutputType Condition="'$(TargetFramework)' != 'net6.0'">Exe</OutputType>
<RootNamespace>Orbit</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
Expand Down