Squaresplosion
https://github.com/orndorffgrant/squaresplosionPost backdated to the time of the project.
Squaresplosion is a game that a friend and I made during the pandemic. It's a simple multiplayer game where players are squares that move around and try to hit eachother to explode them.
The code and a FAQ are on my github. For a while we hosted it at https://game.squaresplosion.com, but eventually we took it down.
I was mostly responsible for the backend, though I contributed to the UI a bit as well.
This was my first rust project, and I went with async rust as well. At the time, tokio
wasn't the obvious choice (to me at least) for the async runtime, so I used async-std
.
All state is held in memory and read/written by one task. The server spawns a reader and writer task for each websocket connection. As the client sends commands to join a room and then move around, the reader task deserializes them and forwards to the state-owning task. The state-owning task will update the room with player locations, decide if anyone has 'sploded, and broadcast the state to all the writers associated with that room. Those writers then serialize the state and send it to the clients.
The code is riddled with unwrap
s and I'm sure plenty of other bad rust practices, but it worked well enough to play the game with friends!