junglejourney
changeset 235:b74ffb65fb88
Added more sprites for the Atom and a script to convert them to screen data.
| author | David Boddie <david@boddie.org.uk> |
|---|---|
| date | Sun Aug 26 00:18:50 2012 +0200 |
| parents | 8862c859a18a |
| children | f7624dec0ba1 |
| files | images/atom/demise1.png images/atom/demise2.png images/atom/demise3.png images/atom/demise4.png images/atom/down1.png images/atom/down2.png images/atom/left1.png images/atom/left2.png images/atom/right1.png images/atom/right2.png images/atom/up1.png images/atom/up2.png tools/atom/makesprites.py |
| diffstat | 13 files changed, 100 insertions(+), 0 deletions(-) [+] |
line diff
1.1 Binary file images/atom/demise1.png has changed
2.1 Binary file images/atom/demise2.png has changed
3.1 Binary file images/atom/demise3.png has changed
4.1 Binary file images/atom/demise4.png has changed
5.1 Binary file images/atom/down1.png has changed
6.1 Binary file images/atom/down2.png has changed
7.1 Binary file images/atom/left1.png has changed
8.1 Binary file images/atom/left2.png has changed
9.1 Binary file images/atom/right1.png has changed
10.1 Binary file images/atom/right2.png has changed
11.1 Binary file images/atom/up1.png has changed
12.1 Binary file images/atom/up2.png has changed
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/tools/atom/makesprites.py Sun Aug 26 00:18:50 2012 +0200 13.3 @@ -0,0 +1,100 @@ 13.4 +#!/usr/bin/env python 13.5 + 13.6 +""" 13.7 +Copyright (C) 2012 David Boddie <david@boddie.org.uk> 13.8 + 13.9 +This program is free software: you can redistribute it and/or modify 13.10 +it under the terms of the GNU General Public License as published by 13.11 +the Free Software Foundation, either version 3 of the License, or 13.12 +(at your option) any later version. 13.13 + 13.14 +This program is distributed in the hope that it will be useful, 13.15 +but WITHOUT ANY WARRANTY; without even the implied warranty of 13.16 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13.17 +GNU General Public License for more details. 13.18 + 13.19 +You should have received a copy of the GNU General Public License 13.20 +along with this program. If not, see <http://www.gnu.org/licenses/>. 13.21 +""" 13.22 + 13.23 +""" Information provided by Kees van Oss: 13.24 + 13.25 + BBC ATOM 13.26 +TILES 16 x 24 -> 12 x 16 13.27 +PLAYER 8 x 24 -> 8 x 16 13.28 +PROJECTILE 8 x 8 -> 8 x 8 13.29 +ENEMIES 16 x 16 -> 12 x 12 13.30 +WEAPONS 16 x 16 -> 12 x 12 13.31 +TREASURE 16 x 16 -> 12 x 12 13.32 +EXIT 16 x 24 -> 12 x 16 13.33 + 13.34 +Hex: $a0 , $80 , $aa 13.35 +Bin:%10 10 00 00, %10 00 00 00, %10 10 10 10 13.36 +Col: BL BL GR GR BL GR GR GR BL BL BL BL 13.37 + 13.38 +00 = GR = GREEN, 01 = YE = YELLOW, 10 = BL = BLUE, 11 = RE = RED 13.39 +""" 13.40 + 13.41 +import os, sys 13.42 +import Image 13.43 + 13.44 +# Map RGB values to the appropriate values for the Atom palette. 13.45 +palette = {"\x00\x00\x00": 2, "\xff\x00\x00": 3, 13.46 + "\x00\x80\x00": 0, "\xff\xff\x00": 2} 13.47 + 13.48 +if __name__ == "__main__": 13.49 + 13.50 + this_dir = os.path.split(os.path.abspath(__file__))[0] 13.51 + image_dir = os.path.join(this_dir, os.path.pardir, os.path.pardir, "images", "atom") 13.52 + 13.53 + sprites = "" 13.54 + 13.55 + for file_name in os.listdir(image_dir): 13.56 + 13.57 + if file_name.endswith(".png"): 13.58 + 13.59 + im = Image.open(os.path.join(image_dir, file_name)) 13.60 + im = im.convert("RGB") 13.61 + data = im.tostring() 13.62 + k = 0 13.63 + 13.64 + sprite = "" 13.65 + 13.66 + for i in range(im.size[1]): 13.67 + 13.68 + # Initialise the byte value for insertion into the sprite data. 13.69 + byte = 0 13.70 + # The offset into the byte for each pixel starts at the highest 13.71 + # two bits. 13.72 + offset = 6 13.73 + 13.74 + for j in range(im.size[0]): 13.75 + 13.76 + rgb = data[k:k+3] 13.77 + v = palette[rgb] 13.78 + byte = byte | (v << offset) 13.79 + 13.80 + if offset == 0: 13.81 + # For the last pixel in a byte, insert it into the sprite 13.82 + # data, and reset the offset and byte values. 13.83 + sprite += chr(byte) 13.84 + offset = 6 13.85 + else: 13.86 + # Otherwise, decrease the offset into the byte to accept 13.87 + # data for the next pixel. 13.88 + offset -= 2 13.89 + 13.90 + k += 3 13.91 + 13.92 + if offset != 6: 13.93 + # If the current byte has not been added to the sprite data, 13.94 + # add it now. 13.95 + sprite += chr(byte) 13.96 + 13.97 + # Add the sprite data to the collection. 13.98 + sprites += sprite 13.99 + 13.100 + # Write the sprite data to a file. 13.101 + open("sprites.data", "w").write(sprites) 13.102 + 13.103 + sys.exit()
