Nyra Studios
Manual under construction. Some parts are incomplete or may change.

Moving, by mode

Nyra 0.5.4.28

Your client sends intentions: a step, a key pressed, an angle. Position and speed are always worked out by the server. Which mode the game uses you read in welcome.movementMode. The messages of another mode are ignored, without an answer.

Where the character is

x and y are pixels, but they mean a different point in each mode. Put the anchor point of your sprite accordingly.

ModeWhat x and y are
TileThe top left corner of the cell.
PlatformThe feet, at the centre of the base of the character.
8 directionsThe centre of the character.

The y axis grows downwards.

Tile: one step at a time

The character moves one cell at a time. The time of a step is tileConfig.moveDurationMs.

Taking a step. You send move-input:

json
{ "type": "move-input", "dx": 1, "dy": 0 }
  • dx and dy must be numbers. If they are not, the server ignores the message.
  • Only the sign and the strongest axis count: one message makes one step of one cell on a single axis. There is no diagonal step. If dx and dy are both different from zero, the axis with the bigger value wins, and on a tie dy wins.
  • With dx and dy equal to zero you get no answer: it is the stop signal, not a refusal.

If the step is accepted, all the players (you too) receive:

json
{ "type": "player-moved", "playerId": "…", "fromX": 320, "fromY": 320, "toX": 352, "toY": 320, "durationMs": 200, "facing": 0 }

Your client animates the character from fromX, fromY to toX, toY in durationMs. The arrival position stays saved on the account: at the next logins the character starts from there.

If the step is thrown away, you alone receive move-rejected with a reason:

  • in-transition: the character is still taking the previous step.
  • out-of-bounds: the arrival cell is outside the map.
  • blocked: the arrival cell is inside a solid wall.

In tile the server stops the step against solid walls, even when the wall touches the cell only partly; oneway and none are gone through. Whoever receives the refusal gets move-rejected with the reason blocked: the character stays where it is and the facing does not change. If the character already starts inside a wall, it walks freely until it reaches a free cell; from there the walls stop it again.

Turning on the spot. You send face-input:

json
{ "type": "face-input", "facing": 180 }

The allowed values are 0, 90, 180 and 270: 0 is right, 90 is down, 180 is left and 270 is up. If the facing changes, everyone (you too) receives:

json
{ "type": "player-turned", "playerId": "…", "facing": 180 }

If the facing is already that one, nothing happens. During a step you receive face-rejected with the reason in-transition. You can send at most 10 face-input a second. The facing is saved: at the next login you find it in the welcome.

Platform: running and jumping

The character runs, jumps and falls with gravity. You send the state of the keys, only when it changes:

json
{ "type": "input-state", "left": false, "right": true, "jump": false, "run": true }
  • A field counts as pressed only if it is exactly true. If it is missing, it is false.
  • If left and right are pressed together, the character does not move sideways.
  • The jump starts when jump goes from false to true. Holding it down does not make it jump again.
  • Running counts only with a direction key pressed and with the character on the ground.

If onGround is false in the welcome, the character is falling: wait for it to become true before sending the jump.

The server works out the movement and sends it to everyone, only when the position changes:

json
{ "type": "player-moved", "playerId": "…", "x": 145.24, "y": 331.54, "velocityY": -486.6, "onGround": false, "running": false }

The physics values (gravity, speeds, jump, size of the character) are in welcome.physicsConfig. In this mode there is no facing field: if you need it, work the direction out from the keys. In platform and in 8 directions x and y are decimal numbers.

8 directions: free in pixels

The character moves in every direction, with the same speed in each one: the diagonal is not faster. The walls and the shapes of the level stop it, and the character slides along the walls. You have two ways of saying where to go.

With the keys. You send the state of the keys, only when it changes:

json
{ "type": "input-state", "left": false, "right": true, "up": true, "down": false, "run": false }

Opposite keys (left with right, up with down) cancel each other. The jump field is ignored.

With an angle (free direction). Useful for a game with a rotated camera, or to move with a stick:

json
{ "type": "input-angle", "moving": true, "angle": 135.5, "run": false }

and to stop:

json
{ "type": "input-angle", "moving": false }

The angle is in degrees: 0 is right, 90 is down, 180 is left and 270 is up, and the values in between are fine (135.5 is down-left). You can send any number: the server brings it back between 0 and 360 and rounds it to hundredths. With run at true the character runs. An angle that is not a number is thrown away.

The two ways do not mix: the last message received always counts, be it input-state or input-angle. You can send the angle at every step if the camera keeps turning, but the server accepts at most 60 a second. The stop message, with moving at false, is always accepted. The character does not stop by itself: it keeps going until you send moving at false, or all the keys are released.

The server sends to everyone, both for the keys and for the angle:

json
{ "type": "player-moved", "playerId": "…", "x": 205.94, "y": 205.94, "facing": 45, "angle": 45, "moving": true, "running": false }
  • facing is the facing in steps of 45 degrees, for whoever draws sprites in eight directions.
  • angle is the precise facing, in degrees, with the same convention.
  • When the character stops, you receive one last message with moving and running at false.
  • If only the facing changes, without movement, you receive the message anyway.

The values (speeds, size of the character, collision between players) are in welcome.eightdirConfig. When you connect again, you find the position where you left it. The angle is saved too: at the login the welcome carries in angle the last saved angle, and facing is worked out from that angle; if there is no saved angle it is 90.

Warning

The server always works out the speed by itself. There is no message to say how fast to go or how far: your client sends only the direction.