Simple minigames (Screen Language only).

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.
Message
Author
TrebleTriangle
Newbie
Posts: 6
Joined: Sat Jun 04, 2016 11:37 am
Location: A place with lots of mountains and trees.
Contact:

Re: Simple minigames (Screen Language only).

#46 Post by TrebleTriangle »

Yeah, it did work!
Thank you so much! :D

(Although, OpenGL didn't worked for me. Must have been a problem in OpenGL.)

User avatar
Xerofit51
Veteran
Posts: 376
Joined: Thu Jan 09, 2014 12:58 am
Completed: Freak-quency, Harvest-Moon spin off
Projects: Freak-quency
Deviantart: xerofit51
Location: Indonesia
Contact:

Re: Simple minigames (Screen Language only).

#47 Post by Xerofit51 »

Not sure if this post is still active but is it possible for only partial of the numbers game need to be click to win a game

Example in the numbers game you actually only need to click these number 1, 4, 5 but there are 1,2,3,4,5,6 numbers spread along the board

Is this possible? How? Thanks

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Simple minigames (Screen Language only).

#48 Post by Alex »

Well, in Ren'Py you can make any turn-based game.
As for numbers game, you see all the buttons appears on screen at random positions, so some of them are behind others. That's why in this game player must click numbers one after another in predefined order.
If you need some buttons onscreen and only several of them must be clicked, then you can code the game screen the different way, like place all the buttons in positions where they won't overlap and so on... So, be more specific about what this game is about and how should it looks like.

From your description this game might be the hidden object game - if so check the links
viewtopic.php?f=51&t=13830
viewtopic.php?f=11&t=11948

User avatar
Xerofit51
Veteran
Posts: 376
Joined: Thu Jan 09, 2014 12:58 am
Completed: Freak-quency, Harvest-Moon spin off
Projects: Freak-quency
Deviantart: xerofit51
Location: Indonesia
Contact:

Re: Simple minigames (Screen Language only).

#49 Post by Xerofit51 »

Thanks, however I'm experiencing a weird issue with the memory game, if I use images, I need to click the very top part of the card for the card to be selected, if I click the middle or the bottom area the card isn't selected?

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Simple minigames (Screen Language only).

#50 Post by Alex »

That's strange, 'cause cards are just buttons and should work fine. Theese cards placed inside grid... So check your code (or post it here) if you've made some changes in it.

https://www.renpy.org/doc/html/screens.html#button
https://www.renpy.org/doc/html/screens.html#grid

User avatar
Xerofit51
Veteran
Posts: 376
Joined: Thu Jan 09, 2014 12:58 am
Completed: Freak-quency, Harvest-Moon spin off
Projects: Freak-quency
Deviantart: xerofit51
Location: Indonesia
Contact:

Re: Simple minigames (Screen Language only).

#51 Post by Xerofit51 »

Code: Select all

##### The game screen

    
        

init:
    python:
        def cards_shuffle(x):
            renpy.random.shuffle(x)
            return x

    ##### Images
    image A = im.Scale("fool.jpg", 127, 203)         # different card images
    image B = im.Scale("devil.jpg", 127, 203)
    image C = im.Scale("back.jpg", 127, 203)          # back of the card
screen memo_scr:    
    
    ##### Timer
    timer 1.0 action If (memo_timer > 1, SetVariable("memo_timer", memo_timer - 1), Jump("memo_game_lose") ) repeat True
    
    text str(memo_timer) xalign 0.5 yalign 0.05
    
    
    ##### Cards
    #
    # To use images, just comment out lines that show text and uncomment lines that show images
    grid 3 3:                
            area (0.35,0.15, 600, 720)
            for card in cards_list:
                button:
                    if card["c_chosen"]:        # shows the face of the card
                        #text card["c_value"]    # will show text
                        add card["c_value"]    # will show image
    
                    else:                       # shows the back of the card
                        #text "X"                # will show text
                        add "C"                # will show image
    
                    action If ( (card["c_chosen"] or not can_click), None, [SetDict(cards_list[card["c_number"]], "c_chosen", True), Return(card["c_number"]) ] )
     
    

    
label memoria_game:
    
    #####
    #
    # At first, let's set the cards to play (the amount should match the grid size - in this example 12)
    $ values_list = ["A", "A", "A", "A", "A", "A", "B",  "B", "B"]
    
    # Then - shuffle them
    $ values_list = cards_shuffle(values_list)
    
    # And make the cards_list that describes all the cards
    $ cards_list = []
    python:
        for i in range (0, len(values_list) ):
            cards_list.append ( {"c_number":i, "c_value": values_list[i], "c_chosen":False} )   

    # Before start the game, let's set the timer
    $ memo_timer = 50.0
    
    # Shows the game screen
    show screen memo_scr
    
    # The game loop
    label memo_game_loop:
        $ can_click = True
        $ turned_cards_numbers = []
        $ turned_cards_values = []
        
        # Let's set the amount of cards that should be opened each turn (all of them should match to win)
        $ turns_left = 3
        
        label turns_loop:
            if turns_left > 0:
                $ result = ui.interact()
                $ memo_timer = memo_timer
                $ turned_cards_numbers.append (cards_list[result]["c_number"])
                $ turned_cards_values.append (cards_list[result]["c_value"])
                $ turns_left -= 1
                jump turns_loop
        
        # To prevent further clicking befor chosen cards will be processed
        $ can_click = False
        # If not all the opened cards are matched, will turn them face down after pause
        if turned_cards_values.count(turned_cards_values[0]) != len(turned_cards_values):
            $ renpy.pause (1.0, hard = True)
            python:
                for i in range (0, len(turned_cards_numbers) ):
                    cards_list[turned_cards_numbers[i]]["c_chosen"] = False
        
        # If cards are matched, will check if player has opened all the cards
        else:
            $ renpy.pause (1.0, hard = True)
            python: 
                
                # Let's remove opened cards from game field
                # But if you prefere to let them stay - just comment out next 2 lines
                for i in range (0, len(turned_cards_numbers) ):
                    cards_list[turned_cards_numbers[i]]["c_value"] = Null()
                    
                    
                for j in cards_list:
                    if j["c_chosen"] == False:
                        renpy.jump ("memo_game_loop")
                renpy.jump ("memo_game_win")
                
                

        jump memo_game_loop

I don't feel like I made any major changes, just the game size but even if I don't change the game size the problem persist, I can only click the top of the cards for the game to work

Edit : it seems to have something to do with the new GUI since when I used the legacy one it turned out to work fine. All I had to do was change the gui.button height. Thanks anyway!

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Simple minigames (Screen Language only).

#52 Post by Alex »

Glad you've solved it.

SeeingStars
Newbie
Posts: 5
Joined: Wed Apr 12, 2017 5:16 pm
Contact:

Re: Simple minigames (Screen Language only).

#53 Post by SeeingStars »

Hi Alex,

Apologies for another question on Memoria, but I can't quite wrap my head around creating cards that'll reset the turn after opening (as opposed to waiting for a match). Essentially I'm trying to implement some trap cards. I know the label turns_loop handles the overall interaction, but how would I go about resetting the loop if say, the user opens card "A".

Thanks.

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Simple minigames (Screen Language only).

#54 Post by Alex »

Try something like this

Code: Select all

label memoria_game:
    
    #####
    #
    # At first, let's set the cards to play (the amount should match the grid size - in this example 12)
    $ values_list = ["A", "A", "C", "C", "E", "F", "B",  "B", "D"]
    
    $ trap_cards = ["D", "E", "F"]
    
    # Then - shuffle them
    $ values_list = cards_shuffle(values_list)
    
    # And make the cards_list that describes all the cards
    $ cards_list = []
    python:
        for i in range (0, len(values_list) ):
            cards_list.append ( {"c_number":i, "c_value": values_list[i], "c_chosen":False} )   

    # Before start the game, let's set the timer
    $ memo_timer = 50.0
    
    # Shows the game screen
    show screen memo_scr
    
    # The game loop
    label memo_game_loop:
        $ can_click = True
        $ turned_cards_numbers = []
        $ turned_cards_values = []
        
        # Let's set the amount of cards that should be opened each turn (all of them should match to win)
        $ turns_left = 2
        
        label turns_loop:
            if turns_left > 0:
                $ result = ui.interact()
                $ memo_timer = memo_timer
                $ turned_cards_numbers.append (cards_list[result]["c_number"])
                $ turned_cards_values.append (cards_list[result]["c_value"])
                if cards_list[result]["c_value"] in trap_cards:  #<----- check for trap-cards
                    jump turns_done
                $ turns_left -= 1
                jump turns_loop
        
        label turns_done:
            # To prevent further clicking befor chosen cards will be processed
            $ can_click = False
            # If not all the opened cards are matched or only one trap-card opened, will turn them face down after pause
            if turned_cards_values.count(turned_cards_values[0]) != len(turned_cards_values) or len(turned_cards_values) == 1:
                $ renpy.pause (1.0, hard = True)
                python:
                    for i in range (0, len(turned_cards_numbers) ):
                        cards_list[turned_cards_numbers[i]]["c_chosen"] = False
            
            # If cards are matched, will check if player has opened all the cards
            else:
                $ renpy.pause (1.0, hard = True)
                python: 
                    
                    # Let's remove opened cards from game field
                    # But if you prefere to let them stay - just comment out next 2 lines
                    for i in range (0, len(turned_cards_numbers) ):
                        cards_list[turned_cards_numbers[i]]["c_value"] = Null()
                        
                        
                    for j in cards_list:
                        if j["c_chosen"] == False:
                            renpy.jump ("memo_game_loop")
                    renpy.jump ("memo_game_win")
                    
                    

            jump memo_game_loop

SeeingStars
Newbie
Posts: 5
Joined: Wed Apr 12, 2017 5:16 pm
Contact:

Re: Simple minigames (Screen Language only).

#55 Post by SeeingStars »

Thank you, Alex! cards_list[result]["c_value"] was what I wasn't able to figure out. I need to study more on arrays, so bad with them T.T.

User avatar
Sehaf
Regular
Posts: 58
Joined: Thu Feb 25, 2010 9:22 pm
Projects: Demon Lord & Yuki Academy
Deviantart: Sehad
Location: Sweden
Contact:

Re: Simple minigames (Screen Language only).

#56 Post by Sehaf »

So, made my own little version of this memory game in order to try having a combat code. Half the code is based on my own combat engine that works like any classic JRPG combat code, but I wanted to see if it could be combined with the memoria game to give it some flair. have been reading it over and over, and it looks like it should be working, but instead I get an error message when trying to run it, stating that,;; "Line is intended, but the preceding one line phyton statement does not expect a block." for this line

Code: Select all

            if result == "talk":
                    call talk_monsters
Not sure what I do wrong or If I have missed a simple thing. Pleas help

Code: Select all

##### The game screen
screen memo_combat_scr_UI:    
    
    ##########################################################################################################################
        
    ## Add here combat UI buttons, attack, run and so on for effect, but with other workings.
        
    ##########################################################################################################################
    
    
    ##### Standard comands
    #
    # Different actions you can take other then selecting a card
    
    imagebutton:
        xpos .26 ypos .32
        idle "gui/talk_button_idle.png" # Unchecked idle
        hover "gui/talk_button_hover.png" # Unchecked hover
        action [ Return("talk"), SensitiveIf(brickClicked==False) ]
        focus_mask True
    
    imagebutton:
        xpos .36 ypos .42
        idle "gui/attack_button_idle.png" # Unchecked idle
        hover "gui/attack_button_hover.png" # Unchecked hover
        action [ Return("fight"), SensitiveIf(brickClicked==False) ]
        focus_mask True

    imagebutton:
        xpos .26 ypos .52
        idle "gui/item_button_idle.png" # Unchecked idle
        hover "gui/item_button_hover.png" # Unchecked hover
        action [ Return("items"), SensitiveIf(brickClicked==False) ]
        focus_mask True
        
    imagebutton:
        xpos .36 ypos .62
        idle "gui/flee_button_idle.png" # Unchecked idle
        hover "gui/flee_button_hover.png" # Unchecked hover
        action [ Return("flee"), SensitiveIf(brickClicked==False) ]
        focus_mask True
    
    
    
    ##### Cards
    #
    # To use images, just comment out lines that show text and uncomment lines that show images
    grid 6 6: #Decides Size of gridd and how may cards will be in game, want more??? Add more number
        
        xpos 150
        ypos 140
        # Add here information for gridd here??? like where it's to be rendered and such???
        
        for card in cards_list: #Creates a button for each slot in gridd based on card in cards_list
            button: #Creates button
                background None #Decide no background will be there Can be that wish to have background for locked briks and the like, Or simply have other buttons instead... lets see.

                if card["c_chosen"]:        # shows the face of the card
                    add card["c_value"]    # will show image

                else:                       # shows the back of the card
                    add "brik_Back"          # will show image of back

                action If ( (card["c_chosen"] or not can_click), None, [SetDict(cards_list[card["c_number"]], "c_chosen", True), Return(card["c_number"]) ] )


#### The defining of the cards and deck ####################################################################################################################################################################################################

init:
    python:
        def cards_shuffle(x): #Define card shuffle
            renpy.random.shuffle(x) #Shuffle card nr X
            return x #Then return it??

    ##### Images
    image brik_Sword = "gui/sword.png"         # different card images
    image brik_Combo = "gui/combo.png"         # etc..
    image brik_Hart = "gui/hart.png" 
    image brik_Magic = "gui/magic.png" 
    image brik_Talk = "gui/talk.png" 
    image brik_Shield = "gui/shield.png" 

    image brik_Back = "gui/used.png"          # back of the card

    

########################################################################################################################################################################################################


    
label memoria_battle_engine:
    
    #### START OF BATTLE #########################
    #### SETTING UP ##############################
    
    
    play music "sound/battle_enemy.mp3" #Battle music Have some check thing in case of location/enemy type
    
    $ brickClicked = False
    $ battle_continue = True #Set battle true that battle is ongoing.
    
    #This renders all characters and menus
    show y angry at battle_sprite, flip
    show monster normal
    show screen player_gui
    show screen enemy_gui
    #with dissolve
    
    #Decide turn order for combat
    call attackSequence_locator
    
    #Animated thing to hide doors, initiating combat.
    hide screen battle_transform_l_door 
    hide screen battle_transform_r_door
    
    "You have encountered a %(target_enemie)s" #Stating who you are fighting
    
    #This is turn order, shows who acts and when. This will work differently depending on combat type
    show screen turnOrder
    
    call memoria_create_newdeck
    
    $ turned_cards_numbers = []
    $ turned_cards_values = []
    # Let's set the amount of cards that should be opened each turn (all of them should match to win)
    $ turns_left = 3
    
    while battle_continue==True:
        
        ###### Player turn ######################################################
        while player_turn=="player":
            
            $ can_click = True
        
            call screen memo_combat_scr_UI
            
            $ result = _return
            
                if result == "talk":
                    call talk_monsters

                elif result == "fight":
                    call player_attacks
                    if attack == "return":
                        pass
                    else:
                        call attackSequence_change

                elif result == "items":
                    call player_item
                
                elif result == "flee":
                    "You try to flee" #if you flee, have it check for dexterity, if fast enough you escape
                    if dexterity+renpy.random.randint(1, 20)>= 10:
                        $ player_turn = "Run"
                        $ battle_continue = False
                    else:
                        "The monster blocks your way!"
                        call attackSequence_change
                else:
                    $ brickClicked = True
                    
                    if turns_left > 0:
                        $ result = ui.interact()
                        $ turned_cards_numbers.append (cards_list[result]["c_number"])
                        $ turned_cards_values.append (cards_list[result]["c_value"])
                        $ turns_left -= 1
                            
                        if turns_left == 0:
                            $ brickClicked = False
                            
                        $ can_click = False
                        
                        # If not all the opened cards are matched, will turn them face down after pause
                        if turned_cards_values.count(turned_cards_values[0]) != len(turned_cards_values):
                            $ renpy.pause (1.0, hard = True) #Have changed to transition or animation perhaps?
                            python:
                                for i in range (0, len(turned_cards_numbers) ):
                                cards_list[turned_cards_numbers[i]]["c_chosen"] = False
                                
                                $ turned_cards_numbers = []
                                $ turned_cards_values = []
                                # Let's set the amount of cards that should be opened each turn (all of them should match to win)
                                $ turns_left = 3
                    
                        else:
                            $ renpy.pause (1.0, hard = True)
                            python: 
                
                                # Let's remove opened cards from game field
                                # But if you prefere to let them stay - just comment out next 2 lines
                                for i in range (0, len(turned_cards_numbers) ):
                                    cards_list[turned_cards_numbers[i]]["c_value"] = Null()
                    
                                for j in cards_list:
                                    if j["c_chosen"] == False:
                                        pass
                                    else:
                                        renpy.call ("memoria_create_newdeck")
                    





                    
            #Checks if your actions have killed the monster, if not, then it will either continue your turn or then go to monsters turn if still alive. Also check if you have died during your turn.
            if HP<=0:
                stop music fadeout 2
                hide screen enemy_gui
                $ random_mon_talk = renpy.random.randint(5, 25)
                if myBackpack.gold < random_mon_talk:
                    $ myBackpack.gold = 0
                else:
                    $ myBackpack.gold -= random_mon_talk
                    jump game_over
            
            if monster_HP<=0:
                $ player_turn="victory"
                $ battle_continue = False
            
            
        while player_turn=="monster":
            
            call attackSequence_change
             
            if HP<=0:
                stop music fadeout 2
                hide screen enemy_gui
                $ random_mon_talk = renpy.random.randint(5, 25)
                if myBackpack.gold < random_mon_talk:
                    $ myBackpack.gold = 0
                else:
                    $ myBackpack.gold -= random_mon_talk
                    jump game_over
            
            if monster_HP<=0:
                $ player_turn="victory"
                $ battle_continue = False
            ### Monster does attack, randomize his next attack in que and add it to 
            
            
################################################################################################################################################################################################
    
    # If battle is over, thees things will be checked for type of victory and what is given, checks  combat, verbal, sneek, event or other tings like this.

    "Battle is now over!"
    
    if player_turn == "victory":
        stop music fadeout 2
        play music "sound/victory_tune.mp3"
        "You have vanquished the %(target_enemie)s!"
        "You gain %(monster_experience)d EXP!"
        $ experience += monster_experience
        call level_upp
        #   if level up: $ HP = max_HP,,, add to level_upp label
        
        call loot_table_forest ## Or loot table based on location and enemie
                
    elif player_turn == "diplomatic_victory":
        stop music fadeout 2
        play music "sound/victory_tune.mp3"
        "The %(target_enemie)s retreets!"
        $ diplomatic_xp = monster_experience/2
        $ experience += diplomatic_xp
        "You gain %(diplomatic_xp)d EXP!"
        call level_upp
        #   if level up: $ HP = max_HP,,, add to level_upp label
        
        # call loot_table_forest ## Or loot table based on location and enemie
        
    else:
        stop music fadeout 2
        "You have flead the battle flee the battle!"


    # hide bg forest #Change to dynamic background that can be used in all locations
    hide screen enemy_gui
    scene bg black
    with dissolve
    
    return
    
    
##### To create new deck when needed ##############################################################################################################################################################################################    
    
label memoria_create_newdeck:
    
    ##### SETUP
    #
    # At first, let's set the cards to play, can create if menu for different decks if needed (the amount should match the grid size)
    $ values_list = ["brik_Sword", "brik_Sword", "brik_Sword", "brik_Combo", "brik_Combo", "brik_Combo", "brik_Hart",  "brik_Hart", "brik_Hart", "brik_Magic", "brik_Magic", "brik_Magic", "brik_Talk", "brik_Talk", "brik_Talk", "brik_Shield", "brik_Shield", "brik_Shield", "brik_Sword", "brik_Sword", "brik_Sword", "brik_Combo", "brik_Combo", "brik_Combo", "brik_Hart",  "brik_Hart", "brik_Hart", "brik_Magic", "brik_Magic", "brik_Magic", "brik_Talk", "brik_Talk", "brik_Talk", "brik_Shield", "brik_Shield", "brik_Shield"]
    
    # Then - shuffle them
    $ values_list = cards_shuffle(values_list)
    
    # And make the cards_list that describes all the cards
    $ cards_list = []
    python:
        for i in range (0, len(values_list) ):
            cards_list.append ( {"c_number":i, "c_value": values_list[i], "c_chosen":False} )   
            
    return
    


I'm a GameMaker!
My Portfolio: http://www.bluepipestudio.com

User avatar
Steamgirl
Veteran
Posts: 322
Joined: Sat Jul 28, 2012 4:39 am
Completed: My Cup of Coffee, Queen at Arms (co-wrote a battle scene)
Projects: Stranded Hearts, Emma: A Lady's Maid
Deviantart: steamgirlgame
Contact:

Re: Simple minigames (Screen Language only).

#57 Post by Steamgirl »

I am not 100% sure, but isn't python/renpy tab-sensitive?

Remove one tab and see if this fixes it?

Code: Select all

            if result == "talk":
                call talk_monsters
                
You could also double check that you're not accidentally mixing tabs and spaces. I don't know if it's changed over the years but I'm pretty sure Ren'py only accepts spaces as valid, so if your editor isn't set up to do 4 spaces instead of a tab, it can lead to errors.

Sorry if I'm saying really obvious things that you've already tried btw!! Just trying to help. ^_^

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Simple minigames (Screen Language only).

#58 Post by Alex »

Code: Select all

while player_turn=="player":
            
            $ can_click = True
        
            call screen memo_combat_scr_UI
            
            $ result = _return
            
                if result == "talk":
                    call talk_monsters
"if result == "talk":" shouldn't be extra indented, so move it and all the following elifs 4 spaces left.

User avatar
Sehaf
Regular
Posts: 58
Joined: Thu Feb 25, 2010 9:22 pm
Projects: Demon Lord & Yuki Academy
Deviantart: Sehad
Location: Sweden
Contact:

Re: Simple minigames (Screen Language only).

#59 Post by Sehaf »

EDIT***
Scratch that, found the issues. Forgot to assign who went first and confused the poor thing. Still, awesome code.




Thanks both of you, did help and solved that issue. It did however start to complaint that there is risk of infinite loop. Not sure how I will brake that however, but I assume I will manage. (though suggestions again would be grate help! ^_^)
I'm a GameMaker!
My Portfolio: http://www.bluepipestudio.com

ssxsilver
Newbie
Posts: 1
Joined: Wed Jun 13, 2018 2:16 pm
Contact:

Re: Simple minigames (Screen Language only).

#60 Post by ssxsilver »

Hi Alex!

I'm trying to learn through your code, but I'm a little lost on the timer part. It seems sorta portable (just renaming labels), but I can't seem to get it working with this puzzle code: viewtopic.php?f=51&t=16151#p267460

Post Reply

Who is online

Users browsing this forum: No registered users