[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] pygame networking redux



On Tue, Jun 05, 2007 at 11:45:25AM +1000, 12 Dogs wrote:
> 
>    Don't know if this will be helpful, but a while ago i started writing a
>    lemmings  clone using twisted for networking.  the file in question is
>    availablehere:[1]http://thescarydoor.googlecode.com/svn/trunk/default.pyi
>    didn't have much problems with the twisted loop and the event code, i just
>    didn't use the event loop.  The only other option is to use twisted in a
>    second thread which can get a little messy but not too bad as it's just 1
>    thread.
>    Nathan
> 

I also did a game sketch (emphasis on the sketch part) of a "Space Wars" 
game that would support network play using twisted.  The trick I think I 
used was to integrate the pygame event loop and the Twisted reactor was 
to write a function to handle all the pygame things would normally do in 
the main loop, and then supply that function as a callback to 
reactor.callLater().  The callback's last action would be to call 
reactor.callLater() again.  In that way, the pygame event loop just got 
handled by the reactor.

It's not done, as it just supports the server side, but you can see it 
run and send updates out by telnetting to port 7190 on the machine you 
run it on.  You'll get spammmed by the server player's ship position.  
The protocol was designed to be dirt simple, so I could do things like 
telnet in and get some sense of what was going on for debugging 
purposes.

It's probably a naive way of approaching the problem, but it seemed to 
be on the path of working.  If someone wants to play with the code, you 
can get it at 
http://aminorgames.com/downloads/sketches/netgame_demo.tar.gz

It works well on my Fedora Core 4 system using Python 2.4.3 and pygame 
1.7.1

As a bonus, I was learning about joystick controls in pygame, too, so 
the ship has all kinds of fun controls like directional fire, 
autobraking, and retrorockets if you use a Saitek ST290 Pro joystick. 
;-)

Randy