Inspired by BrowserQuest, I want to try my hand at making my own kind of game like this but I don't really know anything about game development other than the basics, like how the game loop works. Although, I feel more than confident with server-side/client-side JS so it's mostly just about learning concepts for me.
Some questions I've had so far when thinking about how I'll go about implementing it:
- I understand there'll be unsynced client-side code and synced server-side code. If a player presses an arrow key on their keyboard, should it send that information to the server, then the server says it's ok, then the client does it? Or should the client just do it anyway then the server validate it after-the-fact and correct the client if they perform an invalid action?
- The data going between server and client will initially be very simple. Currently I just have x and y positions for players. But how often is it ok for clients to send this data back to the server and the server to broadcast the data to all clients? I could do these things every 1ms which would make everything as smooth as possible, but wouldn't this kill the client/server or at least use a truck-load of bandwidth? I only have a very small VPS and wouldn't want to overload it by sending 1000 JSON objects to a bunch of clients every second when I don't have to. What's the sweet-spot here?
- I want to include some PvP style combat in my game but am not sure if the websocket protocol is suitable for this. With UDP, data is sent back and forth super fast partly in thanks to its unreliable nature, right? With websockets, will the communication between clients/server be fast enough to process something like a player attacking another player?
Any other advice about this sort of thing would be great, even if it's just links to existing documentation/examples. Cheers.