Git Product home page Git Product logo

amnp76 / pygame_multiplayer_server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thebillington/pygame_multiplayer_server

0.0 0.0 0.0 21 KB

Repository to hold the code for a very basic online multiplayer Python game, built using Pygame and PodSixNet. To run this project you must be using python 2.7 as the code is not compatible with python 3+;

License: MIT License

Python 100.00%

pygame_multiplayer_server's Introduction

pygame_multiplayer_server

This program is a very basic implementation of the PodSixNet server library using Pygame. There are two main components of the server, which are the client (game.py) and the server (server.py)

Client

The client is a PodSixNet ConnectionListener which can pump a connected server for new packets at regular time intervals. The OnlineGame class implements the ConnectionListener as well as all of the necessary pygame components to make the game run.

Each client has a player number and game ID, which is received from the server when the startgame message is received. This is used to identify which player is moving their character (when the request is sent to the server).

There is also a position network function, used to move the other player when a message is received from the server, notifying the client that the other player has moved.

Server

The server is a combination of a PodSixNet Server and Channel. The Server deals with sending messages to the clients, as well as new connections and game logic. The server has a field channelClass which points it to a Channel object, used to receive requests from the user and pass them on to the server.

When the server receives a connection from a new player, it checks the queue to see if there is a player already waiting. If there isn't, it creates a new game object and stores the players channel so that data can be sent back to the correct client.

If there is already a player in a queue, the second client Channel is added to the game object, and the startgame message is sent to both clients, allowing the game to load and notifying the client of the gameID and which player they are.

Improvements

The PodSixNet server uses TCP rather than UDP, making the sending of packets a costly process. In my original build of this test game, whenever a player was moved there was a message sent to both clients informing them of both player positions.

To improve the efficiency of the server the code has now been changed, so that a message is only sent to the player that DIDN'T move, and updates for this player moving are handled client side. This potentially would open room for cheating, however since any game physics (none so far) would be implemented on the server side, this wouldn't matter too much.

The PodSixNet server is ideal for writing turn based games, however it isn't so good for writing games that require a high number of regular updates, so bear this in mind when writing your server.

pygame_multiplayer_server's People

Contributors

thebillington avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.