Category: mobile

Amazing multi-platform Asteroids in C#

Amazing multi-platform Asteroids in C#

Android asteroidsAsteroids was the first full arcade game I ever wrote in C. Asteroids in C# takes things to a whole new level.  The solution contains 12 projects in all: Three Blazor projects, a WinForms version, a WPF version, a UWP (Universal Windows Platform) and a Xamarin Android Forms version (shown).

You can compile and run any of the projects though you will need to install and setup a suitable SDK and emulated (or a real device) for the Android.

Written by Howard Uman and ported by Ernie Salazar, this is a wireframe asteroids, more true to the original than my own raster version. Out of curiosity, I created an Android 9.0 emulator (I don’t have a recent Android phone) and compiled then deployed it to the emulator. The screenshot is grabbed directly from the emulator which has a less than ideal screen ratio. This would work better on a tablet.

The structure of the C# Solution is interesting. All of the game code is in the Base project. All of the other platforms just host the main game window. The game uses the SkiaSharp graphics framework for Android Forms.

This is a very nice open source project and an excellent way to see how Blazor works in both Wasm and Server mode, not to mention the Android, WinForms/WPF and UWP versions.

I have an interest in Blazor which lets you write C# code that runs in the browser very easily.  With a bit of workj, this should be runnable on a Linux webserver as well. Something for me to try…

 

 

The fun of game design

The fun of game design

Audience
Image by Pexels from Pixabay

My new side project is a free to play multi-player mobile game about living the life of a celebrity. It’s brutally competitive and will accommodate up to 10,000 players in one game. It scales horizontally so multiple games can be run at the same time. It’s an idea I’ve had for years and now I’m on it.

The idea is that you start moving to the big city. A city where your dreams can come true by becoming famous in some field. Whether breaking into film,  or sport, on TV, a famous writer and so on.  But first as a wannabe, you have to get a job, whether its pumping gas, waiting on or one of a dozen jobs.  And try to make your way up the greasy pole to the top of the A-List.

I have devised mechanisms for this. But there’s way more depth to the game than what I’ve said. The game is basically about decision making. Every action has consequences. If you go to this party, you might make friends with someone who can open doors that will give you more public exposure and earn celebrity points.

The game server generates events that you can attend. It’s a busy life attending openings, first nights, filming of videos, commercials, going to auditions, making guest appearances, signing books, partying, going to concerts, balls, awards ceremonies, opening fayres, launching ships, or more mundane things like product launches, endorsements, appearing in TV adverts and more.

All this has to take place in a game city. So the game server has to create a city populated with buildings, with jobs. Celebrities actually do jobs. Those books don’t write themself, or films make themself. Musicians have to record songs, go on tours. But you are also interacting with other players, helping them and helping yourself.

As a game designer and programmer I have to translate all this into code. In the past I programmed postal games. These were games where orders were sent by post, processed, results printed out and then mailed back. In this case, they’re entered on mobile and uploaded to a game server. Here a program will run at regular intervals and process a day’s activities. All those parties etc. have to be processed and the consequences determined. Did you make friends, did you get any new job offers? Have you accumulated some more celebrity points and moved up in the league table? Did you escape from being a wannabe to C-lister yet?

Then after that’s all done, the results and new decisions can be fetched onto mobiles and players decide what their next decisions will be…  That’s what I’m designing and programming. Both the game server engine and the mobile clients.

NoSQl or SQL?

NoSQl or SQL?

Da
Image by Gerd Altmann from Pixabay

I’m still continuing C# development but no longer on MonoGame. My needs have now switched to Flutter. If you haven’t come across it, it’s a cross-platform mobile development system from Google and uses their Dart language.  This is a modern language originally created back in 2011 as a potential replacement for JavaScript. That didn’t work out as other browser creators (Microsoft, Apple and Opera) didn’t go for it.

So Dart sort of languished until three years ago when Flutter emerged as an alternative to POA (Plain old Android development in Java/Kotlin). Flutter is the UI technology- interestingly it redraws the screen controls at 60 times per second, a bit like MonoGame. But this is no game.

The UI is programmed in Dart and it has one unique feature: You can make a change and see it live in one second. It’s called Hot Reload and compared to the old Compile, redeploy and run cycle is quite amazing., Also Flutter is cross-platform and has controls for iOS that look like Apple native controls.

Now my big decision is whether to use SQL or NoSQL to store data. The data isn’t exactly ordered like a schema, more like each database record has a variable number of name=value pairs. Which certainly suggests something NoSQLish.

 

An irritating bug with MonoGame/Android

An irritating bug with MonoGame/Android

Android Phone
Image by Iván Tamás from Pixabay

Bugs happen, it’s a way of life but when the bug affects you as a developer, it can be a tad annoying. I’ve found a bug and mentioned it in the MonoGame forums.

The bug occurs intermittently. I do a build then run the program on an Android phone. It starts loading, shows the splash screen then splat “The Content file was not found” message appears in Visual Studio.

This may be a bug in Xamarin or MonoGame. No doubt it will eventually get fixed but still a bit annoying. About the main workround I’ve found is rebuild everything. Start with the Pipeline tool- do a Build/Clean then a Build/Build. Then in the Project (in Visual Studio) do a Build/Clean then Build/Deploy which recompiles everything.

If the error still persists then it’s possible you have a typo; say a lowercase i instead of I in a filename. (I’ve done that once). Another fix though rather unsatisfactory is in the Project Properties, on the Options tab, right at the top is a checkbox Use Shared Runtime. If you untick that, deployment takes a bit longer. Instead of copying 3 MB which takes a second or so, it copies about 60 MB instead which takes a bit longer. I tried it but went back to the Clean and Deploy approach as copying was taking 10-15 seconds.

 

Trials and tribulations of mobile development

Trials and tribulations of mobile development

Mobile apps
Image by Gerd Altmann from Pixabay

Compared to desktop, I find mobile development somewhat frustrating at times. On iOS, you have a right palaver with certificates and provisioning profiles before you can even run a program on your device. Android is nowhere near so bad, but you have the fragmentation problem I mentioned yesterday. Too many different models with different screen sizes and resolutions.

C# is a nice and powerful language and well suite dto mobile, though to be fair so are Swift on iOS and Java/Kotlin on Android. Android software is a bit of a mishmash. You have to get the right SDKs to match your phone’s OS. Then you have to create a simulator if you are not testing on a device. iOS has its own issues, generally involving needing a Mac before you can put code on the iPhone.

MonoGame is a nice framework. Compared to both Android and iOS native development (no JavaScript here!) it’s a lot more straightforward to work with. You override the Game.Update method for reading keyboards and touchscreens. Then you override Game.Draw to output graphics. In that respect it’s even easier than using SDL for games. It’s a little like WinForm programming.