Answer the question
In order to leave comments, you need to log in
What is the best way to update player coordinates in the game?
Hello colleagues! Recently I was thinking about creating a primitive 2d browser game.
One moment is not clear. Each client (the player's computer, in our case) polls the server several times per second (I know that sockets are better, but I want to do this for now), and the server returns JSON with the coordinates of all the players (there are only 2 of them). After that, the client receives JSON and updates the positions of the players. It is not clear where the json file is stored. Just in a file on the server? But in this case there will be problems with simultaneous writing to a file + problems with obtaining a lock, in short, a file is not an option. In general, I do not understand the system with obtaining and updating the coordinates of the players. How to implement it?
I would like to thank everyone in advance who will help.
Answer the question
In order to leave comments, you need to log in
It is not clear where the json file is stored.tsya.ru
What are databases for?
You create an entity (table) in the database with the players. When changing a player's position, send a request to save a new position for a specific player. To get the position of all (you need) players, make a selection from the database and return it in the format you need (json).
If the speed of the database response matters, look towards Nosql - redis, mongodb.
If this is a real-time game, then a separate "working" demon is made that calculates the logic of the match and stores everything right in its memory. Players interact with it directly (usually a permanent connection is established, but you can also poll via http to start). After the end of the match, the changed data is dumped into the database.
If the game is turn-based, then either to the database or to the cache, but in both cases, you must immediately take into account the maximum expected load on them (how many simultaneous requests there will be, how much data will be driven, how often they will be updated). This is all very specific to a particular project.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question