I'm still ultra impressed by how much is in this game. The fact that you did networking too is awesome! How did you approach that?
Play game
Worlds in Perillel's itch.io pageComments
Thank you so much! I wrote a wordy blog about my experiences leading me to write this game here, but here's the short (yet somehow more detailed 🤔) version of the networking methodology:
- Doing realtime messaging is quite easy with node.js and socket.io. Since all the game logic is client side there's nothing else for the server to do but exchange messages.
- Since it's a two-player game, I opted for a simple "lobby" where the first person who connects gets a random game number from the server and waits until a second person enters the lobby. The second person gets the game number of the first. Instead of setting up a channel (as one normally does in websocket communications), I just assign each to an "opponent" property on their opponent's socket. If a socket has a value for its opponent property, it's in a game.
- The game number is used to seed a client-side random number generator so that the asteroid field is created identically on both players' screens regardless of device. Each asteroid is given an incremental id number which ends up being identical on both devices too.
- Players report their movements and collisions to the server who simply rely it to the other client who updates the display. When a player hits an asteroid they pass that id number which will tell their opponent which asteroid to remove from their screen.
- When the game ends, the server nulls out the opponent property on both sockets so they're no longer considered in a game.
Now this isn't at all how big games do it, and somebody with GreaseMonkey (or a similar plugin) could come up with a script to simply report planet collisions and defeat their opponent immediately. Heck, you could probably do it with the developer tools window now that I think about it. But the point was to have something functional after two days and that lack of security/integrity was the trade-off.
I hope that answered your question. I'd be more than happy to answer any others you may have.
Leave a comment
Log in with itch.io to leave a comment.