Snaxe: Hours 5-7

Submitted by davidc on Wed, 14/09/2011 - 17:16

Edward came over to the atelier and we've been working on adding networking support for the mobile phone clients. We're using his Python software that sits between the clients and the game servers (which are known as "screens"). The clients talk to the "swarm server" natively using WebSockets, falling back to Flash-emulated sockets if the browser doesn't support them, and to AJAX if it doesn't support either. The game server talks to the swarm server using a simple TCP connection.

Messages are passed pretty simply, e.g. "p_2_hello" to send "hello" to player 2, "new_8" when player 8 joins, etc. The whole thing is very fast and should be plenty responsive enough for Snaxe.

He worked on the Python server while I did the Java side: integrating with the swarm server and updating it to handle multiple connections and types of connection. I can now have four players on the local keyboard as well; e.g. Q for my left hand to join the game, then WASD to move around.

The protocol we'll be using is pretty simple (C sent by client, S sent by server)

C: name_<player's name> Enter their name and joins the queue
S: queued Player is now in the queue to play
S: prepare_<N> Tell the player to get ready to play; countdown timer attached
S: color_#<RRGGBB> Inform them of their snake's colour in hexadecimal RGB
S: play Game is now in progress: switch to controller mode
C: n/e/s/w Face snake north/east/south/west
S: gameover Game is completed, return to the name screen

I also added an "Insert Coin" game state for between games, showing the current players waiting to play and the countdown until the next game starts (which will go down faster if more people are waiting, and will be instant if 8 players are ready).

Next: Hours 8-9.