Advertisement

2D Smash Bros. Type Game and P2P???

Started by January 24, 2005 11:34 AM
0 comments, last by wyrzy 20 years ago
Hi, I'm currently developing a Smash Bros. type game using SDL and C++. I'm almost done with the game logic, but I want to implement a Peer-to-Peer system of play. I want 2 machines to connect over a LAN using IP addresses specified by each user at startup. Basically all I want to send for now is positions. I understand that if for instance, player 1's position was sent to player 2, then player 2 could simply draw player 1 at the correct position. What I need to know is: 1)Does SDL already support this type of thing? 2)I've heard alot about WinSock, but when searching the articles, I see nothing on how to configure a p2p connection. 3)Could someone show me some code or give a link to code that uses a system of p2p networking used in a simple game (perhaps one for updating position of a sprite).Thx in advance
toXic1337
Quote:
Original post by toXic1337
Hi,
I'm currently developing a Smash Bros. type game using SDL and C++. I'm almost done with the game logic, but I want to implement a Peer-to-Peer system of play. I want 2 machines to connect over a LAN using IP addresses specified by each user at startup. Basically all I want to send for now is positions. I understand that if for instance, player 1's position was sent to player 2, then player 2 could simply draw player 1 at the correct position. What I need to know is:
1)Does SDL already support this type of thing?
2)I've heard alot about WinSock, but when searching the articles, I see nothing on how to configure a p2p connection.
3)Could someone show me some code or give a link to code that uses a system of p2p networking used in a simple game (perhaps one for updating position of a sprite).Thx in advance

1) SDL has SDL_net for cross-platform networking. Its not much more than just cross-platform calls for sockets programming.

2) From my understanding of P2P, each computer acts as both a client and a server, so you could just follow the tutorials for configuring a client/server setup at http://jcatki.no-ip.org/SDL_net/ (SDL_net site), but do both the client and the server parts for both computers.

3) Here's some psuedo code:
// below is done at startup
Listen( PORT_YOUR_GAME_USES );

//now when you want to connect to a client
while( NULL == (sending_socket=Connect( PORT_YOUR_GAME_USES )) );

//now accept an incoming connection as we're assuming someone also connected to you
while( NULL == (receiving_socket=Receive( PORT_YOUR_GAME_USES )) );

//now in your game
Send( sending_socket, (char *data), size_of_data );
int len=0;
do
{
len += Recv( receiving_socket, (char *data)+len, size_of_data-len );
} while( len < size_of_data );

The above pseudo code was done off the top of my head, and I also am self-taught at network code, so my methods may not be the best. I do, however, use code like that for a net-game I'm making, and it runs smoothly over LAN and the Internet (tested with someone about 400 miles away).

This topic is closed to new replies.

Advertisement