Hi Defold community!
I wanted to share with you a project that I started a year ago, making a persistent massively multiplayer online PC game with Defold on my spare time. While I’ve gone through a lot of things to build and problems to solve during last year, it’s still today in a draft-state but I enjoy working on it.
I appreciate the community, from users helping on the forum to those who share helpful libraries.
Enter the game!
I started by the implementation of a multiplayer layer script on top of the NoobHub opensource socket client, that would communicate with a Python server. I started with that little piece of code: asyncio TCP Echo server. The first step was to allow the game to connect to the server and exchange messages. Creating accounts and characters came later:
With Dirty Larry GUI library, creating basic UIs is a piece of cake!
I slightly modified the NoobHub library to make it work with batchs of JSON payloads. All of the player credentials are encrypted in SHA-1, thanks to an LUA implementation of the hashing algorithm.
Instances and chat
As the game was meant to be divided in multiple maps where players could meet, TCP sockets on the server are splitted in different “channels”, that belongs to a specific map instance.
To make the magic happen on client-side and making sure players were entering and leaving the right “channel” together, every Defold map collection is loading its own multiplayer layer script, with a bunch of specific properties.
Using Monarch as the screen manager was a no-brainer as it helped me organize all my maps collections in screens that embeds the whole multiplayer client instance the player is currently in.
Players are then able to chat on their local channel, and even manage their friend list! All of this is currently done by typing on the chat box, DefChat, which is also an external asset made by @Gmanicus! (hey buddy! )
As I started playing with Defold on a top-down game example, it just felt easier for me to build the game around it. Unfortunately, it’s very complicated to find top-down characters and monsters assets on the web. But I managed to find a nice soldier / zombies sprites pack and added them to the game.
Health bars on zombies are simple GUI boxes that follows the zombie game object, constantly updated with the right position. For those interested on how it works, I used @britzl’s example: Github - britzl/publicexamples/gui_follows_go
When some players enters a zombie collision area, those events are sent to the server that will decide regularly which target to attack, after some checks (is the player alive, still online?).
One of the most interesting things to create in a RPG is skills and spells. I’m looking forward to add more abilities to the characters.
As a backend developer myself, I like tweaking things and having a nice overview of what’s going on with my game. Every JSON action received by the server is triggering a push to an InfluxDB storage. All of this data can then be displayed and updated live on Grafana dashboards.
That way I can monitor how many players are connected and in which map, check the average latency/ping, and even see the current health points of all the monsters in the game!
There’s still a lot of work on the game to make it playable, from making it less a patchwork of different ambiances to a consistent theme, bestiary, characters, work on AIs…
But in the end, I learnt a lot, and still will.