Asteroids in .NET Framework, .NET Core 3, and Blazor WebAssembly
This project is a POC to determine the plausibility of writing a .NET Standard library and using it across devices INCLUDING WebAssembly (WASM). The root library, Asteroids.Standard, encapsulates all logic for rendering the classic '80s video game. None of this is meant to be production-worthy. It is more me just messing around trying to see what works.
The original code was adopted from a very cool WinForms project on CodePlex by Howard Uman, circa 2004:
It was chosen because it was already in C# and very straight forward in terms of inheritance and logic. Separating the logic from the UI layer was relatively simple.
Currently, the project is made of the following:
Asteroids.Standard - .Net Standard Library containing the game engine.
Asteroids.WinForms - Reconstructed WinForms GUI that uses the game engine with a PictureBox as the main renderer. This is using the .NET Framework 4.8.
Asteroids.WinForms.Core - Identical in code to the Asteroids.WinForms project but using .NET Core 3 (see below for more info).
Asteroids.Wpf.Core - Identical in code to the Asteroids.Wpf project but using .NET Core 3 (see below for more info).
Asteroids.Xamarin - The core Xamarin application that uses SkiaSharp for 2D rendering via a SKCanvasView.
Asteroids.Xamarin.Android - Android GUI that uses the core Xamarin library.
Asteroid.Xamarin.UWP - UWP GUI that uses the core Xamarin library.
Asteroids.Blazor - WASM project that uses Microsoft's Blazor to allow cross-compiling the C# code to WASM so it can be rendered in a browser (see below for more info).
All applications are written in Visual Studio so they can be launch simply by doing
Debug -> Start New Instance. All are fully functional in terms of sound and keyboard support.
Note that the Blazor, WinForms and Wpf Core projects require Visual Studio 2019 or the latest Visual Studio Code to edit and compile; otherwise it can be done via Command Line. As of the time of this writing, Visual Studio 2019 (16.3) still does not support WinForms Core in its Designer Editor but does allow the files to be edited in code.
Performance varies among the technologies with WinForms Core being the clear winner for desktop and Firefox for Blazor/Web. Wpf Core is a close second for desktop.
.NET Core Notes
The three .NET Core 3 applications are updated to use the official release of the SDK so remember to have it installed. You can check what versions are installed (you can have multiple) by entering in a command prompt:
dotnet --info or
Core 3 GA will require Visual Studio 19.3 as the minimum version. Blazor is still in preview.
The Android application will need some additional configuration like any other Xamarin project, e.g. I test in an Oreo VM running on my dev machine.
There is no Xamarin iOS app at this point only because Apple does not allow development on non-macs (which is what I am on) without connected hardware. But there is no technical reason for it not to be possible.
The UWP application is set to require the Windows 10 Fall Creators Update at a minimum. This is necessary to run the latest .NET Core and Standard versions.
Microsoft has made Blazor officially part of .NET Core 3. It was first included in Preview 4. Prior to that it was a separate library/install.
Note that while .NET Core 3 is official, Blazor is still in preview. Microsoft is targeting a release window of May 2020 for a final first version.
To build the app, simply do it from Visual Studio - just make sure you have all dependencies listed on their Getting Stated page at Blazor. Besides the .NET Core install there is an extension specific to Blazor that is needed.
Building from CLI in the Asteroids.Blazor project folder is also an option:
dotnet build -c Release
To run the application, simply hit F5 or ctrl+F5 in Visual Studio or from the CLI: