summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bubbob/bubbles.py40
-rw-r--r--bubbob/levels/RandomLevels.py2
-rw-r--r--bubbob/macbinary.py30
-rw-r--r--common/gamesrv.py36
-rw-r--r--display/modes.py24
-rw-r--r--display/pclient.py10
6 files changed, 84 insertions, 58 deletions
diff --git a/bubbob/bubbles.py b/bubbob/bubbles.py
index 523c64c..590b57e 100644
--- a/bubbob/bubbles.py
+++ b/bubbob/bubbles.py
@@ -1,5 +1,6 @@
-import random, math
+
+import random, math, sys
import gamesrv
import images
import boards
@@ -10,11 +11,11 @@ from mnstrmap import Lightning, Water, Fire, SpinningBalls, PlayerBubbles
bubble_wind = {
- '<': (-1, 0),
- '>': (+1, 0),
- '^': ( 0,-1),
- 'v': ( 0,+1),
- 'x': ( 0, 0),
+ b'<': (-1, 0),
+ b'>': (+1, 0),
+ b'^': ( 0,-1),
+ b'v': ( 0,+1),
+ b'x': ( 0, 0),
}
@@ -177,7 +178,10 @@ class Bubble(ActiveSprite):
self.vertical_warp()
## dx = -dx
w = wget(self.x, self.y)
- if w != ' ':
+ print(f"normal_movement: >{w}< {type(w)}", file=sys.stderr)
+ if w != b' ':
+ print(f"normal_movement: w!=b' ' {w}", file=sys.stderr)
+ print(f" bubble_wind= {bubble_wind}", file=sys.stderr)
dx, dy = bubble_wind[w]
elif self.default_windless:
dx, dy = self.default_windless
@@ -257,14 +261,14 @@ class Bubble(ActiveSprite):
y1 = (self.y + 27) // CELL
if dir < 0:
x1 = (self.x + 5) // CELL
- if bget(x1, y1) == ' ' == bget(x1, y1-1):
+ if bget(x1, y1) == b' ' == bget(x1, y1-1):
stepx = -hspeed
else:
ico = icons[0]
dir = 1
else:
x1 = (self.x + 26) // CELL
- if bget(x1, y1) == ' ' == bget(x1, y1-1):
+ if bget(x1, y1) == b' ' == bget(x1, y1-1):
stepx = hspeed
else:
ico = icons[0]
@@ -457,7 +461,7 @@ class DragonBubble(Bubble):
hspeed *= 0.965
xc = int(nx-3.8)//CELL+1
yc = (self.y+HALFCELL)//CELL
- if bget(xc,yc) == '#' == bget(xc, yc+1):
+ if bget(xc,yc) == b'#' == bget(xc, yc+1):
stop += 1
if stop <= 1:
self.move(int(nx+0.5), int(ny+0.5))
@@ -748,7 +752,7 @@ class FireFlame(ActiveSprite):
x0 = self.x//CELL
y0 = self.y//CELL
for dir in dirs:
- if bget(x0+dir, y0+1) == '#' and bget(x0+dir, y0) == ' ':
+ if bget(x0+dir, y0+1) == b'#' and bget(x0+dir, y0) == b' ':
FireFlame(x0+dir, y0, self.poplist, [dir], countdown-1)
for i in range(self.timeout):
yield None
@@ -766,7 +770,7 @@ class FireDrop(ActiveSprite):
self.gen.append(self.dropping())
def dropping(self):
x0 = self.x//CELL
- while bget(x0, self.y//CELL) == '#' or bget(x0, self.y//CELL+1) != '#':
+ while bget(x0, self.y//CELL) == b'#' or bget(x0, self.y//CELL+1) != b'#':
if self.y >= boards.bheight:
self.kill()
return
@@ -786,14 +790,14 @@ class FireBubble(BonusBubble):
if dragon:
x0 = self.x // CELL + 1
y0 = self.y // CELL + 1
- if bget(x0, y0) == '#':
+ if bget(x0, y0) == b'#':
x1 = (self.x + HALFCELL) // CELL
if x1 == x0:
tries = [x1+1, x1-1]
else:
tries = [x1, x1+2]
for x1 in tries:
- if bget(x1, y0) == ' ':
+ if bget(x1, y0) == b' ':
x0 = x1
break
FireDrop(x0*CELL, self.y)
@@ -985,15 +989,15 @@ class WaterCell(ActiveSprite):
s.repeat = 0
x0 = x // CELL
y0 = y // CELL
- if bget(x0, y0+1) == ' ':
+ if bget(x0, y0+1) == b' ':
if y >= boards.bheight:
s.kill()
continue
s.ping = 0
y += CELL
- elif bget(x0+dir, y0) == ' ':
+ elif bget(x0+dir, y0) == b' ':
x += dir*CELL
- elif bget(x0-dir, y0) == ' ':
+ elif bget(x0-dir, y0) == b' ':
s.ping += 1
if s.ping == 3:
s.kill()
@@ -1061,7 +1065,7 @@ class WaterBubble(BonusBubble):
x0 = self.x // CELL + 1
y0 = self.y // CELL + 1
for x1 in [x0, x0+1, x0-1]:
- if bget(x1,y0) == ' ' or bget(x1,y0+1) == ' ':
+ if bget(x1,y0) == b' ' or bget(x1,y0+1) == b' ':
x0 = x1
break
watercell(x0*CELL, y0*CELL, [None], repeat=19)
diff --git a/bubbob/levels/RandomLevels.py b/bubbob/levels/RandomLevels.py
index 16cc5ef..13256d0 100644
--- a/bubbob/levels/RandomLevels.py
+++ b/bubbob/levels/RandomLevels.py
@@ -358,5 +358,5 @@ if __name__ == '__main__':
print(s.__dict__)
else:
rnglevel = {}
- exec(compile(open('levels/rnglevel.py', "rb").read(), 'levels/rnglevel.py', 'exec'), rnglevel)
+ exec(compile(open('levels/rnglevel.py', "r").read(), 'levels/rnglevel.py', 'exec'), rnglevel)
RandomLevel = rnglevel['RandomLevel']
diff --git a/bubbob/macbinary.py b/bubbob/macbinary.py
index a485290..9d48764 100644
--- a/bubbob/macbinary.py
+++ b/bubbob/macbinary.py
@@ -1,11 +1,11 @@
import struct
-
+import sys
def padto(n, m):
return (n+m-1) & ~(m-1)
def resourceclass(rtype):
- return globals().get(rtype.strip() + 'Resource', Resource)
+ return globals().get(rtype.decode().strip() + 'Resource', Resource)
class TypeList:
@@ -118,7 +118,7 @@ class Subfile:
if size is None or self.position + size > self.length:
size = self.length - self.position
if size <= 0:
- return ''
+ return b''
self.f.seek(self.start + self.position)
self.position = self.position + size
return self.f.read(size)
@@ -170,8 +170,9 @@ def image2rgb(image):
result1 = []
for line in image:
for r, g, b in line:
- result1.append(chr(int(r)) + chr(int(g)) + chr(int(b)))
- return len(image[0]), len(image), ''.join(result1)
+ # result1.append(chr(int(r)) + chr(int(g)) + chr(int(b)))
+ result1.append( bytes([int(r),int(g),int(b)]) )
+ return len(image[0]), len(image), b''.join(result1)
class clutResource(Resource):
@@ -209,7 +210,7 @@ class ppatResource(Resource):
imgline = []
for x in range(w):
n = x//pixels_per_byte
- idx = ((ord(line[n]) >> ((pixels_per_byte - 1 - x%pixels_per_byte) * bits_per_pixel))
+ idx = ((line[n] >> ((pixels_per_byte - 1 - x%pixels_per_byte) * bits_per_pixel))
& ((1<<bits_per_pixel)-1))
imgline.append(colormap[idx])
image.append(imgline)
@@ -221,8 +222,8 @@ class LEVLResource(Resource):
WIDTH = 32
HEIGHT = 25
MONSTERS = 30
- WALLS = { 1:'#', 0:' '}
- WINDS = { 0:' ', 1:'>', 2:'<', 3:'v', 4:'^', 5:'x', 0x66:' '}
+ WALLS = { 1:b'#', 0:b' '}
+ WINDS = { 0:b' ', 1:b'>', 2:b'<', 3:b'v', 4:b'^', 5:b'x', 0x66:b' '}
FLAGS = ['flag0', 'letter', 'fire', 'lightning', 'water', 'top', 'flag6', 'flag7']
def getlevel(self, mnstrlist):
@@ -232,17 +233,18 @@ class LEVLResource(Resource):
walls = []
for y in range(self.HEIGHT):
line = f.read(self.WIDTH//8)
- line = [self.WALLS[(ord(line[x//8]) >> (x%8)) & 1]
+ print(f"LVLResource: line={line}", file=sys.stderr)
+ line = [self.WALLS[(line[x//8] >> (x%8)) & 1]
for x in range(self.WIDTH)]
- walls.append(''.join(line))
- result['walls'] = '\n'.join(walls)
+ walls.append(b''.join(line))
+ result['walls'] = b'\n'.join(walls)
winds = []
for y in range(self.HEIGHT):
line = f.read(self.WIDTH)
- line = [self.WINDS[ord(v)] for v in line]
- winds.append(''.join(line))
- result['winds'] = '\n'.join(winds)
+ line = [self.WINDS[v] for v in line]
+ winds.append(b''.join(line))
+ result['winds'] = b'\n'.join(winds)
monsters = []
for i in range(self.MONSTERS):
diff --git a/common/gamesrv.py b/common/gamesrv.py
index eaa9a87..44a3e9c 100644
--- a/common/gamesrv.py
+++ b/common/gamesrv.py
@@ -59,19 +59,28 @@ class DataChunk:
def read(self, slice=None):
f = open(self.filename, "rb")
data = f.read()
+ print(f"read: data={type(data)}",file=sys.stderr)
f.close()
if slice:
start, length = slice
data = data[start:start+length]
+ print(f"read: data={type(data)}",file=sys.stderr)
return data
def defall(self, client):
if client.proto == 1 or not self.filename:
# protocol 1
- try:
+ if hasattr(self,'msgdef'):
msgdef = self.msgdef
- except AttributeError:
- data = zlib.compress(self.read())
+ else:
+ print(f"self={type(self)}", file=sys.stderr)
+ data = self.read()
+ if type(data)==type(''):
+ raise Exception('data should be bytes, not str')
+# data=data.encode()
+ print(f"defall: data={type(data)}", file=sys.stderr)
+ print(f"defall: data={data}", file=sys.stderr)
+ data = zlib.compress(data)
msgdef = self.msgdef = self.getmsgdef(data)
else:
# protocol >= 2
@@ -130,6 +139,8 @@ class Bitmap(DataChunk):
class MemoryBitmap(Bitmap):
def __init__(self, code, data, colorkey=None):
+ if type(data)==type(''):
+ raise Exception('data should be bytes, not str')
self.data = data
Bitmap.__init__(self, code, None, colorkey)
@@ -477,13 +488,16 @@ class Client:
del self.sounds[key]
if broadcast_extras is None or self not in broadcast_clients:
if self.dyncompress is not None:
- # DEBUG: print(f"self.dyncompress={self.dyncompress}", file=sys.stderr)
+ # DEBUG:
+ print(f"(before) self.dyncompress={self.dyncompress}", file=sys.stderr)
udpdatas = self.dynamic_compress(udpdata)
- # DEBUG: print(f"udpdata={udpdata}",file=sys.stderr)
+ # DEBUG:
+ print(f"(after) udpdata={udpdata} udpdatas={udpdatas}",file=sys.stderr)
else:
udpdatas = [udpdata]
- # DEBUG: print(f"udpdatas={udpdatas}",file=sys.stderr)
- for udpdata in udpdatas or []:
+ # DEBUG:
+ print(f"udpdatas={udpdatas}",file=sys.stderr)
+ for udpdata in udpdatas: # or []:
try:
self.udpsockcounter += self.udpsocket.send(udpdata)
except error as e:
@@ -547,16 +561,17 @@ class Client:
yield None, None
frame = (frame + 1) & 0xFF
- self.dyncompress = dyncompress()
+ self.dyncompress = None # dyncompress() disable compression TODO
def dynamic_compress(self, framedata):
result = []
+ print(f"head={head} co={co}", file=sys.stderr)
for head, co in self.dyncompress:
if not co:
return result
data = [head, co.compress(framedata), co.flush(zlib.Z_SYNC_FLUSH)]
if head:
- result.append(''.join(data))
+ result.append(b''.join(data))
def send_can_mix(self):
return not self.msgl and self.socket is not None
@@ -825,6 +840,7 @@ class SimpleClient(Client):
def finishinit(self, game):
num = 0
for keyname, icolist, fn in game.FnKeys:
+ print(f"finishinit: fn={fn} keyname={keyname} icolist={icolist}", file=sys.stderr)
self.msgl.append(message(MSG_DEF_KEY, keyname.encode(), num,
*[ico.code for ico in icolist]))
num += 1
@@ -834,9 +850,11 @@ class SimpleClient(Client):
try:
player = self.players[pid]
fn = game.FnKeys[keynum][2]
+ print(f"cmsg_key: fn={fn} keynum={keynum}", file=sys.stderr)
except (KeyError, IndexError):
game.FnUnknown()
else:
+ print(f"cmsg_key: player={player}", file=sys.stderr)
getattr(player, fn) ()
MESSAGES = Client.MESSAGES.copy()
diff --git a/display/modes.py b/display/modes.py
index c43638d..caadfcb 100644
--- a/display/modes.py
+++ b/display/modes.py
@@ -13,8 +13,8 @@ class BaseDisplay:
def taskbar(self, s):
(x, y, w, h) = s
if self.__taskbkgnd is None:
- pixel = "\x00\x00\x80"
- hole = "\x01\x01\x01"
+ pixel = b"\x00\x00\x80"
+ hole = b"\x01\x01\x01"
self.__taskbkgnd = self.pixmap(32, 32,
((pixel+hole)*16 + (hole+pixel)*16) * 16, 0x010101)
for j in range(y, y+h, 32):
@@ -105,12 +105,12 @@ class SoundMode(Mode):
def graphicmodeslist():
return [
- GraphicMode('X', 'XWindow (Linux/Unix)',
- ['--shm=yes use the Shared Memory extension (default)',
- '--shm=no disable it (for remote connections or old X servers)',
- ],
- {'shm': 'yes'}),
- GraphicMode('windows', 'MS Windows', []),
+# GraphicMode('X', 'XWindow (Linux/Unix)',
+# ['--shm=yes use the Shared Memory extension (default)',
+# '--shm=no disable it (for remote connections or old X servers)',
+# ],
+# {'shm': 'yes'}),
+# GraphicMode('windows', 'MS Windows', []),
GraphicMode('pygame', 'PyGame library (all platforms)',
['--fullscreen=yes go full screen (Esc key to exit)',
'--transparency=yes slightly transparent bubbles (default)',
@@ -121,10 +121,10 @@ def graphicmodeslist():
{'transparency': 'yes', 'fullscreen': 'no',
'zoom': '100', 'smooth': 'yes', 'smoothfast': 'no'},
url='http://www.pygame.org'),
- GraphicMode('gtk', 'PyGTK (Gnome)',
- ['--zoom=xxx% scale image by xxx %'],
- {'zoom': '100'},
- url='http://www.pygtk.org/'),
+# GraphicMode('gtk', 'PyGTK (Gnome)',
+# ['--zoom=xxx% scale image by xxx %'],
+# {'zoom': '100'},
+# url='http://www.pygtk.org/'),
]
def soundmodeslist():
diff --git a/display/pclient.py b/display/pclient.py
index 25820b1..b8650f6 100644
--- a/display/pclient.py
+++ b/display/pclient.py
@@ -226,7 +226,7 @@ class Playfield:
raise
break
self.udpbytecounter += len(udpdata)
- if len(udpdata) > 3 and '\x80' <= udpdata[0] < '\x90':
+ if len(udpdata) > 3 and 0x80 <= udpdata[0] < 0x90:
udpdata = self.dynamic_decompress(udpdata)
if udpdata is not None:
udpdata1 = udpdata
@@ -248,7 +248,7 @@ class Playfield:
self.update_sprites(udpdata)
if self.pending_udp_data:
self.update_sprites(self.pending_udp_data)
- self.pending_udp_data = ''
+ self.pending_udp_data = b''
erasetb = self.taskbarmode and self.draw_taskbar()
d = self.dpy.flip()
if d:
@@ -345,12 +345,14 @@ class Playfield:
except KeyError:
data, colorkey = self.bitmaps[bmpcode]
if type(data) is type(''):
+ raise Exception('data should be bytes, not str')
+ if type(data) is type(b''):
data = zlib.decompress(data)
else:
if data.pending:
raise KeyError
data = data.read()
- print(f"getpixmap(bmpcode = {bmpcode}) data={data[:64]} colorkey={colorkey}",file=sys.stderr)
+ ## DEBUG print(f"getpixmap(bmpcode = {bmpcode}) data={data[:64]} colorkey={colorkey}",file=sys.stderr)
pixmap = loadpixmap(self.dpy, data, colorkey)
self.pixmaps[bmpcode] = pixmap
return pixmap
@@ -713,7 +715,7 @@ class Playfield:
ico.alpha = alpha
def msg_def_bitmap(self, bmpcode, data, colorkey=None, *rest):
- if type(data) is not type(''):
+ if type(data) is not type(b''):
data = self.fileids[data]
self.bitmaps[bmpcode] = data, colorkey