summaryrefslogtreecommitdiff
path: root/bubbob
diff options
context:
space:
mode:
authorDiego Roversi <diegor@tiscali.it>2020-05-23 10:05:51 +0200
committerDiego Roversi <diegor@tiscali.it>2020-05-23 10:05:51 +0200
commit2c41e377ab7257f879840abca9305fd25c274100 (patch)
treee0760281aff75f297aae75474fda0224edff206c /bubbob
parent81c86067960952f0ec87a035ce060da584e05df3 (diff)
more string to bytearray conversion
Diffstat (limited to 'bubbob')
-rw-r--r--bubbob/bubbles.py40
-rw-r--r--bubbob/levels/RandomLevels.py2
-rw-r--r--bubbob/macbinary.py30
3 files changed, 39 insertions, 33 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):