You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The guiding focus to how to write a client to connect to a Tokyo server, receive information events and create actions to control your ship
1. Connection information
ws://${host}/socket?key={key}&name{name}
Parameters
Description
{host}
Domain or IP of server want to connect
{key}
User's identity is unique and used to distinguish bots
{name}
The display name will be shown on UI
When the WebSocket connection is established successfully, your bot is registered, displayed on web UI and ready to use.
2. Action commands
Through WebSocket, a client can send action commands to control their ship.
2.1. Rotate the ship
{"e": "rotate", "data": 0.5}
Fields
Description
e
Event information "rotate"
data
Set the radian value that the ship will head. Value's between [0, 2π]
2.2. Throttle
Set the speed of your ship. Your ship starts to move forward with a new speed.
Set 0 to stop your ship.
{"e": "throttle", "data": 0.5}
Fields
Description
e
Event information "throttle"
data
Speed value. It's between [0, 1]
2.3. Fire a bullet
{"e": "fire"}
Fields
Description
e
Event information "fire"
3. Events
From WebSocket, the server consecutively sends events to the client every tick with the following structure.
Event message structure contains all world info of the game, including players, bullets, dead person, etc.
3.1. Events structure
3.1.1. State event
State event contains world map states that includes map info, players, bullets, dead and scoreboard
Boundary of the game, players spawn and navigate their ship in boundary from position [0,0] to this max size boundary. It's an array with two values, width and height
players
List of players/ships in the game currently. Detail of the player object will be described in the next sections
bullets
List of bullets that's fired by ships in the game currently. Detail of bullet object will be described in the next sections
dead
List of dead users and the respawn periods. Information of player is a structure with "players"
scoreboard
Top user scores with format "player_id: score"
3.1.2. Current user event
Event contains current user id
{"e":"id","data":247}
Fields
Description
e
State event is is always "id"
data
id of current user
3.1.3. User event
Event contains all users and their ids in the game.