Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import lzma, base64
- from PIL import Image
- def b(a):
- return bytes([a])
- def sl(string):
- return bytes([len(string)]) + string
- def w(a):
- return int(a).to_bytes(2, "big")
- def wl(a):
- return int(len(a)).to_bytes(2, "big")
- def d(a):
- return int(a).to_bytes(4, "big")
- def dl(a):
- return int(len(a)).to_bytes(4, "big")
- def t(i, a, r = None):
- I = int(i).to_bytes(2, "big")
- A = bytes([a])
- if r:
- R = int(r).to_bytes(2, "big")
- else:
- R = b''
- return I + A + R
- def wh(w, h):
- return int(w).to_bytes(2, "big") + int(h).to_bytes(2, "big")
- image = Image.open('Tiles9x13.png')
- spriteSheet = image.load()
- COLUMNS = 9
- ROWS = 13
- TILE_WIDTH = int(image.size[0] / COLUMNS)
- TILE_HEIGHT = int(image.size[1] / ROWS)
- PALETTE = image.palette.tobytes()
- PALETTE_LENGTH = int(len(PALETTE) / 3)
- IMAGE = image.tobytes()
- #LZ_IMAGE = lzma.compress(image.tobytes())
- #LZB64_IMAGE = base64.b64encode(lzImg)
- DATA = bytes([COLUMNS, ROWS, TILE_WIDTH, TILE_HEIGHT, PALETTE_LENGTH])
- DATA += PALETTE + IMAGE
- """
- attributes:
- 0 = none
- 1 = flip horizontally
- 2 = flip vertically
- 3 = rotate 90
- 4 = rotate 180
- 5 = rotate 270
- 6 = none range
- 7 = fh range static ci
- 8 = fv range static ci
- 9 = r90 range static ci
- 10 = r180 range static ci
- 11 = r270 range static ci
- 12 = none range +ci
- 13 = fh range +ci
- 14 = fv range +ci
- 15 = r90 range +ci
- 16 = r180 range +ci
- 17 = r270 range +ci
- 18 = none range -ci
- 19 = fh range -ci
- 20 = fv range -ci
- 21 = r90 range -ci
- 22 = r180 range -ci
- 23 = r270 range -ci
- w = 0 copy name attribute (0 - 5)
- """
- BLANK = 114
- W, H = TILE_WIDTH, TILE_HEIGHT
- SPRITES = \
- sl(b'pf') + wh(W, H) + t(0,0) + \
- sl(b'ls') + wh(W * 2, H) + t(3, 0) + t(3, 1) + \
- sl(b'eg') + wh(W, H) + t(4, 0) + \
- sl(b'hy') + wh(W, H) + t(5, 0) + \
- sl(b'lt') + wh(W * 2, H) + t(6, 6, 2) + \
- sl(b'hsr') + wh(12, H * 2) + t(7, 12, 4) + \
- sl(b'hwr') + wh(12, H * 2) + t(7, 12, 2) + t(11, 12, 2) + \
- sl(b'hsl') + w(0) + sl(b'hsr') + b(1) + \
- sl(b'hwl') + w(0) + sl(b'hwr') + b(1) + \
- sl(b'hc1') + wh(12, H * 2) + t(13, 12, 2) + t(17, 12, 2) + \
- sl(b'hc2') + wh(12, H * 2) + t(15, 12, 2) + t(19, 12, 2) + \
- sl(b'hc3') + wh(12, H * 2) + t(13, 12, 2) + t(21, 12, 2) + \
- sl(b'csr') + wh(W, H * 2) + t(23, 12, 2) + \
- sl(b'cwr') + wh(W, H * 2) + t(26, 12, 2) + \
- sl(b'csl') + w(0) + sl(b'csr') + b(1) + \
- sl(b'cwl') + w(0) + sl(b'cwr') + b(1) + \
- sl(b'cpr') + wh(W * 2, H * 2) + t(28, 12, 2) + t(24, 12, 2) + \
- sl(b'cpl') + w(0) + sl(b'cpr') + b(1) + \
- sl(b'cc1') + wh(W, H * 2) + t(30, 12, 2) + \
- sl(b'cc2') + w(0) + sl(b'cc1') + b(1) + \
- sl(b'lv') + wh(W, H) + t(32, 0) + \
- sl(b'cg') + wh(4 * W, H * 5) + t(BLANK, 0) + t(33, 12, 2) + t(BLANK, 0) + t(35, 12, 2) + t(36, 19, 2) + t(37, 12, 2) + t(38, 19, 2) + \
- t(37, 12, 2) + t(38, 19, 2) + t(39, 12, 2) + t(40, 19, 2) + \
- sl(b'bc1') + wh(2 * W, 2 * H) + t(BLANK, 0) + t(41, 12, 3) + \
- sl(b'bc2') + wh(2 * W, 2 * H) + t(BLANK, 0) + t(44, 12, 3) + \
- sl(b'be1') + wh(2 * W, 2 * H) + t(47, 12, 3) + t(49, 1) + \
- sl(b'be2') + w(0) + sl(b'be1') + b(3) + \
- sl(b'tle') + wh(W * 21, H * 2) + t(50, 12, 5) + t(54, 1) + t(50, 12, 2) + t(55, 12, 6) + t(BLANK, 0) + t(59, 12, 4) + t(61, 12, 2) +\
- t(63, 12, 3) + t(65, 1) + t(66, 0) + t(66, 1) + t(63, 12, 2) + t(67, 12, 2) + t(57, 14, 2) + t(69, 0) + t(60, 2) + t(BLANK, 0) +\
- t(69, 0) + t(60, 2) + t(70, 12, 2) + t(70, 12, 2) + \
- sl(b'fnt') + wh(W * 43, H) + t(72, 12, 43)
- DATA += SPRITES
- LZ_DATA = lzma.compress(DATA)
- LZB64_DATA = base64.b64encode(LZ_DATA)
- writableData = bytes("CHUCKIE_SPRITES = b'", "utf-8") + LZB64_DATA + b"'"
- writableDataLen = len(writableData)
- writableDataChunks = int(writableDataLen / 100)
- #fn, ex = filename.split(".")
- f= open("sprites.py","wb")
- for index in range(writableDataChunks):
- f.write(writableData[index * 100: index * 100 + 100] + b"\\\n")
- f.write(writableData[(index + 1) * 100:] + b"\n")
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement