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
Alex
Lemma-Class Veteran
Posts: 2677
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Simple minigames (Screen Language only).

#91 Post by Alex » Sun May 24, 2020 4:58 pm

ForeverAScone wrote:
Sun May 24, 2020 12:42 pm
... I meant that each move can be used only a couple times per battle, like what you were saying "using a supermove only 3 times per battle". I was planning on using it with the one on one battle.

Code: Select all

    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)"
Well, in this part player can eat some cookie if (s)he has at least one left. You can add similar variables to store the amount of supermoves and add those supermoves as choices in menu.
Try

Code: Select all

label battle_game_1:
    #### Some variables that describes the game state.
    $ fist_of_fire_left = 3
    $ acid_rain_left = 2
    # rest of code unchanged

Code: Select all

    while (wolf_hp > 0) and (red_hood_hp > 0):
        
        menu:
            "Atack!":
                $ wolf_hp -= 2
                r "K-y-aaa!!!11 (damage dealt - 2hp)"

            "Let's make some hot wolves :green: ([fist_of_fire_left] left)" if fist_of_fire_left > 0:
                $ fist_of_fire_left -= 1
                $ wolf_hp -= 6
                r "GrrGrrr!!!11 (damage dealt - 6hp)"

            "It's an acid rain, hallelujah ([acid_rain_left] left)" if acid_rain_left > 0:
                $ acid_rain_left -= 1
                $ wolf_hp -= 5
                "~some magical passes and muffled mumble~ (damage dealt - 5hp)"
                
            "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)"
edit: oops, forgot to reduce amount of supermoves...
Last edited by Alex on Mon May 25, 2020 5:26 pm, edited 1 time in total.

User avatar
ForeverAScone
Newbie
Posts: 20
Joined: Sat May 23, 2020 8:08 pm
Projects: Working title to do with string theory. Got any got string puns/phrases? Please do tell me, lol.
Location: Under your bed
Contact:

Re: Simple minigames (Screen Language only).

#92 Post by ForeverAScone » Sun May 24, 2020 11:56 pm

Alex wrote:
Sun May 24, 2020 4:58 pm

Code: Select all

    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)"
Well, in this part player can eat some cookie if (s)he has at least one left. You can add similar variables to store the amount of supermoves and add those supermoves as choices in menu.
Try

Code: Select all

label battle_game_1:
    #### Some variables that describes the game state.
    $ fist_of_fire_left = 3
    $ acid_rain_left = 2
    # rest of code unchanged

Code: Select all

    while (wolf_hp > 0) and (red_hood_hp > 0):
        
        menu:
            "Atack!":
                $ wolf_hp -= 2
                r "K-y-aaa!!!11 (damage dealt - 2hp)"

            "Let's make some hot wolves :green: ([fist_of_fire_left] left)" if fist_of_fire_left > 0:
                $ wolf_hp -= 6
                r "GrrGrrr!!!11 (damage dealt - 6hp)"

            "It's an acid rain, hallelujah ([acid_rain_left] left)" if acid_rain_left > 0:
                $ wolf_hp -= 5
                "~some magical passes and muffled mumble~ (damage dealt - 5hp)"
                
            "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)"
Thanks so much for taking the time to help me out :D At first the count for the amount of moves left wasn't going down, but I was able to mess around with things and get it to work after a little while, and now it works great :) Thank you again, this has been a great help since I'm practically brand new to Ren'Py!
Your average noob here. Howdydoo

User avatar
ForeverAScone
Newbie
Posts: 20
Joined: Sat May 23, 2020 8:08 pm
Projects: Working title to do with string theory. Got any got string puns/phrases? Please do tell me, lol.
Location: Under your bed
Contact:

Re: Simple minigames (Screen Language only).

#93 Post by ForeverAScone » Fri Jul 10, 2020 1:40 pm

In the battle minigame (specifically the single battle though I bet it does the same thing in the group battle), I've noticed that when the enemy's health is at 0, it still gets one last turn to fight which often results in a double KO even though the enemy should not have been able to fight any more since it was at 0 HP. Is there a way to fix that? Thanks
Your average noob here. Howdydoo

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

Re: Simple minigames (Screen Language only).

#94 Post by Alex » Fri Jul 10, 2020 3:47 pm

ForeverAScone wrote:
Fri Jul 10, 2020 1:40 pm
In the battle minigame (specifically the single battle though I bet it does the same thing in the group battle), I've noticed that when the enemy's health is at 0, it still gets one last turn to fight which often results in a double KO even though the enemy should not have been able to fight any more since it was at 0 HP. Is there a way to fix that? Thanks
Coup de grace, nah? :mrgreen:

Uh, well, let's add another check before wolfy's attack then

Code: Select all

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

        if wolf_hp > 0: # <--- check if wolf is still alive after all the girl has done...

            $ wolf_damage = renpy.random.randint(1, 6)
        
            $ red_hood_hp -= wolf_damage
        
            w "RrrrrRRrrrr! {i}*wolf bites you*{/i} (damage dealt - [wolf_damage]hp)"

The group battle shouldn't have this issue, 'cause it has checks for party/animies before each combatant's action.

User avatar
ForeverAScone
Newbie
Posts: 20
Joined: Sat May 23, 2020 8:08 pm
Projects: Working title to do with string theory. Got any got string puns/phrases? Please do tell me, lol.
Location: Under your bed
Contact:

Re: Simple minigames (Screen Language only).

#95 Post by ForeverAScone » Fri Jul 10, 2020 5:29 pm

Ah, thank you again, it works great now :D
Your average noob here. Howdydoo

User avatar
akio93
Newbie
Posts: 9
Joined: Thu Apr 04, 2019 11:18 pm
Contact:

Re: Simple minigames (Screen Language only).

#96 Post by akio93 » Tue Sep 08, 2020 2:11 am

Hello! thank you for the wonderful codes! I have a question, how do you make the enemy in group battle heal themselves instead of attacking the player? Like they can choose to attack you or heal themselves when it's their turn. Is that possible? thanks!

Edit: I also want to know how to use my turn to heal one other party members or heal all of them at once?

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

Re: Simple minigames (Screen Language only).

#97 Post by Alex » Tue Sep 08, 2020 2:06 pm

akio93 wrote:
Tue Sep 08, 2020 2:11 am
Hello! thank you for the wonderful codes! I have a question, how do you make the enemy in group battle heal themselves instead of attacking the player? Like they can choose to attack you or heal themselves when it's their turn. Is that possible? thanks!

Edit: I also want to know how to use my turn to heal one other party members or heal all of them at once?
You could try to make it like this

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:
            hbox:
                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
                            
                if healing_flag:
                    textbutton "<- Heal" action Return(["heal", each_party_member]) yminimum 40
                
                
        hbox:
            frame:
                size_group "party"
                yminimum 40
                text "Healing Potions left - [potions_left]" yalign 0.5
            if players_turn and potions_left > 0:
                textbutton "<- Use" action ToggleVariable("healing_flag", True, False) yminimum 40
            else:
                textbutton "<- Use" action None yminimum 40
                
        hbox:
            frame:
                size_group "party"
                yminimum 40
                text "Heal the party Scrolls left - [healing_scrolls_left]" yalign 0.5
            if players_turn and healing_scrolls_left > 0:
                textbutton "<- Use" action Return(["heal_all", None]) yminimum 40
            else:
                textbutton "<- Use" action None yminimum 40
                
        hbox:
            frame:
                size_group "party"
                yminimum 40
                text "Attack all the enemies Scrolls left - [attack_scrolls_left]" yalign 0.5
            if players_turn and attack_scrolls_left > 0:
                textbutton "<- Use" action Return(["attack_all", None]) 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(["attack", 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
    $ healing_scrolls_left = 3
    $ attack_scrolls_left = 2
    $ players_turn = False
    $ healing_flag = 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.
                #
                $ action_type, actor  = ui.interact()
                
                
                #### Now disallow player's interact with the game.
                #
                $ players_turn = False
                
                $ healing_flag = False # drop the healing flag
                
                if action_type == "heal":
                    $ actor["current_hp"] = min( actor["current_hp"]+5, actor["max_hp"] )
                    $ potions_left -= 1
                    "*Drink* 5hp restored"
                
                elif action_type == "heal_all":
                    python:
                        for each_party_member in party_list:
                            if each_party_member["current_hp"] > 0:
                                each_party_member["current_hp"] = min( each_party_member["current_hp"]+5, each_party_member["max_hp"] )
                    
                    $ healing_scrolls_left -= 1
                    "*Magic* 5hp restored to all"
                
                elif action_type == "attack":
                    $ player_damage = renpy.random.randint( current_player["min_damage"], current_player["max_damage"] )
                    $ enemies_list[actor]["current_hp"] -= player_damage
                    "Take this! (damage dealt - [player_damage]hp)"
                    
                elif action_type == "attack_all":
                    python:
                        for each_enemy in enemies_list:
                            if each_enemy["current_hp"] > 0:
                                each_enemy["current_hp"] -= 5
                    $ attack_scrolls_left -= 1
                    "Take this! (damage dealt to all - 5hp)"
                    
            
            #### 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's action
                #
                if current_enemy["current_hp"] < current_enemy["max_hp"] * 0.5: # will choose action if current_hp < 1/2 max_hp
                    $ action_type = renpy.random.choice( ("attack", "heal") )
                    
                else:
                    $ action_type = "attack"
                    
                
                if action_type == "attack":
                
                    #### 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]])"
                    
                elif action_type == "heal":
                
                    #### Enemy will heal himself.
                    #
                    $ current_enemy["current_hp"] = min( current_enemy["current_hp"]+5, current_enemy["max_hp"] )
                    "*Mwahaha* [current_enemy[name]] restored 5hp"
                
            
            #### 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

# The game starts here.

label start:

    "..."
    call battle_game_2
    "---"

    return

User avatar
akio93
Newbie
Posts: 9
Joined: Thu Apr 04, 2019 11:18 pm
Contact:

Re: Simple minigames (Screen Language only).

#98 Post by akio93 » Wed Sep 09, 2020 5:28 am

thank you very much! This is so helpful you also include to attack all enemy! so neat! thank you again! > 7 < )/

Post Reply

Who is online

Users browsing this forum: No registered users