125a4d11af
Now, when a user moves, only his/her position is sent back to the other users. The position of all users is not sent each time. The messages sent to the browser are now: - the list of all users as a return to the join_room event (you can send responses to events in socket.io) - a "join_room" event sent when a new user joins the room - a "user_moved" event when a user moved - a "user_left" event when a user left the room The GameScene tracks all these events and reacts accordingly. Also, I made a number of refactoring in the classes and removed the GameSceneInterface that was useless (it was implemented by the LogincScene for no reason at all) |
||
---|---|---|
.. | ||
src | ||
tests | ||
.dockerignore | ||
.eslintrc.json | ||
.gitignore | ||
Dockerfile | ||
jasmine.json | ||
package.json | ||
position-test.js | ||
README.md | ||
server.ts | ||
tsconfig.json | ||
yarn.lock |
Back Features
Login
To start your game, you must authenticate on the server back. When you are authenticated, the back server return token and room starting.
POST => /login
Params :
email: email of user.
Join a room
When a user is connected, the user can join a room.
So you must send emit join-room
with information user:
Socket.io => 'join-room'
userId: user id of gamer
roomId: room id when user enter in game
position: {
x: position x on map
y: position y on map
}
All data users are stocked on socket client.
Send position user
When user move on the map, you can share new position on back with event user-position
.
The information sent:
Socket.io => 'user-position'
userId: user id of gamer
roomId: room id when user enter in game
position: {
x: position x on map
y: position y on map
}
All data users are updated on socket client.
Receive positions of all users
The application sends position of all users in each room in every few 10 milliseconds.
The data will pushed on event user-position
:
Socket.io => 'user-position'
[
{
userId: user id of gamer
roomId: room id when user enter in game
position: {
x: position x on map
y: position y on map
}
},
...
]