Awesome Open Source
Awesome Open Source

Asteroids in .NET Framework, .NET 5, and Blazor WebAssembly

Live Demo: https://aesalazar.github.io/AsteroidsWasm/

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:

https://www.codeproject.com/articles/7428/c-asteroids

Which now resides here:

https://awesomeopensource.com/project/unhuman/csharp-asteroids

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 and .NET 5.

  • Asteroids.Wpf - Equivalent WPF GUI to the WinForms applications that uses a WPF WriteableBitmap as the main renderer with help from the WritableBitmapEx library. This is using the .NET Framework 4.8 and .NET 5.

  • 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 - WebAssembly project that uses Microsoft's Blazor Client to allow cross-compiling the C# code to WASM so it can be rendered in a browser (see below for more info).

  • Asteroids.Blazor.Server - Similar to the Wasm project but instead uses Microsoft's Blazor Server to execute the application server-side (see below for more info).

  • Asteroids.Blazor.Electron - Similar to the above Blazor Server project but running inside Electron to execute the code as a Desktop application.

  • Asteroids.BlazorComponents - Blazor Class Library that contains the actual game engine instantiated object and associated HTML and JavaScript bridge to allow rendering in the browser.

General Notes

All applications are written in Visual Studio and 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 .NET 5 and Wpf .NET 5 projects require Visual Studio 2019 or the latest Visual Studio Code to edit and compile; otherwise it can be done via Command Line.

Performance varies among the technologies with WinForms in .NET 5 being the clear winner for desktop and Firefox for Blazor/Web. Wpf in .NET 5 is a close second for desktop, however, the UWP app is also quite fast and has better sound support in that more then one can play at a time, out of the box.

.NET 5 Notes

All .NET 5 applications including Blazor are tested on version 5.0.103 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 dotnet --version

To run all projects in this solution requires the installation of Visual Studio 16.8 minimum or the latest Visual Studio Code.

Xamarin Notes

The Android application will need some additional configuration like any other Xamarin project, e.g. I test in an Android 9.0 (Pie) 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 5 and Standard versions.

Blazor Notes

Microsoft has made Blazor officially part of .NET Core. It was first included in 3.0 Preview 4. Prior to that it was a separate library/install.

The difference between the Wasm and Server projects is the hosting model. With Blazor, you have the option to either fully host the code and application Client-Side via WebAssembly or Server-Side with updates pushed to the Client via SignalR. In a production application, the choice would be highly dependent on the situation and more information can be found on Microsoft's Hosting Models Page.

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.

Building from CLI in the Asteroids.Blazor.Wasm 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:

dotnet run

The app can be published with:

dotnet publish -c Release

Blazor Electron Notes

The Blazor Electron project is probably the most experimental of all in this repo. It uses the Electron.NET wrapper in conjunction with a Blazor Server app to show a the game in a Desktop application.

It requires the global installation of the ElectronNet.CLI before it can be ran:

dotnet tool install ElectronNET.CLI -g

Once done, it can be ran like any other project from within Visual Studio.

NOTE: Electron.NET requires node.js and npm so make sure to have them installed. If you do not just grab the latest LTS:

https://nodejs.org/en/


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Html (432,534
C Sharp (277,407
Android (41,742
Dotnet (8,112
Electron (6,065
Dotnet Core (4,374
Webassembly (2,302
Wpf (2,074
Xamarin (1,778
Wasm (1,760
Winforms (1,005
Uwp (1,001
Blazor (979
Dotnet Standard (789
Blazor Webassembly (256
Blazor Server (183
Asteroids (120
Blazor Client (88
Xamarin Library (59
Electron Net (4
Related Projects