Simon minigame [updated for renpy 6.9+]

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
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Simon minigame [updated for renpy 6.9+]

#1 Post by gas »

SIMON MINIGAME
==============

#### REVISED CODE NOW WORKING WITH RENPY 6.9 and further ####
V 0.1.1 Tested against renpy 6.99.14.3

This is a Simon minigame.

The game show you a sequence that grow larger each step.
It's up to you to repeat the whole sequence by clicking buttons.
You lose if you press the wrong button or time expire.
You win by completing the whole sequence (10 signs in the sequence by default).

How to use it
Past simon code where you want. Then use in your game script:

Code: Select all

    call simon pass (complete=10, toadd=2)
Where 'complete' is the total number of signs to guess, and 'toadd' the number of signs added to the sequence each turn.
'Complete' MUST BE a multiple of 'toadd'.

The game require 5 images to work, and 4 sound effects. I'll give you some graphical proxy just below, but I don't own any proper sound.
In game, the sound effects are called (silly) bip, bop, bep, bup .ogg.

Code: Select all

### SIMON MINIGAME II 0.1.1
# Made by: GAS
# Found on LemmaSoft Forum
# Free to use at will
    
label simon(complete=10, toadd=2):
    $ sequence=[]
    $ yourguess=0
label simonturn:
    # add signs to the sequence, enlarging it each turn.
    $ seqiter=0
    python:
        for i in range(toadd):
            roll=renpy.random.randint(0,3)
            sequence.append(roll)
label simonshow:
    $ i=0
    while i<len(sequence):
        $ thesign=sequence[i]
        # display the actual sequence, sign by sign
        # .. neutral screen (all greyed out)
        show screen simonvoid
        $ renpy.pause(0.5, hard=True)
        hide screen simonvoid
        # ... a button is lighted on!
        show screen simondisplay
        # ... so, play the relative sound
        if thesign==0:
            play sound "bip.ogg"
        if thesign==1:
            play sound "bop.ogg"
        if thesign==2:
            play sound "bep.ogg"
        if thesign==3:
            play sound "bup.ogg"
        $ renpy.pause(0.5, hard=True)
        hide screen simondisplay
        $ i+=1
    $ i=0 # Yeah, the very cornerstone of the game is that line!!
label simonguess:
    $ thesign=sequence[i]
    call screen simoncheck
    $ dasign=_return
    if dasign=="bust":
        "Too slow!"
        return
    elif dasign!=thesign:
        "Oh no! You missed it!"
        return
    if dasign==thesign:
        $ i+=1
        if i==len(sequence):
            jump simonend
    jump simonguess
label simonend:
    if len(sequence)==complete:
        "You won!"
        return
    jump simonturn
    
screen simondisplay():
    text "SIMON SAYS..." xalign 0.5 yalign 0.2
    grid 2 2:
        xalign 0.5
        yalign 0.5
        spacing 5
        if thesign==0:
            add "red.png"
        else:
            add "grey.png"
        
        if thesign==1:
            add "green.png"
        else:
            add "grey.png"
        
        if thesign==2:
            add "blue.png"
        else:
            add "grey.png"
        
        if thesign==3:
            add "yellow.png"
        else:
            add "grey.png"
screen simonvoid():
    text "SIMON SAYS..." xalign 0.5 yalign 0.2
    grid 2 2:
        xalign 0.5
        yalign 0.5
        spacing 5
        for i in range(4):
            add "grey.png"
screen simoncheck():
    timer 3.0 action Return("bust")
    bar value AnimatedValue(value=0, range=3, old_value=3, delay=3.0) xalign 0.5 xsize 500
    text "!! REPEAT !!" xalign 0.5 yalign 0.2
    grid 2 2:
        xalign 0.5
        yalign 0.5
        spacing 5
        imagebutton idle "grey.png" hover "red.png" action Return(0) activate_sound "bip.ogg"
        imagebutton idle "grey.png" hover "green.png" action Return(1) activate_sound "bop.ogg"
        imagebutton idle "grey.png" hover "blue.png" action Return(2) activate_sound "bep.ogg"
        imagebutton idle "grey.png" hover "yellow.png" action Return(3) activate_sound "bup.ogg"

Attachments
blue.png
blue.png (4.29 KiB) Viewed 4971 times
green.png
green.png (3.76 KiB) Viewed 4971 times
grey.png
grey.png (2.74 KiB) Viewed 4971 times
red.png
red.png (4.62 KiB) Viewed 4971 times
yellow.png
yellow.png (3.65 KiB) Viewed 4971 times
Last edited by gas on Wed May 02, 2018 2:21 pm, edited 1 time in total.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

Alte
The Great Organizer
Posts: 411
Joined: Fri Apr 18, 2014 5:26 pm
Github: nualte
itch: alte
Contact:

Re: Simon minigame

#2 Post by Alte »

Is it possible to add certain sounds on buttons? The sound wav files are in the attachment.
E-note = blue | C♯-note = yellow | A-note = red | E-note (alternative) = green
Attachments
SimonSounds.zip
(108.21 KiB) Downloaded 217 times
Ren'Py Cookbook Directory

I'm not affiliated with Ren'Py/ itch.io/ Steam/ etc.

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Simon minigame

#3 Post by gas »

Alte wrote:Is it possible to add certain sounds on buttons? The sound wav files are in the attachment.
E-note = blue | C♯-note = yellow | A-note = red | E-note (alternative) = green
And that's your refined code with sounds!

Code: Select all

label simongame (difficulty=0, endgame=0,goquick=0):
    #this is a coding of old SIMON sequence game.
    #At first, determine some variable and reset counters.
    $ sequence=[] #the sequence to reply.
    $ nowpush=0 #the sequence iterator
    $ thecolor=0#the button you have to push.
    
label turnsequence: #now, call the randomizer to add signs.
    python:
        for i in range (0,difficulty):
            added=renpy.random.randint(0,3)
            sequence.append(added)
    $nowpush=0
    
label showthesequence: #now, show the screen that display the sequence
    if nowpush==len(sequence):
        jump theguessin #jump away if the sequence is complete
    show screen voidgame
    $ renpy.pause(0.5,hard=True)
    show screen displaysequence
    if sequence[nowpush]==0:
        $ renpy.play("a-note-red.wav")
    if sequence[nowpush]==1:
        $ renpy.play("e-note-blue.wav")
    if sequence[nowpush]==2:
        $ renpy.play("e-alt-green.wav")
    if sequence[nowpush]==3:
        $ renpy.play("c-sharp-note-yellow.wav")
    hide screen voidgame
    $ renpy.pause(0.5,hard=True)
    if nowpush< len(sequence):
        $ nowpush+=1
    jump showthesequence

label theguessin: #this label prepare the screen, hiding what's left from previous
    $ nowpush=0
    hide screen displaysequence
    #Now, call the screen for player input
    $ nowpush=0
label guessthesequence:  #now have the player input commands to repeat the sequence
    if nowpush==len(sequence):
        show screen voidgame
        $ renpy.pause(0.5,hard=True)
        jump turnsequence #if complete, redo from start
    call screen inputcolor
    $ myguess=_return #that's the button you pressed
    $ theright =sequence[nowpush] #that's the correct button to push at the moment
    if theright==myguess:
        $nowpush+=1
        if nowpush==(endgame):
            jump winner
        jump guessthesequence
    if theright!=myguess:
        jump looser
label winner: #a messagge to define victory
    "You win!"
    return
label looser: #a message
    "You loose!"
    return

    
screen displaysequence:
    grid 2 2:
        xalign 0.5
        yalign 0.5
        spacing 5
        if sequence[nowpush]==0:
            add "redon.png"
        else:
            add "buttonoff.png"
        if sequence[nowpush]==1:
            add "blueon.png"
        else:
            add "buttonoff.png"
        if sequence[nowpush]==2:
            add "greenon.png"
        else:
            add "buttonoff.png"
        if sequence[nowpush]==3:
            add "yellowon.png"
        else:
            add "buttonoff.png"
screen voidgame:
    grid 2 2:
        xalign 0.5
        yalign 0.5
        spacing 5
        add "buttonoff.png"
        add "buttonoff.png"
        add "buttonoff.png"
        add "buttonoff.png"
    
screen inputcolor:
    use racetheclock(goquick)
    text "Your turn" xalign 0.5 yalign 0.9
    grid 2 2:
        xalign 0.5
        yalign 0.5
        spacing 5
        imagebutton idle "buttonoff.png" hover "redon.png" action (Play("sound","a-note-red.wav"),Return(0))
        imagebutton idle "buttonoff.png" hover "blueon.png" action (Play("sound","e-note-blue.wav"),Return(1))
        imagebutton idle "buttonoff.png" hover "greenon.png" action (Play("sound","e-alt-green.wav"),Return(2))
        imagebutton idle "buttonoff.png" hover "yellowon.png" action (Play("sound","c-sharp-note-yellow.wav"),Return(3))

screen racetheclock(goquick):
    $ mytime=AnimatedValue(value=10.0, range=10.0, delay=goquick, old_value=0.0)
    bar value mytime xalign 0.5 yalign 0.1 xsize 500
    timer goquick action Jump("too_slow")
    
label too_slow:
    "Out of time!"
    return
    
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

Alte
The Great Organizer
Posts: 411
Joined: Fri Apr 18, 2014 5:26 pm
Github: nualte
itch: alte
Contact:

Re: Simon minigame

#4 Post by Alte »

gas wrote:And that's your refined code with sounds!
Neat! Thanks gas.

Few more suggestions, if possible.
- 3 seconds countdown before Simon starts
- Sequence: #, on the top left corner
- Best: #, on the top right corner
Ren'Py Cookbook Directory

I'm not affiliated with Ren'Py/ itch.io/ Steam/ etc.

User avatar
effenelle
Regular
Posts: 39
Joined: Thu Nov 29, 2012 12:41 pm
Projects: Un:Wanted [GxB]
Deviantart: effenelle
Location: inside imagination
Contact:

Re: Simon minigame

#5 Post by effenelle »

Nice! Thank you for this! I've always like SIMON game. Will find the opportunity to use this :)
Un:Wanted (GxB)
A game made from free resources found in LemmaSoft's Creative Commons!
\(^▽^)/
Thanks everyone!

Gushi
Newbie
Posts: 24
Joined: Sun Apr 01, 2018 3:25 pm
Projects: Project 4th Wall
itch: https://umberbridge.
Contact:

Re: Simon minigame

#6 Post by Gushi »

Hey first of all, thank you for the code. I've been needing a mini game like this. However when I was using it I encountered a minor traceback error before the game goes back to the main menu,

Code: Select all

While running game code:
  File "game/script.rpy", line 71, in script
    label turnsequence: #now, call the randomizer to add signs.
Exception: Possible infinite loop.
This was from a completely blank game and the code wasn't edited in any way so I simply played the game how it was so I think it's a bug that needs to be fixed.

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Simon minigame

#7 Post by gas »

Sorry if actually don't work as intended, it's a bit old. I'll revise it this week along a lot of other minigames and codes
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

nautilus_nc
Newbie
Posts: 17
Joined: Wed Jan 16, 2019 11:59 pm
Contact:

Re: Simon minigame [updated for renpy 6.9+]

#8 Post by nautilus_nc »

work on the actual version of renpy ?

User avatar
Trafagal
Regular
Posts: 100
Joined: Mon Apr 29, 2019 9:32 am
Contact:

Re: Simon minigame [updated for renpy 6.9+]

#9 Post by Trafagal »

Hi Gas,

Just came here to say thank you!

I tried this game on the latest renpy(Ren'py 7.4.8.1895) and it worked.
simon.JPG
Check out some of my stuffs here:https://linktr.ee/theartofjoshlab

Art Portfolio: https://www.instagram.com/theartofjoshlab/

Working on a personal Visual Novel~

Post Reply

Who is online

Users browsing this forum: Google [Bot]