Simple multiplayer 'real-time' online game that uses WebSockets and is played via browser. Also known as 'io game' type. Created with Golang (backend) and JavaScript/Phaser 3 (frontend).
Things you need to install.
- Golang (tested on 1.19.3)
- Browser that support JavaScript
- Clone repository using command
git clone https://github.com/vytautashi/go-tank.git
- Run command
go build
within/game-server
directory - Run command
go build
within/game-client
directory
- Run game-server executable in
/game-server
directory - Run game-client executable in
/game-client
directory - Access game using browser via url http://localhost:8081 (open on multiple tabs to spawn multiple players)
- Movement - keyboard arrows (up, down, left, right)
- Fire gun - spacebar
This repository demonstrates basic created 'io game' using Golang and Phaser. Player can move and fire bullets which collides with other players. Its not blooted with a lot of functionality in order to make it simple and easy to understand.
It does have:
- Movable game characters (tanks)
- Bullets collision with players
- Communication between server and clients via WebSockects
- Backend uses concurrency (Golang go routines, communication via channels, non-blocking)
It does not have:
- IP restrictor (same person from same computer can have multiple active players in game) (backend)
- Spam restrictor (do not limit message count received from clients/players via WebSockects) (backend)
- Client-side prediction (https://en.wikipedia.org/wiki/Client-side_prediction) (frontend)
- Code is not performance friendly (highly optimised code would be hard to read/understand)
- Now bullet objects are recreated everytime in frontend when it gets message about bullets positions from
game-server
, better would be to track bullets using id and move them accordingly instead of recreating or/and instead of deleting hide somewhere of the game screen and when command received, just set to correct position. (frontend) - Might be good to send only once Bullet data (position, speed, lifetime, moving direction) and let frontend calculate every next frame bullets positions, only send additional message to frontend if bullet collided with player and exploded so to remove bullet ealier from frontend. (backend+frontend)
- And other places.
- Now bullet objects are recreated everytime in frontend when it gets message about bullets positions from