E
E
Egorian2018-12-01 18:51:54
Node.js
Egorian, 2018-12-01 18:51:54

How to implement game rooms in the game?

Now I have a 2D tds browser shooter. On the node server, for physics I use the 2D MatterJs engine. Now simple mechanics have been implemented: synchronization of player movements, shooting, magazine.
At the moment, the server code has the following structure:

var gameObjects={players:{},walls:{},bases:{}}; // здесь хранится инфа о игроках и других объектах
// launch game cycle
    setInterval(function(){
        Matter.Engine.update(engine, engine.timing.delta); //обновление физики
    },1000/60)
io.on('connection', function (socket) {
socket.player=createPlayer(socket);
socket.on("....",function(){});
socket.on("....",function(data){});
socket.on("....",function(data){});
socket.on("....",function(data){});
socket.on("....",function(data){});
socket.on("....",function(data){});
});

And here's the question. How to implement rooms (sessions)? Came up with this option:
var rooms=[
    {players:{},walls:{},bases:{},engine:setInterval(...,1000/60)},
    {players:{},walls:{},bases:{},engine:setInterval(...,1000/60)},
    {players:{},walls:{},bases:{},engine:setInterval(...,1000/60)}
]

Допустим, что в одной комнате может быть maxN игроков, если N игроков > maxN, то закидывать в следующую комнату.
И один вопрос не по теме. Надо ли как-то распределять нагрузку на сервер? Потоки и т.д?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question