Lately I've been looking into networking and sockets and made small test programs to get the basics down. So far I've made a TCP turn-based game from where I learnt a lot and helped me getting some fundamentals down.
Recently I also got a basic game working where multiple clients can connect and see each other move, but I feel like the architecture is not the best though. This made me want to expand the game a little and build a more solid foundation but I've been struggling to find the answers on a few questions I have.
The approach I've had for 2D action games(which is my goal to make) is to have a dedicated server, a separate project written purely in java(I use LibGDX for clients) and in the server project I have a Client
class which has a x
, y
, and an id
. Then when a client connects to the server it creates a new Client
object, gives it an ID based on the amount of clients connected and puts it in an ArrayList
called players
.
Then for movement I have the Game client send a message when it moves, structured like id,x,y;
. The servers Client
object receives the message and tells the server to broadcast()
it to all the other clients which in turn receives a position message. The Game clients get a message, structured as above, and the Game client updates his own playerList
.
This feels really clumsy and not well structured at all and this leads to my next question, what data should the server have?
Let's say we have a 2-player game where the players cooperate to kill mobs and receive items and exp. How would the server keep track of the mob entities? Would i create an identical Entity
class from the Game Client and put in the Server project with everything but the render
/ graphical stuff? And collision with projectiles and stuff, do I collision check in the Game Client and then validate in the server?
All this feels very overwhelming and I would love if someone could give me some advice or point me to any forum posts they've read. I've searched around the forum but haven't managed to find anything that really answers this structuring part.
Thanks in advance, feel free to ask me anything!