Skip to content

Commit cf4614d

Browse files
authored
Merge pull request #46 from bijington/feature/platformer
Create a Platformer sample
2 parents 913e024 + a9984dc commit cf4614d

File tree

106 files changed

+1792
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1792
-16
lines changed

engine/Orbit.Engine/GameObjectContainer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Reflection;
1+
using System.Diagnostics;
2+
using System.Reflection;
23

34
namespace Orbit.Engine;
45

@@ -12,7 +13,7 @@ public abstract class GameObjectContainer : IGameObjectContainer, IRender, IUpda
1213
/// <summary>
1314
/// Gets a snapshot of the game objects in the container.
1415
/// </summary>
15-
protected IList<IGameObject> GameObjectsSnapshot => gameObjects.ToList();
16+
public IReadOnlyList<IGameObject> GameObjectsSnapshot => gameObjects.ToList();
1617

1718
/// <inheritdoc />
1819
public void Add(GameObject gameObject)

engine/Orbit.Engine/Sprite.cs

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics;
12
using System.Linq;
23

34
namespace Orbit.Engine;
@@ -11,19 +12,25 @@ public class Sprite : GameObject
1112
private readonly double imageDisplayDuration;
1213
private int imageIndex;
1314
private double elapsedMilliseconds;
14-
private bool isRunning;
15+
16+
/// <summary>
17+
/// Gets whether the sprite is running.
18+
/// </summary>
19+
public bool IsRunning { get; private set; }
1520

1621
/// <summary>
1722
/// Creates a new instance of <see cref="Sprite"/> which accepts the names of images to load.
1823
/// </summary>
1924
/// <param name="imageNames">The names of the images to display, in order of sequence to be displayed.</param>
2025
/// <param name="imageDisplayDuration">How long each image should be displayed for before transitioning to the next image in the sequence.</param>
2126
/// <param name="autoStart">Whether the sprite animation should start automatically.</param>
22-
public Sprite(IReadOnlyList<string> imageNames, double imageDisplayDuration, bool autoStart = true)
27+
/// <param name="playMode">How the sprite will animate.</param>
28+
public Sprite(IReadOnlyList<string> imageNames, double imageDisplayDuration, bool autoStart = true, PlayModeType playMode = PlayModeType.Loop)
2329
{
2430
this.images = imageNames.Select(LoadImage).ToList();
2531
this.imageDisplayDuration = imageDisplayDuration;
26-
this.isRunning = autoStart;
32+
this.IsRunning = autoStart;
33+
this.PlayMode = playMode;
2734
}
2835

2936
/// <summary>
@@ -32,11 +39,13 @@ public Sprite(IReadOnlyList<string> imageNames, double imageDisplayDuration, boo
3239
/// <param name="images">The images to display, in order of sequence to be displayed.</param>
3340
/// <param name="imageDisplayDuration">How long each image should be displayed for before transitioning to the next image in the sequence.</param>
3441
/// <param name="autoStart">Whether the sprite animation should start automatically.</param>
35-
public Sprite(IReadOnlyList<Microsoft.Maui.Graphics.IImage> images, double imageDisplayDuration, bool autoStart = true)
42+
/// <param name="playMode">How the sprite will animate.</param>
43+
public Sprite(IReadOnlyList<Microsoft.Maui.Graphics.IImage> images, double imageDisplayDuration, bool autoStart = true, PlayModeType playMode = PlayModeType.Loop)
3644
{
3745
this.images = images;
3846
this.imageDisplayDuration = imageDisplayDuration;
39-
this.isRunning = autoStart;
47+
this.IsRunning = autoStart;
48+
this.PlayMode = playMode;
4049
}
4150

4251
/// <inheritdoc />
@@ -52,7 +61,7 @@ public override void Update(double millisecondsSinceLastUpdate)
5261
{
5362
base.Update(millisecondsSinceLastUpdate);
5463

55-
if (this.isRunning is false)
64+
if (this.IsRunning is false)
5665
{
5766
return;
5867
}
@@ -67,6 +76,16 @@ public override void Update(double millisecondsSinceLastUpdate)
6776
// - Loop
6877
// - Reverse
6978
imageIndex = Math.Clamp(imageIndex + 1, 0, images.Count);
79+
80+
if (imageIndex == images.Count)
81+
{
82+
imageIndex = 0;
83+
84+
if (PlayMode == PlayModeType.Single)
85+
{
86+
Stop();
87+
}
88+
}
7089
}
7190
}
7291

@@ -77,22 +96,48 @@ public void Stop()
7796
{
7897
elapsedMilliseconds = 0;
7998
imageIndex = 0;
80-
this.isRunning = false;
99+
this.IsRunning = false;
81100
}
82101

83102
/// <summary>
84103
/// Pauses the sprite animation.
85104
/// </summary>
86105
public void Pause()
87106
{
88-
this.isRunning = false;
107+
this.IsRunning = false;
89108
}
90109

91110
/// <summary>
92111
/// Starts the sprite animation.
93112
/// </summary>
94113
public void Start()
95114
{
96-
this.isRunning = true;
115+
this.IsRunning = true;
116+
}
117+
118+
/// <summary>
119+
/// Gets the <see cref="PlayMode"/> determining how the sprite will animate.
120+
/// </summary>
121+
public PlayModeType PlayMode { get; }
122+
123+
/// <summary>
124+
/// Gets the mode in which a sprite will animate.
125+
/// </summary>
126+
public enum PlayModeType
127+
{
128+
/// <summary>
129+
/// The sprite will animate through the full sequence once and then stop.
130+
/// </summary>
131+
Single,
132+
133+
/// <summary>
134+
/// The sprite will animate indefinitely.
135+
/// </summary>
136+
Loop,
137+
138+
/// <summary>
139+
/// The sprite will animate forwards and then backwards through the sequence.
140+
/// </summary>
141+
Reverse
97142
}
98143
}

games/AirHockey/AirHockey/AirHockey.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
<ItemGroup>
4949
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.0" />
50-
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.3" />
50+
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
5151
<PackageReference Include="Plugin.Maui.Audio" Version="3.0.0-preview2" />
5252
</ItemGroup>
5353
<ItemGroup>

games/BuildingGames/BuildingGames/BuildingGames.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
<ItemGroup>
6262
<PackageReference Include="SkiaSharp.Extended.UI.Maui" Version="2.0.0-preview.83" />
63-
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.3" />
63+
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
6464
</ItemGroup>
6565
<ItemGroup>
6666
<None Remove="Resources\Images\repository-qrcode.png" />

games/ChooseYourOwnAdventure/ChooseYourOwnAdventure/ChooseYourOwnAdventure.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<ItemGroup>
6464
<PackageReference Include="SkiaSharp.Extended.UI.Maui" Version="2.0.0-preview.83" />
6565
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.0" />
66-
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.3" />
66+
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
6767
<PackageReference Include="Plugin.Maui.Audio" Version="1.0.0" />
6868
</ItemGroup>
6969
<ItemGroup>

games/DrawingGame/DrawingGame/DrawingGame.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
<ItemGroup>
5656
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.0" />
57-
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.3" />
57+
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
5858
</ItemGroup>
5959
<ItemGroup>
6060
<MauiXaml Update="Pages\JoinGamePage.xaml">

games/Orbit/Orbit/Orbit.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@
6363
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
6464
<PrivateAssets>all</PrivateAssets>
6565
</PackageReference>
66-
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.3" />
66+
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
6767
</ItemGroup>
6868
</Project>

games/Platformer.sln

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31611.283
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orbit.Engine", "..\engine\Orbit.Engine\Orbit.Engine.csproj", "{A1865AEA-D891-46BE-BB87-665AB8907619}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orbit.Engine.Tests", "..\engine\Orbit.Engine.Tests\Orbit.Engine.Tests.csproj", "{622CFDD5-7E63-4EBC-A67F-8418CD1CE2DA}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Platformer", "Platformer\Platformer.csproj", "{3DE622E7-1CBE-4B83-B2D5-FD0AD23F1090}"
11+
EndProject
12+
Global
13+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14+
Debug|Any CPU = Debug|Any CPU
15+
Release|Any CPU = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{A1865AEA-D891-46BE-BB87-665AB8907619}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{A1865AEA-D891-46BE-BB87-665AB8907619}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{A1865AEA-D891-46BE-BB87-665AB8907619}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{A1865AEA-D891-46BE-BB87-665AB8907619}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{622CFDD5-7E63-4EBC-A67F-8418CD1CE2DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{622CFDD5-7E63-4EBC-A67F-8418CD1CE2DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{622CFDD5-7E63-4EBC-A67F-8418CD1CE2DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{622CFDD5-7E63-4EBC-A67F-8418CD1CE2DA}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{3DE622E7-1CBE-4B83-B2D5-FD0AD23F1090}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{3DE622E7-1CBE-4B83-B2D5-FD0AD23F1090}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{3DE622E7-1CBE-4B83-B2D5-FD0AD23F1090}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{3DE622E7-1CBE-4B83-B2D5-FD0AD23F1090}.Release|Any CPU.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572}
36+
EndGlobalSection
37+
EndGlobal

games/Platformer/App.xaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version = "1.0" encoding = "UTF-8" ?>
2+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:Platformer"
5+
x:Class="Platformer.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>

games/Platformer/App.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Platformer;
2+
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new AppShell();
10+
}
11+
}

0 commit comments

Comments
 (0)