npm update, player movement logics
This commit is contained in:
parent
b422198925
commit
ca88c085e6
25
package-lock.json
generated
25
package-lock.json
generated
@ -1081,17 +1081,6 @@
|
||||
"resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz",
|
||||
"integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg=="
|
||||
},
|
||||
"node_modules/lru-cache": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
|
||||
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
|
||||
"dependencies": {
|
||||
"yallist": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/make-error": {
|
||||
"version": "1.3.6",
|
||||
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
|
||||
@ -1407,12 +1396,9 @@
|
||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
||||
},
|
||||
"node_modules/semver": {
|
||||
"version": "7.6.0",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz",
|
||||
"integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==",
|
||||
"dependencies": {
|
||||
"lru-cache": "^6.0.0"
|
||||
},
|
||||
"version": "7.6.1",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.6.1.tgz",
|
||||
"integrity": "sha512-f/vbBsu+fOiYt+lmwZV0rVwJScl46HppnOA1ZvIuBWKOTlllpyJ3bfVax76/OrhCH38dyxoDIA8K7uB963IYgA==",
|
||||
"bin": {
|
||||
"semver": "bin/semver.js"
|
||||
},
|
||||
@ -1805,11 +1791,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/yallist": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
||||
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
|
||||
},
|
||||
"node_modules/yn": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz",
|
||||
|
@ -51,6 +51,7 @@ async function authenticateUser(socket: any, username: string, password: string)
|
||||
socket.user = user;
|
||||
|
||||
world_players[user.id] = {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
coords: {
|
||||
x: 0,
|
||||
@ -74,6 +75,8 @@ async function setupMap(socket: any) {
|
||||
players: world_players
|
||||
});
|
||||
socket.emit('message', 'You have joined the room: ' + map.name);
|
||||
// list world players
|
||||
socket.emit('message', 'World players: ' + JSON.stringify(world_players));
|
||||
|
||||
// let the room know a new player has joined
|
||||
io.to(map.name).emit('player_join', world_players[socket.user.id]);
|
||||
@ -89,15 +92,16 @@ async function startTickEmitter(socket: any) {
|
||||
|
||||
function listenForMoveEvents(socket: any) {
|
||||
socket.on('move', (coords: any) => {
|
||||
console.log('Player moved:', socket.user.id, coords)
|
||||
const user = socket.user as IUser;
|
||||
world_players[user.id].coords = coords;
|
||||
io.in('Test Map').emit('player_move', {
|
||||
io.in('Test Map').emit('player_moved', {
|
||||
id: user.id,
|
||||
coords
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//r
|
||||
function listenForDisconnect(socket: any, username: string) {
|
||||
socket.on('disconnect', () => {
|
||||
console.log('User disconnected:', username);
|
||||
@ -115,4 +119,4 @@ async function listConnectedUsers() {
|
||||
io.on('connection', handleSocketConnection);
|
||||
|
||||
const PORT = process.env.PORT || 3000;
|
||||
server.listen(PORT, () => console.log(`Server running on port ${PORT}`));
|
||||
server.listen(PORT, () => console.log(`Server running on port ${PORT}`));
|
Loading…
x
Reference in New Issue
Block a user