49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
let players = {};
|
|
const config = {
|
|
type: Phaser.HEADLESS,
|
|
parent: "phaser-example",
|
|
width: 800,
|
|
height: 600,
|
|
autoFocus: false,
|
|
physics: {
|
|
default: "arcade",
|
|
arcade: {
|
|
debug: false,
|
|
gravity: { y: 0 },
|
|
},
|
|
},
|
|
scene: {
|
|
preload: preload,
|
|
create: create,
|
|
update: update,
|
|
},
|
|
};
|
|
function preload() {}
|
|
function create() {
|
|
const self = this;
|
|
io.on("connection", function (socket) {
|
|
console.log("a user connected");
|
|
// create a new player and add it to our players object
|
|
players[socket.id] = {
|
|
team: Math.floor(Math.random() * 2) == 0 ? "ukraine" : "russia",
|
|
};
|
|
// send the players object to the new player
|
|
socket.emit("currentPlayers", players);
|
|
// update all other players of the new player
|
|
socket.broadcast.emit("newPlayer", players[socket.id]);
|
|
socket.on("disconnect", function () {
|
|
console.log("user disconnected");
|
|
|
|
// remove this player from our players object
|
|
delete players[socket.id];
|
|
// emit a message to all players to remove this player
|
|
io.emit("disconnection_event", socket.id);
|
|
});
|
|
});
|
|
}
|
|
function update() {}
|
|
|
|
const game = new Phaser.Game(config);
|
|
|
|
window.gameLoaded();
|