Repository navigation
Two games for the joystick and the mouse, and png_to_bitmap.py - #11
Merged
Merged
Conversation
Converts a PNG saved with a palette of at most 16 colours into a C header for fb_blit() / fb_blit_key(): one FB_BITMAP, or with --tile an array of them cut from a sheet (tiles, animation frames), the palette as ST colour words for palette_set(), and the fully transparent entry as NAME_KEY. A pixel's palette index is its colour, so an app's images share the palette it sets. Plain Python: it reads indexed PNGs itself (zlib, every filter, 1 to 8 bits per pixel) and refuses what the ST cannot show (a truecolour image, a colour past 15, more than one transparent entry, half transparency). The host test writes PNGs with every filter and depth, checks the palette and the key, and compiles the headers with fb_blit.h to read every pixel back through FB_BITMAP.
Two small games on the public APIs only, the reference for starting a game. Arena: steer with joystick 1 or the cursor keys, fire shoots the way you last moved; grab gems, shoot enemies, three lives. Zap: enemies and gems wander the arena, the left button zaps an enemy under the crosshair and the right one takes a gem, sixty seconds a round; the HUD lights L and R while the buttons are held. They share game_kit.c: an arena of 16x16 tiles under a HUD line, sprites drawn over it and restored under the next frame (a few tile blits per sprite, not the whole arena), labels, and a tune and sound effects computed as they play, as 8-bit PCM on both outputs. The art is indexed PNGs in rp/src/assets on one palette, converted by png_to_bitmap.py. Debug builds of Arena take keys that vary the scene (enemy count and size, freeze, full redraws). They are entries 6 and 7 of the demo menu (demo_games.c): ESC goes back to the menu, which gets its keyboard mode and its music back. The menu's music moves from emul.c into the dispatcher (demo_menu_music()) for that, and the menu panel is centred. examples/mini_game builds a firmware that boots straight into Arena (Zap with three calls changed); hello_text's apply.sh also removes the new demo_games.c.
README "Starting a game" and the example's README walk through what a game needs: an input mode, keys held down, the joystick's and the mouse's press latches, drawing only what moved, art from indexed PNGs, and sound computed as it plays. CLAUDE.md, the skill, the dev tools README (menu entries 6 and 7, Arena's knobs from swd.py key) and the changelog follow.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two small games written against the public APIs only (
fb_*,font_*,palette_*,ikbd_*,audio_*), as the reference for starting a game:rp/src/game_arena.c), the joystick game. Steer with joystick 1 or the cursor keys; fire (or space) shoots the way you last moved. Grab gems, shoot enemies, stay away from them: three lives.rp/src/game_zap.c), the mouse game. Enemies and gems wander the arena. The left button zaps an enemy under the crosshair, the right one takes a gem, and the wrong button costs points. Sixty seconds a round. The HUD lights L and R while the buttons are held, so it doubles as a button test.Around them:
demo_games.c). ESC goes back to the menu, which gets its keyboard mode and its music back: the music moves fromemul.cintodemo_menu_music(). The menu panel is now centred.game_kit.c:rp/src/assetson one palette, turned intorp/src/include/art_*.hbyconvert.sh.examples/mini_game: builds a firmware that boots straight into Arena (apply.sh, ashello_text). Swapping three calls runs Zap instead.tools/png_to_bitmap.py: turns an indexed PNG (at most 16 colours, one of them transparent) intoFB_BITMAPs forfb_blit()/fb_blit_key(). It outputs a whole image or a sheet cut into tiles, with the palette as ST words forpalette_set(). It's plain Python with no extra packages.tools/dev/swd.py key.Tests
make -C tests/host testruns a newtest_png_to_bitmap.py. It covers:fb_blit.hand give back every pixel.apply.shin a clean copy) both build without warnings in debug and release.