James Crake-Merani

<- Return home

Coronavirus: The Game

By James Crake-Merani. Published on 16/01/2023


Context

Everytime I think back to 2020, I am reminded as to what an extraordinary year it was. I think when you are in the middle of something like that, you forget how unusual it is, and just begin to accept it as normal. Its only when you look back do you realise just how crazy the whole situation was. When we starting hearing about the COVID-19 outbreak (then often referred to as Coronavirus), we saw a lot of the shocking scenes from places that were hit hard in the early days of the pandemic like China, and Italy. But I think watching it all, it was hard to work out if the virus was actually going to come close to home. The thing is with a novel virus is that no one really knows whats going to happen. Some remarked that it was no different to the flu so why should we be worried about it?

I was, at the time, a GCSE student in year 11 -- the year of my exams. GCSEs are a lot of work in year 11; there is so much revision to do. I wasn't really keeping that much of a close eye on the news as a result of this but it was becoming impossible to ignore. The situation in the UK kept getting worse. Cases just kept increasing exponentially but the UK government seemed to be sticking to its policy of herd immunity. This was the idea that we couldn't stop people from getting the virus so we're not going to bother, and instead try to get many people infected so that the population would eventually build up an immunity to the virus. While schools were shutting down across the world, the UK started to become a bit of an outlier. I started to wonder if they would ever shutdown here, or if the government would try to keep them open. Eventually, I got ill, and had to self-isolate from school. I got better after a few days, and decided that I really need to get back to revising but a few days after, I start to think something major is going to happen, and maybe I should put my revision on hold for a few more days. It emerged that if the UK government persued its strategy of herd immunity, the NHS would be so overwhelmed with COVID cases that it wouldn't be able to function, not to mention the deaths that would be caused directly from people contracting COVID. Then, reports started to come in that the other nations of the UK were shutting down their schools. It was therefore obvious that England was about to do the same on that day. And they did. I remember watching the TV when Boris Johnson was making his announcement. But what came as a complete surprise to me was him also announcing the following:

"Of course, this does mean that exams will not take place as planned in May, and June but of course we will make sure that pupils get the qualifications that they need, and deserve for their academic career."

Not only was I now not going to school, I also had no exams to revise for. This was March, and I had no more school until September when I would join sixth form. I was completely free.

I never like to leave myself with nothing to do, so I immediately started to think about what project I could start working on. In discussion with a friend, I decided to make a game about the ongoing situation. And like most projects, it took way longer than I thought it would.

Coming up with the idea

Throughout the pandemic, there were many instances of panic buying, normally initiated by erroneous thinking. At the very beginning of the pandemic, some people feared that shops were going to shutdown (which the government made clear was never going to happen) so people started to stockpile. One item in particular seemed to be the one of the biggest victims of the stockpiling: toliet paper. I've heard this might've been because some people thought diarrhea was a common symptom of COVID-19, and wanted to be prepared. Often panic buying had a sort of domino effect, where store shelves start to become emptier so people feel the need to panic buy before the shops ran out.

I decided my game was going to take place in a supermarket, and the player had to buy as much toilet paper as they could before time runs out. They would compete with AI players, and at the end of the game their score would be compared against their AI opponents. I had some other ambitions for the game that I was never able to realise because the game took far longer to develop than I anticipated. When I felt like I got the game to be playable enough, I had basically had enough, and decided to move on. Particularly, I wanted the game to have combat between different opponents as you would try to knock them off course. This never got done, and the movement in the game is fairly simplistic as well -- more simplistic than I would've wanted.

Implementation

The game is written in C#, and uses the MonoGame framework for the graphics. C# was my favourite language at the time. I had to re-familiarise myself with the language for my Computer Science A-Level earlier last year, and looking back on it I actually realised that its a fairly decent language. I wouldn't choose to use it these days though mainly due to the fact that its a language owned, and maintained by Microsoft. I liked to use MonoGame at the time because it was much more lightweight compared to a game engine like Unity. Looking back though, I think using MonoGame held me back a bit because I had to consider some basic concepts that could've been handled by a game engine. While I'm not sure I would use Unity for such a project, if I were to write a game in C# again, I think I would probably wind up using the Godot engine instead. Plus, its free & open source which Unity definitely isn't.

The user roates using the left, and right arrow key, and moves forward by holding the up arrow key. In the supermarket, there are several shelves with a certain amount of toilet paper on them. The user can pick up one roll of toilet paper by pressing the x button. However, when the player collects toilet paper, this is not immediately added to their score. Rather, they have to go to the checkout before the toilet paper they have collected is added to the score, and the user can only carry a certain amount of toilet paper in their cart at the same time.

Once a shelf is emptied of its toilet paper, it needs to be restocked. There were several restocker agents who would go to a shelf, restock it, and then move outside of the visible game area to get more stock before repeating the process. They kept doing this until there were no more shelves to restock. But I found that shelves were being restocked too quickly so I decided to make it so restocking is done in cycles instead. At the beginning of every cycle, the game would work out which shelves needed restocking, and then this would be carried out by the individual agents. But what if a shelf which, at the beginning of the cycle was full, becomes empty? Well this shelf would not be attended to until the next cycle, and there is a defined time period in each level between each cycle. This was to prevent shelves from being immediately restocked as soon as they were emptied.

The AI opponents in the game are extremely simplistic. They just look for the nearest shelf which has toilet paper on it, and make a beeline to that shelf, collecting as many as they can before progressing to either another non-empty shelf, or the checkout.

One of the problems I encountered while making the game was getting the Maths to work. I've always been fairly weak at Maths, and turns out its quite important when making a 2D, and also a 3D game. One of the problems I had was getting the AI to go to the right shelf. The way I had the AI coded is that it would rotate to the direction where the shelf is, and then keep moving forward until it is near the shelf. The problem here was if the shelf is far away, the floating point calculation made to get the angle was not accurate enough, and sometimes the AI would not be able to get near to the shelf, and would just keep moving forward forever. The way I fixed this was to instead make the AI check every frame to see if they are still facing the shelf at the right angle before moving forward. I think from memory though that this didn't always fix the problem, and some of the opponent AIs would just leave the game area, and never come back.

Looking back at the code

Being that I wrote this game over 2 years ago, when I went to look back at the code I was expected to be horrified at the way I used to program. This actually ended up not being the case. Although there are definitely things in the code that I would not do today (whats with all the type casting?), the code is fairly decent I thought.

In terms of functionality, there are some glaring omissions mainly because I'd grown fed up of working on the project after working on it for so long. One of the big ones is that there's no ability to load different levels; they're just simply defined in the entry method, and passed onto the constructor for the GuiGame class. Another one is that there's no way to play multiplayer with someone using another controller. This I think would've actually been fairly easy to implement I suspect.

Running it on your machine

I have provided the source code in a tarball however both .NET, and MonoGame seemed to have changed a fair bit since I wrote the game. .NET Core is now on its 7th version whereas this game was written for .NET Core 2. Additionally, MonoGame used to have a program which you would need in order to build the content for it but according to their website it all works through NuGet. Please also recall what I said earlier: there are some basic functionalities missing you might need to change in code if you want to run the game at a certain resolution for example.


<- Return home