Page 7 of 9
Re: Simple minigames (Screen Language only).
Posted: Sun May 24, 2020 4:58 pm
by Alex
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...
Re: Simple minigames (Screen Language only).
Posted: Sun May 24, 2020 11:56 pm
by ForeverAScone
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

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!
Re: Simple minigames (Screen Language only).
Posted: Fri Jul 10, 2020 1:40 pm
by ForeverAScone
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
Re: Simple minigames (Screen Language only).
Posted: Fri Jul 10, 2020 3:47 pm
by Alex
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?
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.
Re: Simple minigames (Screen Language only).
Posted: Fri Jul 10, 2020 5:29 pm
by ForeverAScone
Ah, thank you again, it works great now

Re: Simple minigames (Screen Language only).
Posted: Tue Sep 08, 2020 2:11 am
by akio93
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?
Re: Simple minigames (Screen Language only).
Posted: Tue Sep 08, 2020 2:06 pm
by Alex
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
Re: Simple minigames (Screen Language only).
Posted: Wed Sep 09, 2020 5:28 am
by akio93
thank you very much! This is so helpful you also include to attack all enemy! so neat! thank you again! > 7 < )/
Re: Simple minigames (Screen Language only).
Posted: Sat Aug 28, 2021 7:15 pm
by Trafagal
Hi Alex,
For the "Memoria" game, may I ask is there a way to put the X cards in the middle of the screen below the timer instead of leaning to the left?
Thank you for the wonderful games!
Re: Simple minigames (Screen Language only).
Posted: Sat Aug 28, 2021 8:06 pm
by Alex
Trafagal wrote: ↑Sat Aug 28, 2021 7:15 pm
Hi Alex,
For the "Memoria" game, may I ask is there a way to put the X cards in the middle of the screen below the timer instead of leaning to the left?
imageleft.JPG
Thank you for the wonderful games!
Try it like
Code: Select all
##### Cards
#
# To use images, just comment out lines that show text and uncomment lines that show images
grid 3 4:
align(0.5, 0.5)
Re: Simple minigames (Screen Language only).
Posted: Sat Aug 28, 2021 8:26 pm
by Trafagal
Alex wrote: ↑Sat Aug 28, 2021 8:06 pm
Trafagal wrote: ↑Sat Aug 28, 2021 7:15 pm
Hi Alex,
For the "Memoria" game, may I ask is there a way to put the X cards in the middle of the screen below the timer instead of leaning to the left?
imageleft.JPG
Thank you for the wonderful games!
Try it like
Code: Select all
##### Cards
#
# To use images, just comment out lines that show text and uncomment lines that show images
grid 3 4:
align(0.5, 0.5)
Thank you Alex! That was quick!
Managed to change the position!. I wonder if you have any games or similar works which I can look into?
Re: Simple minigames (Screen Language only).
Posted: Sat Aug 28, 2021 8:31 pm
by Alex
Trafagal wrote: ↑Sat Aug 28, 2021 8:26 pm
...I wonder if you have any games or similar works which I can look into?
They all in the first post...

Re: Simple minigames (Screen Language only).
Posted: Sat Aug 28, 2021 8:42 pm
by Trafagal
Alex wrote: ↑Sat Aug 28, 2021 8:31 pm
Trafagal wrote: ↑Sat Aug 28, 2021 8:26 pm
...I wonder if you have any games or similar works which I can look into?
They all in the first post...
Okay, Got it!

Re: Simple minigames (Screen Language only).
Posted: Sun Aug 29, 2021 4:18 am
by Trafagal
Hi Alex,
While I was testing the "Find the Difference" game. I receive this error.
I wonder if anyone can help.
Thank you.
Re: Simple minigames (Screen Language only).
Posted: Sun Aug 29, 2021 11:20 am
by Alex
Trafagal wrote: ↑Sun Aug 29, 2021 4:18 am
Hi Alex,
While I was testing the "Find the Difference" game. I receive this error.
Try to set any default value for variable
The original code was made long time ago, and for now the proper way is to set default values for variables that will be changed during the game.
https://www.renpy.org/doc/html/python.h ... -statement