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
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).

#16 Post by Xerofit51 »

I have this weird issue where it works find as text but always fails using pictures(one pair is missing, game can't be completed) How to fix this?

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

Re: Simple minigames (Screen Language only).

#17 Post by Alex »

Hmm, did you get an error, like "grid not full"?
The "cards" are set by

Code: Select all

$ values_list = ["A", "A", "A", "A", "A", "A", "B",  "B", "B", "B", "B", "B"]
so you should add the correct number of cards of each type.
Anyway, you could pm me or post here your code to check it.

User avatar
Kate
Regular
Posts: 197
Joined: Thu Sep 19, 2013 6:10 pm
Projects: Blackout
Organization: Moonlight Otome
Location: United States
Contact:

Re: Simple minigames (Screen Language only).

#18 Post by Kate »

I have a question regarding Memoria.

I've copied the code exactly and pasted it into a separate game file to play with it.

It shows the cards being listed like this:

Code: Select all

 
    # 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", "B", "B", "B"]
    
In what order do I need to put words to make them match? I put my words in like this (testing "mystery" words before I try images for my mystery game):

Code: Select all

    # At first, let's set the cards to play (the amount should match the grid size - in this example 12)
    $ values_list = ["Murder", "Run", "Missing", "Help", "Clue", "Suspect", "Murder",  "Run", "Missing", "Help", "Clue", "Suspect"]
    
but when I play, if I pick the two cards that say "Murder", it won't say they've matched. So, how do I set the pairs up with text? And does it work the same way for pictures?
Current Project:
Blackout [VN][Romance][GxB][Mystery][Suspense] http://lemmasoft.renai.us/forums/viewto ... 43&t=34118
"It is the duty of authors to make the fantastic seem ordinary and the ordinary seem fantastic." - K. Auer

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

Re: Simple minigames (Screen Language only).

#19 Post by Alex »

If you've copy/pasted the code as it is, then you need to open 3 words of a kind to match

Code: Select all

        # Let's set the amount of cards that should be opened each turn (all of them should match to win)
        $ turns_left = 3
Change the value of "turns_left" variable to 2 if you want player to find pairs of words.

User avatar
AsHLeX
Miko-Class Veteran
Posts: 556
Joined: Wed Dec 25, 2013 1:09 pm
Completed: Starlight Dreamers, Mysterious Melody, Town of Memories, Marked, To Fly, The Change, Him From The Past, A Forgotten Memory
Projects: Cafe Mysteria
Location: Malaysia
Contact:

Re: Simple minigames (Screen Language only).

#20 Post by AsHLeX »

So... I have a sort of weird question. How do I change the color of the text for the timer? ^^" Thanks!

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

Re: Simple minigames (Screen Language only).

#21 Post by Alex »

Why don't you try

Code: Select all

text "[game_timer]" size 25 color "#c00" xpos 10 ypos 10

User avatar
Naustix
Regular
Posts: 46
Joined: Mon Dec 24, 2012 8:46 pm
Completed: ACE Academy
Projects: Entangled States, GalaCollider
Organization: Studio Lockheart
Github: naustix
Location: Omaha, NE
Contact:

Re: Simple minigames (Screen Language only).

#22 Post by Naustix »

Alex, quick question for the "Numbers" minigame:

Right now, it defaults to displaying everything to the top-left corner- what would I do if I wanted to change the position to the center of the screen? Or even the various parts, like the timer itself?

Thank you for posting these, they've been a pleasure to play with.
Lead Programmer from ACE Academy
Project Lead & Engineer for Entangled States / Founder at Studio Lockheart

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

Re: Simple minigames (Screen Language only).

#23 Post by Alex »

Make some changes in code to adjust the positions of elements.

Code: Select all

text "[game_timer]" size 25 xpos 10 ypos 10
the timer.

You can set the spreading area for the buttons

Code: Select all

numbers_buttons.append ( {"b_number":i, "b_value":buttons_values[i], "b_x_pos":(renpy.random.randint (10, 70))*10, "b_y_pos":(renpy.random.randint (15, 50))*10, "b_to_show":True} )
this sets the position of each button in range 100-700 by x-axis and 150-500 by y-axis, so change it to

Code: Select all

numbers_buttons.append ( {"b_number":i, "b_value":buttons_values[i], "b_x_pos":(renpy.random.randint (25, 40))*10, "b_y_pos":(renpy.random.randint (15, 30))*10, "b_to_show":True} )

User avatar
Naustix
Regular
Posts: 46
Joined: Mon Dec 24, 2012 8:46 pm
Completed: ACE Academy
Projects: Entangled States, GalaCollider
Organization: Studio Lockheart
Github: naustix
Location: Omaha, NE
Contact:

Re: Simple minigames (Screen Language only).

#24 Post by Naustix »

Alex wrote:Make some changes in code to adjust the positions of elements.

Code: Select all

text "[game_timer]" size 25 xpos 10 ypos 10
the timer.

You can set the spreading area for the buttons

Code: Select all

numbers_buttons.append ( {"b_number":i, "b_value":buttons_values[i], "b_x_pos":(renpy.random.randint (10, 70))*10, "b_y_pos":(renpy.random.randint (15, 50))*10, "b_to_show":True} )
this sets the position of each button in range 100-700 by x-axis and 150-500 by y-axis, so change it to

Code: Select all

numbers_buttons.append ( {"b_number":i, "b_value":buttons_values[i], "b_x_pos":(renpy.random.randint (25, 40))*10, "b_y_pos":(renpy.random.randint (15, 30))*10, "b_to_show":True} )
Thank you for your quick reply, Alex.
The code you suggested to change did centralize the spawn locations of the numbers, but wasn't quite what I was looking for:
http://puu.sh/jcU13/cb0c7b7497.jpg

But I took your hint and changed them to give a more even spread across the screen, which is what I was looking for (1920 x 1080 resolution in this case)
http://puu.sh/jcUyQ/fe0396b37d.jpg

In addition to this, how can I center the top bar containing the number sequence?
Lead Programmer from ACE Academy
Project Lead & Engineer for Entangled States / Founder at Studio Lockheart

User avatar
AsHLeX
Miko-Class Veteran
Posts: 556
Joined: Wed Dec 25, 2013 1:09 pm
Completed: Starlight Dreamers, Mysterious Melody, Town of Memories, Marked, To Fly, The Change, Him From The Past, A Forgotten Memory
Projects: Cafe Mysteria
Location: Malaysia
Contact:

Re: Simple minigames (Screen Language only).

#25 Post by AsHLeX »

Thanks, Alex! Got it! :D

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

Re: Simple minigames (Screen Language only).

#26 Post by Alex »

Well, yes the original code was made for game resolution 800x600.
The position of the hints is set by the area property

Code: Select all

# It might be usefull to show the order of buttons to click if it's not obvious.
    side "c b":
        area (150, 05, 640, 70)         # The size of hint's area
so just tweak the numbers.

http://www.renpy.org/doc/html/style_pro ... perty-area

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

Re: Simple minigames (Screen Language only).

#27 Post by Alex »

Simple battle game.

Code: Select all

define r = Character('Red Hood', color="#CD0000")
define w = Character('mr.Wolf', color="#B5B5B5")

screen simple_stats_screen:
    frame:
        xalign 0.01 yalign 0.05
        xminimum 220 xmaximum 220
        vbox:
            text "Red Hood" size 22 xalign 0.5
            null height 5
            hbox:
                bar:
                    xmaximum 130
                    value red_hood_hp
                    range red_hood_max_hp
                    left_gutter 0
                    right_gutter 0
                    thumb None
                    thumb_shadow None
                    
                null width 5
                
                text "[red_hood_hp] / [red_hood_max_hp]" size 16
                
                
    frame:
        xalign 0.99 yalign 0.05
        xminimum 220 xmaximum 220
        vbox:
            text "mr.Wolf" size 22 xalign 0.5
            null height 5
            hbox:
                bar:
                    xmaximum 130
                    value wolf_hp
                    range wolf_max_hp
                    left_gutter 0
                    right_gutter 0
                    thumb None
                    thumb_shadow None
                    
                null width 5
                
                text "[wolf_hp] / [wolf_max_hp]" size 16
                
    text "Red Hood vs. mr.Wolf" xalign 0.5 yalign 0.05 size 30
                
# The game starts here.
label battle_game_1:
    #### Some variables that describes the game state.
    $ wolf_max_hp = 30
    $ red_hood_max_hp = 50
    $ wolf_hp = wolf_max_hp
    $ red_hood_hp = red_hood_max_hp
    $ cookies_left = 13
    
    scene black
    
    "Once upon a time there lived in a certain village a little country girl, the prettiest creature who was ever seen."
    "Her mother was excessively fond of her; and her grandmother doted on her still more."
    "This good woman had a little red riding hood made for her. It suited the girl so extremely well that everybody called her Little Red Riding Hood."
    "One day her mother, having made some cookies, said to her, \"Go, my dear, and see how your grandmother is doing, for I hear she has been very ill. Take her some cookies, and this little pot of butter."
    "Little Red Riding Hood set out immediately to go to her grandmother, who lived in another village."
    "As she was going through the wood, she met with a wolf, who had a very great mind to eat her up, but {w}suddenly..."
    jump battle_1_loop


label battle_1_loop:
    
    #### Let's show the game screen.
    #
    show screen simple_stats_screen
    
    #### The game loop.
    # It will exist till both enemies have more than 0 hp.
    #
    while (wolf_hp > 0) and (red_hood_hp > 0):
        
        menu:
            "Atack!":
                $ wolf_hp -= 2
                r "K-y-aaa!!!11 (damage dealt - 2hp)"
                
            "Eat cookie (got [cookies_left] cookies left)" if cookies_left > 0:
                $ red_hood_hp = min(red_hood_hp+5, red_hood_max_hp)
                $ cookies_left -= 1
                r "Mmm, tasty... (restore 5hp)"
        
        $ wolf_damage = renpy.random.randint(1, 6)
        
        $ red_hood_hp -= wolf_damage
        
        w "RrrrrRRrrrr! {i}*wolf bites you*{/i} (damage dealt - [wolf_damage]hp)"
    #
    ####        
        
    hide screen simple_stats_screen
    
    if wolf_hp <= 0:
        if red_hood_hp <= 0:
            "Double KO"
            
        else:
            r "I wiiiin!!!!!111"
            r "Finally, mom sew me a grey hood."
            "(grandmother got [cookies_left] cookies)"
            
    else:
        w "Om-nom-nom-nom {i}*wolf ate you all up*{/i} (along with the basket, of course...)"
    
    jump battle_1_ending
        
label battle_1_ending:
    "The end."
    return

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

Re: Simple minigames (Screen Language only).

#28 Post by Alex »

Group battle game.

Code: Select all

define battle_narrator = Character(None, interact=False)

screen battle_screen:
    vbox:
        xalign 0.01 yalign 0.05
        spacing 5
        
        for each_party_member in party_list:
            frame:
                size_group "party"
                xminimum 250 xmaximum 250
                yminimum 75
                vbox:
                    text "[each_party_member[name]]" size 22 xalign 0.5
                    null height 5
                    hbox:
                        bar:
                            xmaximum 130
                            value each_party_member["current_hp"]
                            range each_party_member["max_hp"]
                            left_gutter 0
                            right_gutter 0
                            thumb None
                            thumb_shadow None
                            
                        null width 5
                        
                        text "[each_party_member[current_hp]] / [each_party_member[max_hp]]" size 16
        hbox:
            frame:
                size_group "party"
                yminimum 40
                text "Potions left - [potions_left]" yalign 0.5
            if players_turn and potions_left > 0:
                textbutton "<- Use" action Return("heal") yminimum 40
            else:
                textbutton "<- Use" action None yminimum 40
                        
                        
    vbox:
        xalign 0.99 yalign 0.05
        spacing 5
        
        if enemies_list != []:
            for i, each_enemy_member in enumerate(enemies_list):
                hbox:
                    if players_turn and each_enemy_member["current_hp"] > 0:
                        textbutton "Attack ->" action Return(i) yminimum 75
                    else:
                        textbutton "Attack ->" action None yminimum 75
                    
                    frame:
                        size_group "enemies"
                        xminimum 250 xmaximum 250
                        yminimum 75
                        vbox:
                            text "[each_enemy_member[name]]" size 22 xalign 0.5
                            null height 5
                            hbox:
                                bar:
                                    xmaximum 130
                                    value each_enemy_member["current_hp"]
                                    range each_enemy_member["max_hp"]
                                    left_gutter 0
                                    right_gutter 0
                                    thumb None
                                    thumb_shadow None
                                    
                                null width 5
                                
                                text "[each_enemy_member[current_hp]] / [each_enemy_member[max_hp]]" size 16
            
            

init python:
    def check_party(x):
        #### This function will check
        # if at least one of X party members is alive.
        #        
        for member in x:
            if member["current_hp"] > 0:
                return "ok"
                
        return "lost"



label battle_game_2:
    #### Some variables that describes the game state.
    #
    # The "party_list" is a list of all allies each one of that
    # is described by a dictionary.
    #
    $ party_list =[{"name":"Me", "max_hp":50, "current_hp":50, "min_damage":3, "max_damage":5}]
    $ potions_left = 10
    $ players_turn = False
    
    #### Enemies list will have the description for enemies.
    #
    $ enemies_list = []
    
    scene black
    
    #### Let's show the game screen.
    #
    show screen battle_screen
    
    
    #### We can add some allies to the party:
    #
    menu:
        "Who do you take with you?"
        
        "Friend 1":
            $ party_list.append ( {"name":"Friend 1", "max_hp":30, "current_hp":30, "min_damage":5, "max_damage":6} )
            
        "Friend 2":
            $ party_list.append ( {"name":"Friend 2", "max_hp":60, "current_hp":60, "min_damage":1, "max_damage":4} )
            
        "Noone... :(":
            pass
            
    
    #### Enemies party can be set manually or automatically like:
    #
    python:
        for i in range ( 0, renpy.random.randint(1,4) ):
            enemy_name = "Enemy %d" %i
            enemy_max_hp = renpy.random.randint(10,20)
            enemy_current_hp = enemy_max_hp
            enemy_min_damage = renpy.random.randint(1,3)
            enemy_max_damage = renpy.random.randint(4,6)
            
            enemies_list.append ( {"name":enemy_name, "max_hp":enemy_max_hp, "current_hp":enemy_current_hp, "min_damage":enemy_min_damage, "max_damage":enemy_max_damage} )
            
    
    "Let the battle begins!"
    
    #### Main battle loop.
    #
    label battle_2_loop:
        
        #### At first let's check if player's party is ok.
        #
        if check_party(party_list) == "lost":
            jump battle_2_lose
                
        
        #### All the party members will do their actions one after another.
        #
        $ party_index = 0
        
        while party_index < len(party_list):
            
            $ current_player = party_list[party_index]
            
            #### Current player will act only if he still alive.
            #
            if current_player["current_hp"] > 0:
                
                #### Let's check if enemies party is still ok.
                #
                if check_party(enemies_list) == "lost":
                    jump battle_2_win
            
                #### Let the player make his turn.
                #
                $ players_turn = True
                
                battle_narrator"[current_player[name]], it's your turn now."
                
                #### Store the result of player's interaction.
                #
                $ res = ui.interact()
                
                #### Now disallow player's interact with the game.
                #
                $ players_turn = False
                
                if res == "heal":
                    $ current_player["current_hp"] = min( current_player["current_hp"]+5, current_player["max_hp"] )
                    $ potions_left -= 1
                    "*Drink* 5hp restored"
                
                else:
                    $ player_damage = renpy.random.randint( current_player["min_damage"], current_player["max_damage"] )
                    $ enemies_list[res]["current_hp"] -= player_damage
                    "Take this! (damage dealt - [player_damage]hp)"
                    
            
            #### And the turn goes to the next party member.
            #
            $ party_index += 1
                    
            
            
        ##### And now it's enemies party turn.
        # 
        # At first let's check if enemy's party is ok.
        #
        if check_party(enemies_list) == "lost":
            jump battle_2_win
        
        
        
        #### All the party members will do their actions one after another.
        #
        $ enemy_index = 0
        
        while enemy_index < len(enemies_list):
            $ current_enemy = enemies_list[enemy_index]
            
            #### Current enemy will act only if he is still alive.
            #
            if current_enemy["current_hp"] > 0:
                
                #### Let's check if player's party is still ok.
                #
                if check_party(party_list) == "lost":
                    jump battle_2_lose
                
                #### Enemy will attack the random player.
                #
                $ party_member_to_attack = party_list[renpy.random.randint( 0, (len(party_list)-1) )]
                
                $ enemy_damage = renpy.random.randint( current_enemy["min_damage"], current_enemy["max_damage"] )
                
                $ party_member_to_attack["current_hp"] -= enemy_damage
                
                "Rrrrr! ([current_enemy[name]] dealt [enemy_damage]hp damage to [party_member_to_attack[name]])"
                
            
            #### And the turn goes to the next party member.
            #
            $ enemy_index += 1
            
            
        #### Next round of the battle.
        #
        jump battle_2_loop
            
            
#### The results of the game.
#
label battle_2_win:
    "Well done!"
    hide screen battle_screen
    return
    
label battle_2_lose:
    "X_X"
    hide screen battle_screen
    return

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

Re: Simple minigames (Screen Language only).

#29 Post by Alex »

Race game.

Code: Select all

screen game_scr():
    
    #### This part will let us interact with the screen.
    # Put it under the "timer_on" trigger to be able to show it
    # to the player without any interaction.
    if timer_on:
        #### Every 0.5 sec the game will change its state.
        timer 0.5 action Return("smth") repeat True
        
        key "a" action Return("a")
        key "A" action Return("a")
        key "d" action Return("d")
        key "D" action Return("d")
    #
    ####
    
    #### The background of the game screen.
    # If you have predefined image, like "image game bg = 'game_bg.png'",
    # you'll be able to add it simple like:
    # add "game bg"
    # Note: it is up to you to set the proper position for the bg
    # to let player know how far his car is from start and finish lines.
    #
    # But for now - some pseudographic bg
    text "   ================================== \n\n====================================" color "#c0c0c0" anchor (0.0, 0.0) pos (start_pos-125, 200)
    text "#\n#" color "#c0c0c0" anchor (1.0, 0.0) pos (start_pos, 270)
    text "#\n#" color "#c0c0c0" anchor (0.0, 0.0) pos (finish_pos, 270)
    #
    ####
    
    #### Some of the opponents.
    # Use this part if you've set the "opponents" list.
    # If not - then just comment or delete this part.
    #
    for i, each_opponent in enumerate(opponents):
        ####
        # If you've set the opponent's car appearence as an image
        # then show it as:
        # add each_opponent["car"] anchor (1.0, 0.0) pos (each_opponent["opp_car_pos"], 200-(len(opponents)-i)*5)
        #
        # But for pseudographic it will be
        text (each_opponent["car"]) color (each_opponent["car_color"]) anchor (1.0, 0.0) pos (each_opponent["opp_car_pos"], 200-(len(opponents)-i)*5)
        #
        ####
    #
    ####
    
    #### Player's car.
    # If you have predefined image, like "image car = 'my_car.png'",
    # you'll be able to add it like:
    # add "car" anchor (1.0, 0.0) pos (car_pos, 200)
    #
    # But for pseudographic car it will be
    text "[car]" anchor (1.0, 0.0) pos (car_pos, 200)
    #
    ####

# The game starts here.
label race_game:
    #### Some variables that describes the game state.
    $ car = "___/-----\_____\n=@====@="
    $ start_pos = 200
    $ finish_pos = 600
    $ car_pos = (start_pos + finish_pos)/2
    $ last_pressed = ""
    $ timer_on = False
    
    #### The list of the opponents
    # (each one described by the dictionary).
    # If you have predefined image, like "image red car = 'red_car.png'",
    # you'll be able to set opponent's car appearence like:
    # "car":"red car"
    #
    $ opponents = [
        {"car_name":"Mr. Red", "car":car, "car_color":"#c00", "opp_car_pos":(start_pos + finish_pos)/2, "opp_car_move":(-5, 0, 5, 5, 5, 5, 5, 10, 10)},
        {"car_name":"Mr. Green", "car":car, "car_color":"#0c0", "opp_car_pos":(start_pos + finish_pos)/2, "opp_car_move":(-5, 0, 5, 5, 5, 5, 5, 10, 10)}
        ]
    #
    ####
    
    scene black
    "..."
    
    #### Let's show the game screen.
    #
    show screen game_scr
    
    "Let's begin! (push 'a' and 'd' buttons)"
    
    #### And for now the player is able to interact with the game.
    #
    $ timer_on = True
    
    #### The game loop that has all its logic.
    #
    label race_game_loop:
        #### The result of interaction with the game.
        #
        $ res = ui.interact()
        
        #### The game change its state by the timer.
        #
        if res == "smth":
            $ car_pos -= 5
            if car_pos <= start_pos:
                #### Don't forget to turn off the ability to interact
                # with the game before jump to the result of the game.
                #
                $ timer_on = False
                jump race_lose
            
            #### Let's change the opponents positions
            # (if you've set the "opponents" list, ofcourse).
            # If not - then just comment or delete this part.
            #
            python:
                for i in range(len(opponents)):
                    opponents[i]["opp_car_pos"] += renpy.random.choice(opponents[i]["opp_car_move"])
                    if opponents[i]["opp_car_pos"] >= finish_pos:
                        winner = opponents[i]["car_name"]
                        timer_on = False
                        renpy.jump("race_over")
            #
            ####
                        
            jump race_game_loop

        #### Let's check if player has pressed the right button.
        #
        elif res == "a" and last_pressed != "a":
            $ last_pressed = "a"
            $ car_pos += 10
        elif res == "d" and last_pressed != "d":
            $ last_pressed = "d"
            $ car_pos += 10
        if car_pos >= finish_pos:
            $ timer_on = False
            jump race_win
        
        jump race_game_loop

#### The results of the game.
#
label race_over:
    $ renpy.pause(0.5, hard=True)
    "[winner] finished first!"
    hide screen game_scr
    return
    
label race_lose:
    $ renpy.pause(0.5, hard=True)
    "Too slow..."
    hide screen game_scr
    return
    
label race_win:
    $ renpy.pause(0.5, hard=True)
    "You finished first!"
    hide screen game_scr
    return

User avatar
Donmai
Eileen-Class Veteran
Posts: 1960
Joined: Sun Jun 10, 2012 1:45 am
Completed: Toire No Hanako, Li'l Red [NaNoRenO 2013], The One in LOVE [NaNoRenO 2014], Running Blade [NaNoRenO 2016], The Other Question, To The Girl With Sunflowers
Projects: Slumberland
Location: Brazil
Contact:

Re: Simple minigames (Screen Language only).

#30 Post by Donmai »

Awesome! Thank you, Alex.
Image
No, sorry! You must be mistaking me for someone else.
TOIRE NO HANAKO (A Story About Fear)

Post Reply

Who is online

Users browsing this forum: No registered users