Domanda

I'm trying to integrate Kryonet within a Slick2D game with the assistance of this tutorial. I'm trying to create a server/client infrastructure where a user can either create a server or join a server to play a two player game.

The tutorial suggests adding the overall game object as a "network listener," however in my Slick2D game the GameContainer and StateBasedGame are only available across the whole application.

The GameContainer wraps my game object and this game object extends StateBasedGame. I have no idea how to integrate KryoNet.

I'm really struggling to find info that can help me so any guidance at all would be great.

È stato utile?

Soluzione

You should create a GameServer class and a GameClient class. Game logic goes in GameServer and rendering goes in GameClient. If your game logic is mixed with your rendering code, take a look at some model view controller explanations (here's a decent article: http://www.badlogicgames.com/wordpress/?p=2668).

Let me tell you that usually the server and client are completely different applications and sometimes it isn't feasable to let the users host the server because it might involve configuring firewalls and whatnot.

So GameServer should extend Listener, create an instance of kryonet's Server, and add itself as a listener to the server. GameClient should similarly extend Client, create an instance of kryonet's Client, and add itself as a listener to the client.

If you pass a reference of the current game state class to the GameClient, the GameClient can communicate to it and tell it what to render and then the game state can tell the client what to send as input. Similarly, if you pass a reference of the current game state class to the GameServer, the server can provide input to the game logic and then the game logic can tell the server what to send to the clients.

I would recommend creating a simple message passing program on IP loopback to get familiar with kryonet.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top