r/javascript • • 5d ago

AskJS [AskJS] Good resources for using JS/TS for simple real-time multiplayer games/interfaces, web-based?

I have designed a game in real life and thought of creating a very simple online version of it so I can play it with more people at any time. I don't have much experience with JS, just basic webpage functionality, though I have a lot of experience with programming in general.

The game is not very complicated in terms of mechanics, just turn-based in a real-time updating board and I'd probably be looking to something similar to what chess websites implement, if not an identical implementation. I'd just like resources related to designs I could get "inspiration" from and how the web clients would communicate with the server. I do not want to use automated assistance.

9 Upvotes

7 comments sorted by

5

u/Silly_Maintenance_87 5d ago

Check out Colyseus framework for networking and Phaser, PlayCanvas or Babylon engines for the client. Also, PixiJS is a solid choice for client side if you don't mind to implement basic game systems by yourself.

1

u/tomByrer 5d ago

also r/threejs has several game & gamish libs for it also. ThreeJS tends to have more support from AIs & Reddit, though I'm not sure about the ThreeJS game wrappers.

1

u/Skriblos 5d ago

Depending on what you are looking to do, there are multiple directions you could go. For the most outnod the box features you could use a game engine like phaser. Coincidentally I found this guide: https://www.dynetisgames.com/2017/03/06/how-to-make-a-multiplayer-online-game-with-phaser-socket-io-and-node-js/

That highlights most of what you need.

If you wanna go completely from scratch and don't need complex graphics then using the canvas API is what you should do MDN has some guides for how to do this: https://developer.mozilla.org/en-US/docs/Games

But more then that the things you need to know about are: General game design:    Canvas    Or webgl Communication:    Websockets    Routing - ip addresses and webhosting Server:    Game engine Server, if in js then using nodejs this includes websockets and concurrency.

This is not a comprehensive list either. There are tons of other resources on YouTube and you just have to Google, "how to make a multiplayer game in js" and you'll get a bunch of good links probably.

Keep in mind if you want to play with people of the local network you will need to either get a stable public ip from your internet provider or pay for Server hosting. Some of the cheapest plans are like 5$ a month but should cope with a handful of users.    

1

u/al3x_7788 5d ago

I already have the server hosting and DNS part covered.

I think for the most part, the game is so simple I'd go with the second thing you mentioned. I have some ideas about the interface, make some depth/3D effect but that'd be purely cosmetic so I'll probably keep it flat for now. Thank you for the links.

As I said in my original post, the game would have a board and two players, simple clicks.

I'll check it out.

1

u/Top_Pie2513 4d ago

https://github.com/croquet/croquet is a cool platform.

https://github.com/croquet/worldcore is a game engine built with it.

https://github.com/croquet/microverse takes worldcore a step further?

1

u/KarachoGames 4d ago

For a turn based board game you dont really need a game engine, a plain websocket server is enough. The "ws" package or socket.io both work fine for this.

The one rule that saves you most trouble: the server decides everything. The client only sends "player clicked field X" and the server checks if that move is allowed, saves the new board and sends the new state to both players. Never trust the browser, otherwise people will cheat with the dev tools open.

Also send the whole board state after every move (its tiny for a board game). Then reconnect and page refresh are trivial, the client just asks for the current state and draws it. If you have a clock, keep the time on the server too.

For inspiration the lichess source code is open and the ui part (chessground) is typescript, so you can see how a real chess site does it.