Run Taotie Run – new Here Be Monsteres mini-game made with Dart and StageXL

Using StageXL and Dart, I built another mini-game themed around our MMORPG Here Be Monsters this week. The game follows a pack of Taotie monsters, which is a type of spirit monster created when a ghost with immense hunger possesses a Chinese pot. Taotie originates from Chinese folklores and is one of many monsters that you encounter in the world of Here Be Monsters as seen in the in-game almanac page on Taotie:

Taotie's almanac page 


Run Taotie Run

As the player, you assume the role of the leader of this pack of travelling Taotie who are looking for anything and everything to eat (I’m not making these up, according to the folklores they eat just about anything!) when they ran into a Starium shower (i.e. asteroids falling from the sky).


Being pots, you will crack and die if you get hit by an asteroid, hence the premise of the game is for you to lead your Taotie minions and navigate through the asteroids and survive for as long as you can.

To make things slightly more interesting and to encourage player to take more calculated risk, how fast you accumulate points towards your score is based on how you play. If you choose to hide around the edges you might have a better chance of surviving longer but your score also increase at a much slower rate compared to if you were to spend more time around the centre of the screen where your reaction time will be more thoroughly tested by the incoming asteroids:


Whilst self-preservation is of the highest priority (you get hit directly and it’s game over..), to discourage you from using your minions as mere cannon fodders the rate you accumulate score is also directly proportional to the number of minions you have. So keep your minions alive and you’ll pick up points a lot faster as a reward!

What’s more, there will occasionally be Cherries appearing on the screen for a brief moments, and collecting them before they disappear will yield a handsome 10000 bonus points towards your score!

Screenshot Screenshot




To create the desired effect of the minions following your every move but always being several steps behind, I used the Zip function from the Rx’s set of APIs which I had begun porting over to Dart with a small project called stream_ext which is available on here.

It’s also worth mentioning that the Rx’s APIs had been studied and taken into account in the design of Dart’s Stream type which already contains the most commonly used Rx APIs such as fold, map and where, so my porting effort is strictly limited to those more ‘exotic’ functions such as zip, merge, combineLatest and delay just to name a few.

Using zip, it made it very easy to create a stream of mouse move events which is some steps behind the source (the mouse move events emitted whenever you move the mouse), see the highlighted lines 137-138 below:



Please give the game a go and let me know what you think and any suggestions you have on how to make it more fun!



Play the Game

Source Code


stream_ext – bringing more Rx API to the Dart

Over the last week or so, I’ve been looking at and playing around with the Streams API in Dart, which has been (in part at least) based on the Rx API, and it’s easy to see the parallels between the two sets of APIs and you can find most of the core Rx APIs on Dart’s Stream type already, but there were a few notable absentees which I have often found useful, such as merge, zip, delay and window.

With these absentees in mind I started a small Dart project called stream_ext (for stream extensions) to port them over, and here are some details of the first couple of functions I have done along with some live demo examples.



The merge function merges two streams into a single unified output stream.


You can try a live demo use of the merge function here, with the source code here.



The combineLatest function merges two streams into one by using the supplied selector function whenever one of the streams produces an event.


You can try a live demo use of the combineLatest function here, with the source code here.



The delay function creates a new stream whose events are directly sourced from the input stream but each delivered after the specified duration.


You can try a live demo (a port of the ‘Time flies like an array’ example) use of the delay function here, with the source code here.



The throttle function creates a new stream based on events produced by the specified input, upon forwarding an event from the input stream it’ll ignore any subsequent events produced by the input stream until the flow of new events has paused for the specified duration, after which the last event produced by the input stream is then delivered.


You can try a live demo use of the throttle function here, with the source code here.



The zip function combines two streams into one by combining their elements in a pairwise fashion, combining the latest value on each stream and producing a new event using the supplied zipper function.


You can try a live demo use of the zip function here, with the source code here.


It’s still early days and there are quite a few more useful Rx function I think will be useful to people working with Dart, and I hope you find these extension functions useful and please don’t hesitate to get in touch and leave some feedbacks on the project!

Dart – implementing the Singleton pattern with factory constructors

In Dart there is an interesting language feature called ‘Factory Constructors’, which effectively allows you to override the default behaviour when using the new keyword – instead of always creating a new instance the factory constructor is merely required to return an instance of the class, the difference is important.

Factory constructors allow you to implement a number of techniques and patterns without altering code that consumes your class. For instance,

  • Singleton pattern which we will look at more closely.
  • Object pooling, a useful technique for reducing the amount of allocations (and its associated allocation cost and consequent GC pressure) in performance critical applications.
  • Flyweight pattern which is already discussed in more detail in this Idiomatic Dart article.

These are just 3 use cases that I can think of off the top of my head, please feel free to suggest any more that I have missed.

Problems with common Singleton pattern implementations

In other languages (well, the ones that I’m familiar with anyway!), in order to implement the Singleton pattern you have to ensure that the class’s constructor is not exposed publicly and that access to the singleton instance is done via a static Singleton property. Revered C#/Java developer Jon Skeet has a very good article on the various solutions one might adopt to implement the singleton pattern in C#.


These implementations require code that consumes your class to be aware of its implementation of the singleton pattern and create a vast blast radius throughout your application should you one day decide that the singleton pattern is no longer necessary/applicable.

For instance, if assumptions in your application change drastically (and they often do..) and you need to switch to the flyweight or another pattern instead to cater for changing requirements and/or assumptions.

Unintentional tight coupling

In the case of C# (where static members are not allowed on interfaces and abstract classes are un-constructible) the standard singleton pattern also create tight coupling to a concrete implementation where it’s seldom necessary.

You can, to some degree, work around this issue of tight coupling by introducing an IOC container as middle man between your class and its consumers, most IOC containers provide some mechanism for controlling object lifespans (transient, singleton, pooled, etc.). However, you now have tight coupling to the IOC container instead…

Singleton pattern with Factory constructors

You can implement the singleton pattern using factory constructors like this:

the key thing here is that any consuming code is completely oblivious to the fact that we have just implemented the singleton pattern. If we were to continue our mind later or forced to adopt a different pattern because of changing requirement, there will be trivial or no change on all the consuming code!


Idiomatic Dart – Factory constructors

Jon Skeet – Implementing the Singleton pattern in C#

Whack A Meng – new Here Be Monsters mini-game made with Dart and StageXL

Hot on the heels of making my first game with Dart and StageXL at the London GameCraft 2013, I decided to strike whilst the iron’s hot and make a mini-game featuring characters from our MMORPG Here Be Monsters.


The result, is a whack-a-mole style game where the antagonist is ‘Meng the Terrible’ from the on-going Nanjing storyline in the world of Here Be Monsters.

Your task is simple, just whack him whenever you see him poke his head out of the rabbit holes!

image image


To progress through the levels, you need to whack Meng enough times before the time runs out, and in later levels NPCs (other monsters from the world of Here Be Monsters) will pass by the rabbit holes. If you intentionally or accidentally end up whacking the NPCs they’ll no only show you their displeasure but also deduct your current score!

Screenshot1 Screenshot5


To show their support for your quest to vanquish the evil doers in their world, the NPCs will give you some words of encouragement at the end of each level depending on if you were able to accomplish your target.



Whilst by far not my strong suit, I have thoroughly enjoyed the asset production aspect of making this game. Whilst I’m still very much a beginner and learning plenty about Dart and StageXL, I have been pretty impressed by how productive they allow me to be in putting this game together so quickly on my own.



Play the Game

Source Code

London GameCraft 2013 – Agents of P.R.I.S.M

After an 11-hour marathon session at the London GameCraft event yesterday, I am very proud to say that my team’s entry – Agents of P.R.I.S.M was awarded with the MOST INTERESTING INTERPRETATION OF THE THEME award for the theme of the day – Impact of P.R.I.S.M.

It was a great day out for the guys and gals from GameSys which also saw our other team’s entry – After Him – winning the BEST TEAM EFFORT award too for best arts.

I’d like to take this opportunity to say thanks to everyone for organizing such a wonderful event, we had a great time and I saw many interesting games developed by a wide variety of different technologies and frameworks. Personally I used this opportunity to experiment with Dart and StageXL and I’m pleased with what I was able build with them in less than 11 hours.

You can play the game here, and if you’re interested in checking out the source code (admittedly of poor organization due to time constraint!) feel free to check out the github repository.

Agents of P.R.I.S.M

image image

To directly answer the question of ‘what’s the impact of PRISM’, it’s the creation of a surveillance capability that whilst can serve to help prevent crime and terrorist attacks, is also subject to misuse and abuse.

If underused and unable to stop the sort of disaster it is intended to prevent, it’ll no doubt come under much public criticism. On the other hand, if it’s misused or overused and cause too much intrusion to everyday lives of innocent people then it’ll also cause public unrest. It is therefore a fine balance between not doing enough and doing too much, and it is this need for balance that we wanted to focus on with Agents of P.R.I.S.M.


Mission Brief

As an agent with access to P.R.I.S.M, your task is to identify a criminal out of a set of potential targets, and you have a set of surveillance options that can be used against each of these targets, in the order of each option’s cost and level of effectiveness and intrusiveness:

1. CCTV surveillance (least expensive, effective and intrusive)

2. Credit card surveillance

3. Email surveillance

4. Phone surveillance

5. Send agents on the field to conduct in-person surveillance (most expensive, effective and intrusive, this is truly a high risk, high reward approach)

You need to balance against:

  • Time – if you don’t identify the criminal before time runs out then he gets away and you failed your task, so move fast!
  • Intrusion level – if you’re too aggressive with your use of surveillance options then it’ll make the citizens unhappy, when they become angry with how much you’re intruding on their lives it leads to civil unrest and you lose.
  • Budget – government agencies have to operate within its budget, so do you, spend carelessly on expensive surveillance options will drain your budget and when you run out of budget you can no longer catch the criminal and you lose.

As you progress through the levels, the amount of budget and time you have and number of potential suspects will change and make the game more and more challenging.


Game Play


Clicking on each target allows you to start or stop the different types of surveillance on him/her.

As you continue to apply surveillance on each of your targets their level of happiness will decrease (even the criminal has the right to be unhappy about being watched you know!), as does the overall civilian happiness.

As surveillance reveals more information about each of your targets your level of suspicion against them will also grow. However, for the innocent civilians you’ll soon realize that they’re clean. For these civilians, continued surveillance on them will no longer raise your suspicion level but would continue to cause them upset so it’s best for you to stop any surveillance on targets as soon as the suspicion level stops growing.

The more intrusive form of surveillance option you use the faster the target’s happiness decreases, and the faster your suspicion level will grow since the surveillance will reveal more information about your target, it also decreases your budget faster too as you fork out to likes of Google, Microsoft and telephone companies in order to acquire communication records..


I hope after reading you find the idea of the game interesting and would like to give it a try. I appreciate that the game doesn’t feel as fun as it could be in its current form, it needs much more work balancing the various constraints the player has to work with, for example, more time and less budget can encourage a more considered and careful approach to playing.

The UI can also be improved to offer the player more useful guidance and a tutorial wouldn’t go amiss too.

That said, please bare in mind that the entire game was written by one person in less than 11 hours using an unfamiliar language and framework. If time permits and there are interest out there, I’m more than happy to put in a few more hours and give the game a much needed final polish.



Play the Game

Source Code