Page 1 of 1

Simon minigame [updated for renpy 6.9+]

Posted: Mon Sep 12, 2016 6:33 pm
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"


Re: Simon minigame

Posted: Sat Sep 17, 2016 11:03 pm
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

Re: Simon minigame

Posted: Mon Sep 19, 2016 1:35 pm
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
    

Re: Simon minigame

Posted: Mon Sep 19, 2016 8:17 pm
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

Re: Simon minigame

Posted: Sat Mar 25, 2017 12:56 pm
by effenelle
Nice! Thank you for this! I've always like SIMON game. Will find the opportunity to use this :)

Re: Simon minigame

Posted: Thu Apr 05, 2018 3:12 pm
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.

Re: Simon minigame

Posted: Sat Apr 07, 2018 2:35 pm
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

Re: Simon minigame [updated for renpy 6.9+]

Posted: Fri Jan 18, 2019 3:41 pm
by nautilus_nc
work on the actual version of renpy ?

Re: Simon minigame [updated for renpy 6.9+]

Posted: Sun Sep 05, 2021 10:04 am
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