Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiplayer game programming

I'm working on a game where multiple players should be able to play at a time. It's a 2D game, and all the characters should be able to see each other move on the screen. Like the game is now all the devices just post and fetch each others coordinates to a server. This is done by running to threads:

public void StartCoordinatorFetcherThread(final Sprite Object)
{
    Thread CoordinateStarter = new Thread()
    {
        public void run()
        {           
            while(true)
            {
                Object.testing = Object.InternetObject.GetMessages();
                try {
                    Thread.sleep(20);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    };
    CoordinateStarter.start();
}

public void StartCoordinatorPosterThread(final Sprite Object)
{
    Thread CoordinatePoster = new Thread()
    {
        public void run()
        {           
            while(true)
            {
                Object.InternetObject.PostCoordinates(Object.x,Object.y);
                try {
                    Thread.sleep(20);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    };
    CoordinatePoster.start();
}

Anyway, I would like the characters to move more smoothly since it can be a bit "laggy" doing it like this.Does anyone have an idea on how I can achieve this goal?

Maybe I should I have a type of coordinate stack which just gets pushed coordinates to it all the time and then pops of the values as the game runs?

Any help will be highly appreciated.

Greetings!

like image 930
Araw Avatar asked Mar 29 '12 10:03

Araw


People also ask

What protocol is used for multiplayer games?

The two networking protocols that we'll discuss in the section, and that are also the two most widely used protocols in multiplayer networked games, are the Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP). Both protocols provide communication services between clients in a network system.

What protocol do video games use?

The two most common protocols are TCP (transmission control protocol) and UDP (user datagram protocol).

How does networking in games work?

There are mainly two possible network architectures: peer-to-peer and client-server. In the peer-to-peer architecture, data is exchanged between any pair of connected players while in the client-server architecture, data is only exchanged between players and the server.


1 Answers

I know that this is flash, but this is a nice tutorial to improve the move of players: http://playerio.com/documentation/tutorials/building-flash-multiplayer-games-tutorial/

like image 179
goodm Avatar answered Oct 02 '22 23:10

goodm