Skip to content

Instantly share code, notes, and snippets.

@doorbash
Created September 13, 2020 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doorbash/eaeada076ebbb751c3816594b82bdd03 to your computer and use it in GitHub Desktop.
Save doorbash/eaeada076ebbb751c3816594b82bdd03 to your computer and use it in GitHub Desktop.
import { Client } from ".";
const client = new Client("ws://localhost:2560");
(async () => {
try {
const room = await client.joinOrCreate<any>("ffa");
console.log("joined successfully", room.sessionId);
room.state.players.onAdd = (player, i) => {
// console.log("add player", i);
}
room.state.players.onRemove = (player, i) => {
// console.log("remove player", i);
}
room.state.fruits.onAdd = (fruit, i) => {
if(fruit.key != i) {
console.error("WTF " + fruit.key + " != " + i)
}
// console.log("fruit added " + i)
}
room.state.fruits.onRemove = (fruit, i) => {
if(fruit.key != i) {
console.error("WTF " + fruit.key + " != " + i)
}
// console.log("fruit removed " + i)
}
} catch (e) {
console.error("couldn't join room:", e);
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment