Monday, September 30, 2013

Networking for Games Game Jam Space Jam Games and Jam

Our task: create a slightly simplified version of Space Wars that could be played by 2-4 networked players in about two and a half hours.
The result: at the end of two and a half hours we had something that almost entirely didn't run.
Over the next few days Ian the Super Fantastic and I worked to finish it up and mend all the breaks.

The end product featured:
  • independent momentum and turning
  • toggle-able gravity and center planet
  • screen-wrapped player and projectile movement
  • a color selection lobby for player differentiation

The biggest challenge we faced was, what initially seemed to be, random data loss. Turns out we were trying to pack way too much data into single packets so it would try to read in data, get about halfway through it and run out of data to read. This lead to all sorts of interesting behavior and, considering the magnitude of the problem, surprisingly few breaks. Finally we decided to send packets that contained just a data identifier and the actual data  instead of packing everything into a single packet and sending it once a frame.

One thing I think we definitely should have done differently is handling player movement over the network. Currently each player simply sends it's screen coordinates every frame and each player updates the local version of that player. What we should have done was send the player's input when it was provided and let the actual movement be handled locally, perhaps with an actual position update every couple seconds to make sure things did not go horribly, horribly awry.

There were a couple things that went well, on the other hand. I think the general gravity and momentum based movement we implemented worked very smoothly. The color-selection lobby state I made is pretty spiffy as well. Each player flies around and chooses a color as indicated by color-overlays; the game refuses to start until there is only one player per color (as determined by the host), which we felt was a better way to determine the in-game differentiation without worrying about player order and assigning things based on it.

Ian Percoco is awesome: Ian's post