Implemented player login

This commit is contained in:
Quentin Roussel
2024-03-26 03:35:19 +01:00
parent b23d2a63e6
commit 7d75e91c80
16 changed files with 182 additions and 130 deletions

View File

@@ -1,5 +1,3 @@
import { Socket } from "socket.io";
export default class Game {
constructor() {
this.teams = [];
@@ -31,7 +29,8 @@ export default class Game {
chased: null,
currentLocation: [0, 0],
lastSentLocation: [0, 0],
enemyLocation: [0, 0]
enemyLocation: [0, 0],
sockets: []
});
this.updateTeamChasing();
return true;

View File

@@ -158,7 +158,9 @@ io.of("player").on("connection", (socket) => {
socket.on("disconnect", () => {
console.log("user disconnected");
game.getTeam(teamId).sockets = game.getTeam(teamId).sockets.filter(s => s !== socket.id);
if(teamId !== null && game.getTeam(teamId) !== undefined){
game.getTeam(teamId).sockets = game.getTeam(teamId).sockets.filter(s => s !== socket.id);
}
});
socket.on("login", (teamId) => {
@@ -175,7 +177,6 @@ io.of("player").on("connection", (socket) => {
});
socket.on("send_position", () => {
console.log("send_position", position);
game.sendLocation(teamId);
game.getTeam(teamId).sockets.forEach(s => {
io.of("player").to(s).emit("enemy_position", game.getTeam(teamId).enemyLocation);