-
Notifications
You must be signed in to change notification settings - Fork 18
Levels v7
- status: complete
- version: 7.x
- follows from: Authorization Rules
Levels break the game in independent parts, each of which can be played with different synchronization rules and group sizes.
The typical use case consists in having an initial single-player level where the game is explained, then the client reaches the waiting room of the next level where it waits to start the multiplayer game.
To create a new game level, create a new folder named after the level
inside the levels/
directory. For instance to create a level named part2
levels/part2/
.
Then, inside the new level directory, add a game/
folder, and optionally a waitroom/
folder, following exactly the same structure as for the corresponding folders at the top-level directory.
The order of the levels must be specified manually. The game begins by running the code inside the game/
folder; this is the default level. Then, clients must be moved to the next level manually.
A client finishing the default level could be moved to a next level named part2
with the following code.
The client sends a message to the logic:
node.say('level_done');
Upon receiving it, the logic uses the Server API to move the client to next room (usually the waiting room of the next level).
node.on.data('level_done', function(msg) {
// currentRoom is optional, avoid lookup.
let currentRoom; // let currentRoom = gameRoom.name;
let levelName = 'part2';
// Move client to the next level.
// (async so that it finishes all current step operations).
setTimeout(function() {
console.log('moving client to next level: ', msg.from);
channel.moveClientToGameLevel(msg.from, levelName, currentRoom);
}, 100);
});
Levels in the levels/
folder inherit all the settings and treatments from the default level (inside the top-level game/
folder). In addition, they can also add new settings and treatments or extend existing ones by specifying an own game.settings.js
inside the level's game/
directory.
Player data can be stored in the channel registry (you need to know the player id), while other game-related data can be stored directly in the channel object.
Player data
let client = channel.registry.getClient(playerId);
client.userName = 'XXX';
// Alternatively.
channel.registry.updateClient(playerId, { userName: 'XXX' });
Game data
channel.highScore = 1000;
Go back to the wiki Home.
Copyright (C) 2021 Stefano Balietti
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.