pimoroni-pico icon indicating copy to clipboard operation
pimoroni-pico copied to clipboard

Added an example of a memory game.

Open waterphox opened this issue 3 years ago • 4 comments

This is the second game I made for the badger2040. It's a simple Simon-style memory game where you must memorize the order that shapes appear on the screen. When the game says GO!, just press the corresponding buttons to eliminate the shapes! It demonstrates use of partial display updates using partial_update and is an example of when a turbo-level update speed works well.

waterphox avatar Mar 22 '22 21:03 waterphox

Awesome. Thank you. On my TODO list to give this a try!

If you'd like this to be a builtin example, the "eliminationsquares.bin" should be added to git as the source image, and CMake will take care of building it if you add a line like the following: https://github.com/pimoroni/pimoroni-pico/blob/fa2774b1147257e537e91c29f4ee270459d2b2e4/micropython/examples/badger2040/micropython-builtins.cmake#L38

Source image should probably be included either way! And you should use the existing "assets" directory: https://github.com/pimoroni/pimoroni-pico/tree/main/micropython/examples/badger2040/assets

Gadgetoid avatar Mar 24 '22 19:03 Gadgetoid

I hope you enjoy it! I made the suggested changes to have this included as a built-in example. I have a launcher icon for it but I don't know the best way to share that. At this point I have so many new things on my badge, I modified the launcher to have folders and my launchericons file has quite a few new ones in it..!

waterphox avatar Mar 24 '22 19:03 waterphox

Intrigued to know how you managed folders! But I think I have a pretty good idea how they could work, based on our new stateful apps approach.

Let me get https://github.com/pimoroni/pimoroni-pico/pull/313 merged, and a new release sorted, and we can start to improve things from there!

App icons are a tricky business, we might have to make it easy to just store individual image files alongside the app, use a default icon, or something else.

Gadgetoid avatar Mar 25 '22 15:03 Gadgetoid

Folders are kinda hackey. Basically just some folder names, and bumping out the examples list in to sub-lists.

currentMenu = 0
previousMenu = 0
menuTitle = ("MiniGLaDOS v2", "Folders", "Crud", "Utilities", "Games")

selections = [
    #Main Menu
    [
        ("_badge", 5),
        ("_image", 3),
        ("_fursona", 8),
        ("_list", 4),
        ("_ebook", 2),
        ("_folders", 9)
    ],
    #Folders Menu
    [
        ("_back", 10),
        ("_games", 9),
        ("_utilities", 9),
        ("_crud", 9)
    ],
    #Crud Menu
    [
        ("_back", 10),
        ("_info", 6),....ETC

And then making the example launching function check for folder names

def launch_example(index):
    global currentMenu, previousMenu, page
    try:
        pick = selections[currentMenu][(page * 3) + index][0]
        if pick == "_folders":
            currentMenu = 1
            page = 0
            render()
        elif pick == "_crud":
......
elif pick == "_back":
            currentMenu = previousMenu
            previousMenu = previousMenu - 1
            page = 0
            if previousMenu < 0:
                previousMenu = 0
            render()
        else: #They picked something other than a folder or back option
            launch(pick)
        return True
    except IndexError: #Typically triggers if you press a button under a blank spot (no icon/app there)
        return False

And a new value that just says how many icons are in launchericons so I can add them quickly without doing math.

try:
    icons = bytearray(open("launchericons.bin").read())
    iconcount = 14
except (OSError, ImportError):
    import launchericons
    icons = bytearray(launchericons.data())
    iconcount = 8
    pass

Let me know after the release if there's anything else I need to do for this game! Since it's a pretty interactive thing I don't think it needs to use the new appstates.txt or go to sleep at any point.

waterphox avatar Mar 25 '22 17:03 waterphox

Badger has a new home over at https://github.com/pimoroni/badger2040 and this could make a cool default example if we port it!

Gadgetoid avatar Mar 09 '23 20:03 Gadgetoid