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

[pygame] bit operations



Hi:

This is more a python question... And may be stupid... but i cannot see it... please help.

I want to make my game playable online. So I have to send all the info to the client and then he will draw corresponding frames in corresponding positions in the screen...

So I want to send a list of integers to the client [(x, y) coords, image(ship/explosion...) index, frame index (they are many frames for each ship/explosion...)....  )]

So I decided to 'pack' them in order to send less bytes in a array (x,y never should be > 2048, so I can send this coords in 22 bits -3 bytes instead of 4-) doing something like this code that I've done to test :

t = 0.0 + (1 << 48) + (2 << 40) + (3 << 32) + (4 << 24) +  (5 <<16) + (6 << 8) + 7 # So I have all the info in one number
print "t is " + `t`
j =  (t >> 48)
print j


And I've this output:

t is 283686952306183.0

 j =  (t >> 48)

TypeError: unsupported operand type(s) for >>: 'float' and 'int'

why this error? :(