Matching slots mini-game

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
jeffster
Eileen-Class Veteran
Posts: 1014
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Matching slots mini-game

#1 Post by jeffster »

You know the idea: make all slots match, and that would give you something. Here's a little script (that might even teach some novices a couple of useful tricks).
It's not a random reward slot machine, rather a puzzle where you set all slots manually.
The first version of the code here is a simple skeleton, easy to understand. (Just click buttons, switch items).
More advanced code, with animated scrolling through pictures (that trick can be useful in many games!), is attached below in the zip. Unpack it, place the files in a freshly created Ren'Py 8 project (overwrite), then Launch it to play.
matching_slots.gif
matching_slots.gif (607.69 KiB) Viewed 1023 times
Skeleton code (not quite a game yet but testable):

Code: Select all

define items = [
    'book',
    'bug',
    'dice',
    'film',
    'look',
    'pawn',
    'sun',
    'talk',
    'tool',
    'wand',
    ]

default slots = [ None, None, None ]

screen slot_machine(task):
    text f"Get me {task}!"
    frame:
        style_prefix "sm"
        align (.5, .5)
        xysize (432, 432)       # 3*128 + 4*12
        padding (12, 12)
        background "#CDE3"
        vbox:
            frame:
                has hbox
                for col in range(0, 3):
                    imagebutton auto "button/up_%s.webp":
                        action [
                            CycleDict(slots, col, items, reverse=True),
                            renpy.restart_interaction
                            ]
            frame:
                has hbox
                for col in range(0, 3):
                    button:
                        background Transform(Frame("gui/frame.png"), alpha=0.5)
                        add f"item/{slots[col]}.webp" offset (-6, -6)
                        sensitive False
            frame:
                has hbox
                for col in range(0, 3):
                    imagebutton auto "button/down_%s.webp":
                        action [
                            CycleDict(slots, col, items),
                            renpy.restart_interaction
                            ]

    if slots[0] == slots[1] == slots[2]:
        button:
            xpos 1200
            yalign 0.5
            focus_mask None
            background "#CAFA"
            add f"item/{slots[0]}.webp"

            if slots[0] == task:
                hover_background "#AFCA"
                action Return("Well done!")

            else:
                hover_background "#FACA"
                action Return(f"You give me a {slots[0]} instead of "
                            f"the {task}? Thank you soooo much!!!")

style sm_frame:
    padding (0, 0)
    background None

style sm_hbox:
    spacing 12

style sm_vbox:
    spacing 12

style sm_button:
    xysize (128, 128)
    focus_mask True

label start:
    scene black
    "Click to start"

label playSM:
    python:
        task = renpy.random.choice(items)
        slots[0] = renpy.random.choice(items)
        slots[1] = renpy.random.choice(items)
        slots[2] = renpy.random.choice(items)
    call screen slot_machine(task)
    "[_return]"

    menu:
        "Play again?"
        "Yeppah":
            jump playSM
        "Noppah":
            "Bubbye!"
Full blown game with bells and whistles (only the essential files!):
matching_slots_1.0.zip
(66.55 KiB) Downloaded 12 times
If the problem is solved, please edit the original post and add [SOLVED] to the title. 8)

Post Reply

Who is online

Users browsing this forum: No registered users