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.
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!"