diff --git a/src/flappyBird/Assets.hh b/src/flappyBird/Assets.hh new file mode 100644 index 0000000..903e2c7 --- /dev/null +++ b/src/flappyBird/Assets.hh @@ -0,0 +1,7 @@ +#ifndef ASSETS_HH +#define ASSETS_HH +#include +namespace assets { + std::vector bird(); +} +#endif diff --git a/src/flappyBird/assets/yellowbird-downflap.png b/src/flappyBird/assets/yellowbird-downflap.png new file mode 100644 index 0000000..e9e1c77 Binary files /dev/null and b/src/flappyBird/assets/yellowbird-downflap.png differ diff --git a/src/flappyBird/generateAssets.py b/src/flappyBird/generateAssets.py new file mode 100644 index 0000000..a67cb8a --- /dev/null +++ b/src/flappyBird/generateAssets.py @@ -0,0 +1,41 @@ +import argparse +from pathlib import Path +from PIL import Image + +parser = argparse.ArgumentParser() +parser.add_argument("function") +parser.add_argument("input") +parser.add_argument("output") + +args = parser.parse_args() + +function = args.function +input = Path(args.input) +output = Path(args.output) + +if not input.exists(): + print("Input " + str(path.absolute()) + " not found.") + raise SystemExit(1) + +hexList = list() + +with Image.open(input) as image: + imageBytes = bytes(image.getdata()) + byteList = list(imageBytes) + + for byte in byteList: + hexList.append(f'0x{byte:02x}') + + +code = f"""#include +#include + +namespace assets {{ +std::vector {function}() {{ + return {{ {','.join(hexList)} }}; +}} +}} +""" + +with open(output, 'w') as f: + f.write(code) diff --git a/src/flappyBird/meson.build b/src/flappyBird/meson.build index bbc3d39..7f71c8e 100644 --- a/src/flappyBird/meson.build +++ b/src/flappyBird/meson.build @@ -5,5 +5,8 @@ flappy_sources = [ 'MainMenu.cc' ] -flappy_bird = static_library('flappyBird', flappy_sources, dependencies: deps, include_directories: incdirs) +python3 = find_program('python3') +bird = custom_target('bird', output: 'birdSprite.cc', input: ['generateAssets.py', 'assets/yellowbird-downflap.png'], command: [python3, '@INPUT0@', 'bird', '@INPUT1@', '@OUTPUT@']) + +flappy_bird = static_library('flappyBird', [flappy_sources, bird], dependencies: deps, include_directories: incdirs) flappy_dep = declare_dependency(link_with: [flappy_bird], include_directories: incdirs)