examples: new sprite animation demo

This commit is contained in:
slederer 2025-06-20 01:19:40 +02:00
parent bde01e402c
commit e08d610aef
6 changed files with 186 additions and 24 deletions

View file

@ -2,6 +2,9 @@
import sys
import png
sprite_width = 32
sprite_height = 32
def process_pixdata(outfile, pixdata, frameindex = 0, pix_w=640, pix_h=400):
pixmask = 15
@ -72,22 +75,20 @@ def write_pict_file(width, height, px, metadata, outfile):
def write_sprite_file(width, height, px, metadata, outfile):
sprite_height=16
print("processing as SPRT file with {} sprites...".format(height//sprite_height))
if width != 16:
print("width must be 16, aborting")
if width != sprite_width:
print("width must be {}, aborting".format(sprite_width))
sys.exit(1)
pixdata = list(px)
palette = metadata['palette']
if len(palette) != 16:
print("palette must have 16 colors, aborting")
print("palette must have 16 colors instead of {}, aborting".format(len(palette)))
sys.exit(0)
with open(outfile,'wb') as f:
write_sprite_header(f)
process_pixdata(f, pixdata, pix_w=16, pix_h=height)
process_pixdata(f, pixdata, pix_w=sprite_width, pix_h=height)
if __name__ == '__main__':
@ -103,8 +104,8 @@ if __name__ == '__main__':
width, height, px, metadata = p
if width == 640:
write_pict_file(width, height, px, metadata, outfile)
elif width == 16:
elif width == sprite_width:
write_sprite_file(width, height, px, metadata, outfile)
else:
print("Can't handle this file, need a width of\n640 or 16 pixels with 16 color palette.")
print("Can't handle this file, need a width of\n640 or {} pixels with 16 color palette.".format(sprite_width))