Programming multiplayer game-armywarclient & armywarserver

Source: Internet
Author: User

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 shoshould 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 stored ed 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 lolobby, 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.


The above is the screen shot about the this sample. you cocould found the source code from here. you need to install OpenGL library and MySQL (you cocould 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.