Programming Multiplayer Game – ArmyWarClient & ArmyWarServer

cover   This sample is a multiplayer 2D game. The communication between the server and client is the UDP socket. The UDP socket communication will be much faster compared to the TCP socket. But it will not guarantee the data will not lose and in the correct order. So we should consider using UDP data transfer for some un-critical data, and there was no effect on the game play even some data was lost.  To handle the problem of received data may not in order, we labeled the data with a sequence number.

Here the ArmyWar Server will also run the game logic: moving the player with some velocity, check whether a bullet hit the player, whether the player catch the flag and win the match; At the end of each frame, it will broadcast each player delta frame information to all players. Of course, there are also some code there about register new player, login into the game lobby, create a new room to start the game.

ArmyWar client will handle input and send user command to the server. The client will predict the player new position(this will produce an immediate response with the user input), sync and correct the predicted result with the server.

ArmyWar_Screenshot 
The above is the screen shot about the this sample. You could found the source code from here. You need to install OpenGL library and MySQL (you could found my version from here) to run it. One more thing that need to mention here is that i got the source code from the book text and the textures were just some place holders.

转载于:https://www.cnblogs.com/open-coder/archive/2013/05/05/3060610.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值