DEV Community

Ian
Ian

Posted on • Edited on

Building an Idle game Part 1 - Theory

I want to build a Idle RPG game, I'm pretty new to Node so it's going to be an adventure, a bit of trial an error, it should be fun :). This is a multi part series, in which by the end, you will be able to build your own game. I am taking inspiration from the likes of https://idlescape.com, https://melvoridle.com/, https://pendoria.net/.

Tick based systems are pretty interesting, I've never made one before, only theorized a few possibilities. After recently joining a project that uses a tick system, I decided to look into it more from scratch to get more of an understanding of it. What better use than building a real world example.

So where do you start with a tick system?

We need to start by describing what the system will do, we will be using Woodcutting as an example as it doesn't contain so much logic. It should be straightforward, you chop, you gain xp and gain logs. We will go over combat and other skills later.

Woodcutting

There are a few things that needs to happen for this skill - and for several others.

  • The timer for skill must be dynamic, so that we can change the time depending on the level of the skill or any buffs active

  • The skill can generate items and experience so it needs to update the user both locally in Node and in a database somewhere

  • It needs to be able to emit events to the client such as xp, progress bar movement, messages etc.

Queues

My first thought was thinking that it would be best to separate out each skill into a "job" and put it into a Queue. This would elevate much of the processing onto a separate server elsewhere. Initially it sounded great, but when it came to implementation it became quite convoluted, especially when it came to communicating from inside the job to the outside.

Latency also becomes a factor, as everything needs to happen fast so the next action can take place.

So I went with putting everything inside a setInterval() and left it at that. It reduces the complexity so much that avoiding queues for this is the best thing to do.

Conclusion

Sometimes the straightforward answer can be the right one.

So now we have an outline of what a skill will possess and a rough idea of how the tick system will work.

Part 2 will cover the actual code behind the tick system along with the Github repos which contains some other scaffold such as Vue frontend.

Top comments (0)