NightsWatchGames / battle-city

Classical battle-city game made with bevy engine.
https://nightswatchgames.github.io/games/battle-city/
MIT License
85 stars 12 forks source link

Add Network multiplayer #23

Open MyMarvel opened 5 months ago

MyMarvel commented 5 months ago

I suppose it is a big subproject, but I want to understand how to do it and implement it for our project. The idea is to separate a background server from a frontend ui, so there will be 1 server in the internet (e.g. VDS or something) and 2 players, each one will play from his home and his own computer via battle-city ui. But they will play in the same battlefield together. I am curious what instruments rust and bevy has for such a purpose.

lewiszlw commented 5 months ago

Does original game support network multiplayer?

Network multiplayer is complex, especially the design of whole game never consider network. I tend not to add network functionality.

Actually I created another project (https://github.com/NightsWatchGames/texas-holdem) to learn networking. But I don't have much time after I changed my job, someday I will continue work on it.

I am curious what instruments rust and bevy has for such a purpose.

bevy_renet should be a good choice.

lewiszlw commented 5 months ago

And adding network functionality possibly makes game not be able to run in browser, as browser only supports websocket, webrtc protocols. As far as I know, there is no good enough plugin.

MyMarvel commented 5 months ago

No, the original game didn't have it obviously :) This is very interesting. I have plans to write my own game, and the multiplayer should be a real killer-feature for it, so your thoughts about "issues when the game architecture never considered network" worry me, so I want to learn it before creating my game :) Here is an interesting bunch of articles about network games architecture https://www.gabrielgambetta.com/entity-interpolation.html It looks like we should just add additional network layer to send players commands to the server and then sync the actual game state (from the server) with what we computed on the client's side (the predicted state). It looks not so hard for the player entity, but I'm not sure about enemies - it looks like we have to assume they will continue to move just forward and then we'll update their position when we get a changed direction from the game server. I am affraid it will be noticeable on the client side though, but I do not know another way to implement it yet. Anyway, it looks like this project is a good place to learn it.

MyMarvel commented 5 months ago

I read the article series to the end and now know the solution - entity interpolation (to show enemies with smooth movement). I'll try to implement it.

lewiszlw commented 5 months ago

Networking is cool, but I really don't want to refactor this game too much. Maybe you can create a fork to experiment networking.