M
M
MaxZalm2019-06-18 14:28:12
Game development
MaxZalm, 2019-06-18 14:28:12

How to organize server (tcp) logic with primitive game?

Good afternoon!
We decided with a friend to create a primitive game, we know how to program, but we haven’t come across games before the
idea is very simple, there is a field of 100 by 100 cells, 4 players, which means they occupy 4 cells
Press the forward button and move forward at a speed of 3 cells per second, for example, at this time, other players, in theory, should also see this movement and can move in the same way)
the question is how to implement this algorithmically? for example, I moved, informed the server, and the server sent the map to everyone again with the positions of the players? Or just send changes? or how in general
Please help me at least understand in which direction to move)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dollar, 2019-06-18
@dollar

In a simple implementation, everything is simple. Sorry for the tautology, but it's true. The client sends its position to the server (absolute coordinates) immediately after the change. The server sends these coordinates to the others.
But when there is a chance of a collision (for example) and this will need to be handled, or the players generally learn to shoot at each other (shooter), this is where the problems begin. Problems will be noticeable with a large ping. And the answer is no longer simple. You have to sacrifice something - accuracy, or the ability to cheat.
There are also all sorts of client optimizations when packets arrive with different delays, but the movement of the object looks smooth. Beauty also requires sacrifice.
PS tcp I do not advise. If there is little data (i.e. 4 players and 0 other objects), then it doesn't matter. But on high traffic, even 0.5% packet loss will result in lag. So if you plan to grow, it's better to choose udp right away (although the second tcp connection can be used to solve administrative tasks - searching for players, creating a session, etc.)
PPS The synchronization problem is well illustrated here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question